import geopandas as gpd

d:\ANACONDA\envs\ox\lib\site-packages\geopandas\_compat.py:111: UserWarning: The Shapely GEOS version (3.10.2-CAPI-1.16.0) is incompatible with the GEOS version PyGEOS was compiled with (3.10.1-CAPI-1.16.0). Conversions between both will be slow.

warnings.warn(

输入数据并投影

jingkai_polygon = gpd.read_file(r'D:/gis_ex10/new_database/控制边界/行政边界_三环.shp')

jingkai_polygon = jingkai_polygon.to_crs("EPSG:2362") #地理坐标系转投影坐标系

jingkai_polygon.plot()

jingkai_polygon.crs

Name: Xian 1980 / 3-degree Gauss-Kruger zone 38

Axis Info [cartesian]:

- X[north]: Northing (metre)

- Y[east]: Easting (metre)

Area of Use:

- name: China - onshore between 112°30'E and 115°30'E.

- bounds: (112.5, 21.52, 115.5, 45.45)

Coordinate Operation:

- name: 3-degree Gauss-Kruger zone 38

- method: Transverse Mercator

Datum: Xian 1980

- Ellipsoid: IAG 1975

- Prime Meridian: Greenwich

获取质心和边界信息

gdf = jingkai_polygon

gdf["centroid"] = gdf.centroid #取质心

gdf["boundary"] = gdf.boundary #获取边界

gdf["boundary"].plot()

缓冲区

gdf["buffered"] = gdf.buffer(2000)

gdf["buffered"].plot()

可视化

ax = gdf["buffered"].plot(alpha=.5,figsize = (12,15)) # saving the first plot as an axis and setting alpha (transparency) to 0.5

gdf["boundary"].plot(ax=ax, color="white", linewidth=.5)

gdf["centroid"].plot(ax=ax, color="red", alpha=.5,markersize = 100) # passing the first plot as an axis to the second

查看原文