[英]Geopandas .to_crs only converts one coordinate of Point object
我需要将 GeoDataFrame 的 CRS 从 EPSG:2145 转换为 EPSG:3857。 当我使用 .to_crs 方法时,它只会转换 x 坐标,而将 y 保留为旧格式。
我的原始gdf
与 EPSG:2145
gdf
ipere geometry
670 POINT (-73.629 45.572)
671 POINT (-73.569 45.506)
672 POINT (-73.629 45.572)
673 POINT (-73.607 45.565)
771 POINT (-73.636 45.580)
gdf.crs
<Projected CRS: EPSG:2145>
Name: NAD83(CSRS98) / MTM zone 8
Axis Info [cartesian]:
- E(X)[east]: Easting (metre)
- N(Y)[north]: Northing (metre)
Area of Use:
- name: Canada - Quebec - between 75°W and 72°W.
- bounds: (-75.0, 44.99, -72.0, 62.53)
...
然后我尝试转换
gdf2 = gdf.to_crs(3857)
我检查:
gdf2
ipere geometry
670 POINT (-8486769.994 45.572)
671 POINT (-8486769.933 45.506)
672 POINT (-8486769.994 45.572)
673 POINT (-8486769.971 45.565)
771 POINT (-8486770.001 45.580)
如您所见,几何。 知道为什么会这样吗?
set_crs()
将您的地理数据框更改为 EPSG:4326 开始import io
import shapely.wkt
import pandas as pd
import geopandas as gpd
df = pd.read_csv(io.StringIO(""" ipere geometry
670 POINT (-73.629 45.572)
671 POINT (-73.569 45.506)
672 POINT (-73.629 45.572)
673 POINT (-73.607 45.565)
771 POINT (-73.636 45.580)"""), sep="\s\s+", engine="python")
for crs in ["EPSG:4326","EPSG:2145"]:
gdf = gpd.GeoDataFrame(df, geometry=df["geometry"].apply(shapely.wkt.loads), crs=crs)
print(crs)
print(gdf.to_crs("EPSG:3857").to_markdown(index=False))
每股收益:4326
伊佩尔 | 几何学 |
---|---|
670 | 点(-8196342.78761794 5712025.204171824) |
671 | 点(-8189663.618170344 5701535.712440695) |
672 | 点(-8196342.78761794 5712025.204171824) |
673 | 点(-8193893.758820487 5710912.098368462) |
771 | 点(-8197122.024053493 5713297.494982241) |
每股收益:2145
伊佩尔 | 几何学 |
---|---|
670 | 点(-8486769.993448919 45.49609174562639) |
671 | 点(-8486769.933511838 45.42971666048591) |
672 | 点(-8486769.993448919 45.49609174562639) |
673 | 点(-8486769.971471995 45.48905196902809) |
771 | 点(-8486770.000441579 45.50413721057778) |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.