Geopandas未返回正确的米制缓冲区

1 投票
1 回答
27 浏览
提问于 2025-04-12 15:24

我有一个线段的几何形状,我想计算一个宽度为1公里的缓冲区。尽管我已经设置了坐标参考系统(CRS),但似乎无法得到正确的几何形状。

我运行了以下代码来定义地理数据框:


import pandas as pd
from shapely import LineString
import geopandas as gpd

test = pd.DataFrame(
    [["Test", LineString([(41.000, 18.583), (40.892, 18.952)])]], 
    columns=["Nome", "geometry"]
    )

test = gpd.GeoDataFrame(test, crs='EPSG:3003', geometry="geometry")

坐标参考系统设置正确,并且单位是米。

>>> test.crs

<Projected CRS: EPSG:3003>
Name: Monte Mario / Italy zone 1
Axis Info [cartesian]:
- X[east]: Easting (metre)
- Y[north]: Northing (metre)
Area of Use:
- name: Italy - onshore and offshore - west of 12°E.
- bounds: (5.93, 36.53, 12.0, 47.04)
Coordinate Operation:
- name: Italy zone 1
- method: Transverse Mercator
Datum: Monte Mario
- Ellipsoid: International 1924
- Prime Meridian: Greenwich

但是当我尝试计算缓冲区时,得到了这个结果:

>>> test.buffer(1000)

POLYGON ((-918.845 -261.947, -941.757 -166.523...

缓冲区图像

如你所见,缓冲区明显是错误的,因为坐标甚至不是有效的坐标(纬度是-918.845!)我到底哪里出错了?提前谢谢!

1 个回答

1

这是因为你把 EPSG:3003 当成了地理坐标系统来用。由于你的输入是 纬度/经度 的格式,所以你应该用 EPSG:4326 来初始化 GeoDataFrame。然后在进行 to_crs 操作之前,先使用 buffer :

gdf = gpd.GeoDataFrame(test, geometry="geometry", crs=4326).to_crs(3003)

print(gdf.buffer(1000).to_crs(4326))

# 0    POLYGON ((40.88408 18.94991, 40.88390 18.95066...
# dtype: geometry

输出结果 :

ax = gdf.to_crs(4326).plot(color="r")

gdf.buffer(1000).to_crs(4326).plot(ax=ax)

enter image description here

撰写回答