geopandas.GeoDataFrame.set_geometry#
- GeoDataFrame.set_geometry(col, drop=False, inplace=False, crs=None)#
使用现有列或指定的输入设置GeoDataFrame几何图形。默认情况下会生成一个新对象。
原始几何图形列将替换为输入。
- 参数
- col列标签或数组
- drop布尔值,默认为FALSE
删除要用作新几何图形的列
- inplace布尔值,默认为FALSE
就地修改GeoDataFrame(不创建新对象)
- crsPyproj.crs,可选
要使用的坐标系。该值可以是接受的任何值
pyproj.CRS.from_user_input()
例如,授权字符串(例如“EPSG:4326”)或WKT字符串。如果通过,将覆盖DataFrame和COL的CRS。否则,尝试从传递的col值或DataFrame中获取CRS。
- 退货
- GeoDataFrame
参见
GeoDataFrame.rename_geometry
重命名激活的几何图形列
示例
>>> from shapely.geometry import Point >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]} >>> gdf = geopandas.GeoDataFrame(d, crs="EPSG:4326") >>> gdf col1 geometry 0 name1 POINT (1.00000 2.00000) 1 name2 POINT (2.00000 1.00000)
传递数组:
>>> df1 = gdf.set_geometry([Point(0,0), Point(1,1)]) >>> df1 col1 geometry 0 name1 POINT (0.00000 0.00000) 1 name2 POINT (1.00000 1.00000)
使用现有列:
>>> gdf["buffered"] = gdf.buffer(2) >>> df2 = gdf.set_geometry("buffered") >>> df2.geometry 0 POLYGON ((3.00000 2.00000, 2.99037 1.80397, 2.... 1 POLYGON ((4.00000 1.00000, 3.99037 0.80397, 3.... Name: buffered, dtype: geometry