GeoPandas 的 ProjError(x、y、z 和时间必须大小相同)

问题描述 投票:0回答:0

问题描述

不知何故,geopandas

to_crs
方法不起作用。 我有 conda update --all 并尝试在几个环境中运行下面的代码(主要环境,只安装了 geopandas 的最小环境),但它返回了相同的错误(ProjError:x,y,z 和时间必须大小相同)。

代码示例,一个可复制粘贴的示例

### to crs method check
import geopandas as gpd
import pandas as pd
from shapely.geometry import Point

df = pd.DataFrame(
    {'City': ['Buenos Aires', 'Brasilia', 'Santiago', 'Bogota', 'Caracas'],
     'Country': ['Argentina', 'Brazil', 'Chile', 'Colombia', 'Venezuela'],
     'Latitude': [-34.58, -15.78, -33.45, 4.60, 10.48],
     'Longitude': [-58.66, -47.91, -70.66, -74.08, -66.86]})

gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.Longitude, df.Latitude))
gdf.crs = "EPSG:4326" # original crs
gdf = gdf.to_crs("EPSG:6668") # convert to new crs
print(gdf)

ProjError                                 Traceback (most recent call last)
Cell In[18], line 14
     12 gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.Longitude, df.Latitude))
     13 gdf.crs = "EPSG:4326" # original crs
---> 14 gdf = gdf.to_crs("EPSG:6668") # convert to new crs
     15 print(gdf)

File ~\anaconda3\lib\site-packages\geopandas\geodataframe.py:1364, in GeoDataFrame.to_crs(self, crs, epsg, inplace)
   1362 else:
   1363     df = self.copy()
-> 1364 geom = df.geometry.to_crs(crs=crs, epsg=epsg)
   1365 df.geometry = geom
   1366 if not inplace:

File ~\anaconda3\lib\site-packages\geopandas\geoseries.py:1124, in GeoSeries.to_crs(self, crs, epsg)
   1047 def to_crs(self, crs=None, epsg=None):
   1048     """Returns a ``GeoSeries`` with all geometries transformed to a new
   1049     coordinate reference system.
   1050 
   (...)
   1121 
   1122     """
   1123     return GeoSeries(
-> 1124         self.values.to_crs(crs=crs, epsg=epsg), index=self.index, name=self.name
   1125     )

File ~\anaconda3\lib\site-packages\geopandas\array.py:779, in GeometryArray.to_crs(self, crs, epsg)
    775     return self
    777 transformer = Transformer.from_crs(self.crs, crs, always_xy=True)
--> 779 new_data = vectorized.transform(self.data, transformer.transform)
    780 return GeometryArray(new_data, crs=crs)

File ~\anaconda3\lib\site-packages\geopandas\_vectorized.py:1114, in transform(data, func)
   1111 result[~has_z] = set_coordinates(data[~has_z].copy(), np.array(new_coords_z).T)
   1113 coords_z = get_coordinates(data[has_z], include_z=True)
-> 1114 new_coords_z = func(coords_z[:, 0], coords_z[:, 1], coords_z[:, 2])
   1115 result[has_z] = set_coordinates(data[has_z].copy(), np.array(new_coords_z).T)
   1117 return result

File ~\anaconda3\lib\site-packages\pyproj\transformer.py:430, in Transformer.transform(self, xx, yy, zz, tt, radians, errcheck, direction)
    428     intime = None
    429 # call pj_transform.  inx,iny,inz buffers modified in place.
--> 430 self._transformer._transform(
    431     inx,
    432     iny,
    433     inz=inz,
    434     intime=intime,
    435     direction=direction,
    436     radians=radians,
    437     errcheck=errcheck,
    438 )
    439 # if inputs were lists, tuples or floats, convert back.
    440 outx = _convertback(xisfloat, xislist, xistuple, inx)

File pyproj/_transformer.pyx:459, in pyproj._transformer._Transformer._transform()

ProjError: x, y, z, and time must be same size

geopandas.show_versions()

的输出

系统信息

python : 3.9.16 (main, Mar 8 2023, 10:39:24) [MSC v.1916 64 位 (AMD64)] 可执行文件:C:\Users\xxx naconda3\python.exe 机器:Windows-10-10.0.22621-SP0

GEOS、GDAL、项目信息

GEOS:3.8.0 GEOS 库:无 GDAL:3.6.2 GDAL 数据目录:无 项目:6.2.1 项目数据目录:C:\Users\xxx naconda3\Library\share\proj

Python 依赖项

大熊猫:0.12.2 麻木的:1.24.3 熊猫:1.5.3 pyproj:2.6.1.post1 匀称:2.0.1 菲奥娜:1.9.1 地质炼金术2:无 地质学:2.2.0 matplotlib:3.7.1 地图分类:2.5.0 pygeos : 无 化脓性:无 psycopg2:无 pyarrow : 无 树:1.0.1

python-3.x geopandas shapely
© www.soinside.com 2019 - 2024. All rights reserved.