forked from liyingben/NoFlyZone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcj02_to_bd09_geojson.py
33 lines (24 loc) · 1.18 KB
/
gcj02_to_bd09_geojson.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import geopandas as gpd
from coord_convert.transform import wgs2gcj, gcj2bd
from shapely.geometry import Point, LineString, Polygon, MultiPolygon, shape
def transform_coord(coord, transformer):
return tuple(transformer(*coord))
def transform_geometry(geom, transformer):
if geom.geom_type == 'Point':
return Point(transform_coord(geom.coords[0], transformer))
elif geom.geom_type == 'LineString':
return LineString([transform_coord(coord, transformer) for coord in geom.coords])
elif geom.geom_type == 'Polygon':
return Polygon([transform_coord(coord, transformer) for coord in geom.exterior.coords])
elif geom.geom_type == 'MultiPolygon':
return MultiPolygon([transform_geometry(polygon, transformer) for polygon in geom.geoms])
else:
raise ValueError(f'Unsupported geometry type: {geom.type}')
def gcj_to_bd(geometry):
return transform_geometry(geometry, gcj2bd)
input_file = '广东省各市边界_高德坐标系.geojson'
output_file = '广东省各市边界_百度坐标系.geojson'
gdf = gpd.read_file(input_file)
gdf.crs = None
gdf['geometry'] = gdf['geometry'].apply(gcj_to_bd)
gdf.to_file(output_file, driver='GeoJSON')