python - GeoPandas 中坐标表示的不一致
问题描述
我有 GeoSeries 中的形状点列表。
coords.head():
0 POINT (-26.17690 80.81700)
1 POINT (-15.54390 80.61700)
2 POINT (-20.67690 80.36700)
3 POINT (6.10610 80.83300)
4 POINT (17.63910 79.88300)
Name: geometry, dtype: geometry
当尝试使用命令获取压缩坐标列表时,pd.Series(zip(coords.geometry.x, coords.geometry.y)).head()
我得到下一个示例:
0 (-26.1769, 80.817)
1 (-15.5439, 80.617)
2 (-20.6769, 80.367)
3 (6.1061000000000005, 80.833)
4 (17.63909999999999, 79.883)
dtype: object
顺便说一句coords.geometry.x.head()
:
0 -26.1769
1 -15.5439
2 -20.6769
3 6.1061
4 17.6391
dtype: float64
同样奇怪的是,当我尝试重现结果时:
new_coords = [(-26.17690, 80.81700),
(-15.54390, 80.61700),
(-20.67690, 80.36700),
(6.10610, 80.83300),
(17.63910, 79.88300)]
new_coords = gpd.GeoSeries([Point(p) for p in new_coords])
pd.Series(zip(new_coords.geometry.x, new_coords.geometry.y))
new_coords
Zip 的行为并不奇怪:
0 POINT (-26.17690 80.81700)
1 POINT (-15.54390 80.61700)
2 POINT (-20.67690 80.36700)
3 POINT (6.10610 80.83300)
4 POINT (17.63910 79.88300)
dtype: geometry
这里的主要目标是获得准确的坐标值以合并数据帧,因此 zip 返回相似但不相同的值是不可接受的。
解决方案
似乎@juanpa.arrivillaga 是正确的。执行语句时[float(p) for p in coords.geometry.x][:5]
,我得到相同的数字:
[-26.1769, -15.5439, -20.6769, 6.1061000000000005, 17.63909999999999]
所以输入数据不会被 zip 改变。
推荐阅读
- javascript - 将 useEffect 与类组件一起使用
- javascript - Firebase,将数据保存在唯一键中
- java - @query 获取最大日期的记录
- powershell - 将所有用户添加到 AD 组,不包括使用 powershell 的少数用户
- angular - 如何在 ag-grid 中获得正确的过滤器模型?
- python - 如何使用 BeautifulSoup 从 iframe 获取信息?
- typescript - Vue/Typescript 如何找到用于 style = { } 的正确对象类型
- php - 过滤默认查询以在 wordpress 中仅显示选定级别的子页面
- python - 列表初始化
- python - 将嵌套的 mongo db 文档转换为 pandas 数据框