我有一个线串几何,我想计算相应的1公里宽的缓冲区.尽管设置了CRS,我似乎无法返回正确的几何形状

我正在运行以下代码来定义geodrame


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")

crs设置正确,单位为米

>>> 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...

Buffer Image

正如你可以看到的,缓冲区显然是错误的,因为坐标甚至不是有效的坐标(lat是—918.845!) 我做错了什么?thanks in advance

推荐答案

那是因为你把EPSG:3003当作地理CRS.由于输入是在lat/lon,你应该用EPSG:4326初始化GeoDataFrame,然后在生成buffer之前使用to_crs:

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

发帖主题:Re:Kolibrios

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

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

enter image description here

Python相关问答推荐

如何在BeautifulSoup中链接Find()方法并处理无?

当多个值具有相同模式时返回空

将整组数组拆分为最小值与最大值之和的子数组

如何检测背景有噪的图像中的正方形

Python json.转储包含一些UTF-8字符的二元组,要么失败,要么转换它们.我希望编码字符按原样保留

PywinAuto在Windows 11上引发了Memory错误,但在Windows 10上未引发

scikit-learn导入无法导入名称METRIC_MAPPING64'

如何在Raspberry Pi上检测USB并使用Python访问它?

Pandas DataFrame中行之间的差异

在pandas中使用group_by,但有条件

有没有一种ONE—LINER的方法给一个框架的每一行一个由整数和字符串组成的唯一id?

Django RawSQL注释字段

为什么\b在这个正则表达式中不解释为反斜杠

如何在Pyplot表中舍入值

网格基于1.Y轴与2.x轴显示在matplotlib中

python sklearn ValueError:使用序列设置数组元素

Beautifulsoup:遍历一个列表,从a到z,并解析数据,以便将其存储在pdf中.

如何使用pytest在traceback中找到特定的异常

如何编辑此代码,使其从多个EXCEL文件的特定工作表中提取数据以显示在单独的文件中

随机森林n_估计器的计算