Geopandas .to_crs 只转换Point对象的一个​​坐标

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)

如您所见,几何 .知道为什么会这样吗?

  • 这项调查显示起始 CRS 不是 EPSG:2145,而是 EPSG:4326
  • 您可以使用 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))

EPSG:4326

ipere geometry
670 POINT (-8196342.78761794 5712025.204171824)
671 POINT (-8189663.618170344 5701535.712440695)
672 POINT (-8196342.78761794 5712025.204171824)
673 POINT (-8193893.758820487 5710912.098368462)
771 POINT (-8197122.024053493 5713297.494982241)

EPSG:2145

ipere geometry
670 POINT (-8486769.993448919 45.49609174562639)
671 POINT (-8486769.933511838 45.42971666048591)
672 POINT (-8486769.993448919 45.49609174562639)
673 POINT (-8486769.971471995 45.48905196902809)
771 POINT (-8486770.000441579 45.50413721057778)