我正在读取一个县的shapefile,需要提取所有几何图形的最小和最大坐标。这似乎可以用shapely在shapefile中的每个单独的几何图形中实现,但不能在shapefile中的所有几何图形中实现。
sf_shp = os.getcwd() + '/data/map/San_Mateo/SAN_MATEO_COUNTY_STREETS.shp'
sfgeodata = gpd.read_file(sf_shp)
sfgeodata.total_bounds <-- for bounding box. 在geopandas或任何其他包中是否有属性或函数来获取此信息?
发布于 2021-07-02 03:21:17
total_bounds返回一个元组,其中包含作为整体的序列边界的minx、miny、maxx、maxy值。
bounds返回一个DataFrame,其中包含minx、miny、maxx和maxy列的值,其中包含每个几何图形的边界。
即--
import geopandas as gpd
from shapely.geometry import box
import matplotlib.pyplot as plt
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.bounds
world.total_bounds
# bounds for individual geometries
poly_geom = world.bounds
b = poly_geom.apply(lambda row: box(row.minx, row.miny, row.maxx, row.maxy), axis=1)
boxes = gpd.GeoDataFrame(poly_geom, geometry=b)
# visualize
ax = world.plot()
boxes.boundary.plot(color='r', ax=ax)
plt.show()
# total bounds for all geometries
world_box = gpd.GeoSeries(box(*world.total_bounds))
# visualize
ax = world.plot()
world_box.boundary.plot(color='r', ax=ax)
plt.show()bounds

total_bounds

https://stackoverflow.com/questions/68198525
复制相似问题