【Python】geopandas 读取 shp/geojson 边界文件

发布时间 2023-11-21 15:03:59作者: 是阿杰呀

1. 读取 shp/geojson 边界文件

import geopandas as gpd

file = 'media/abc.geojson'
gdf = gpd.read_file(file)
# 将 GeoDataFrame 转换为 GeoJSON 字符串
geojson = json.loads(gdf.to_json())
features = geojson['features']

2. 获取 边界文件的网格范围

import geopandas as gpd

file = 'media/abc.geojson'
gdf = gpd.read_file(file)
grid_bounds = gdf.total_bounds
# 返回一个列表, 包含 最小经度, 最小纬度, 最大经度, 最大纬度
res = grid_bounds.tolist()