import json
import geopandas as gpd
def create_shp(geojsonData, output_path, crs='EPSG:4326', geom_type='Point'):
# 创建 GeoDataFrame
gdf = gpd.GeoDataFrame.from_features(geojsonData['features'])
# 设置坐标系(根据你的数据)
# gdf.crs = "EPSG:4326"
# gdf.crs = "EPSG:3857"
gdf.crs = crs
# 拆分 GeoDataFrame 为包含相同几何类型的子集
# get_gdf = gdf[gdf['geometry'].geom_type == 'Point']
# get_gdf = gdf[gdf['geometry'].geom_type == 'LineString']
get_gdf = gdf[gdf['geometry'].geom_type == geom_type]
# 保存为 Shapefile
get_gdf.to_file(output_path, encoding='utf-8')
def get_file_content(file_path):
# 打开一个文件并读取所有内容
with open(file_path, 'r') as file:
content = file.read()
return content
geojson = json.loads(get_file_content('./1.json'))
create_shp(geojson, output_path="./example/points.shp")
网友评论