Issue
Problem description
Somehow, the geopandas to_crs
method does not work.
I have `conda update --all`` and tried to run the code below in several environments (main environment, minimum environment with just geopandas installed), but it returned the same error (ProjError: x, y, z, and time must be same size).
If someone has any idea to fix this, I appreciate your kind help.
Code Sample, a copy-pastable example
### 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
Output of geopandas.show_versions()
SYSTEM INFO
python : 3.9.16 (main, Mar 8 2023, 10:39:24) [MSC v.1916 64 bit (AMD64)] executable : C:\Users\xxx\anaconda3\python.exe machine : Windows-10-10.0.22621-SP0
GEOS, GDAL, PROJ INFO
GEOS : 3.8.0 GEOS lib : None GDAL : 3.6.2 GDAL data dir: None PROJ : 6.2.1 PROJ data dir: C:\Users\xxx\anaconda3\Library\share\proj
PYTHON DEPENDENCIES
geopandas : 0.12.2 numpy : 1.24.3 pandas : 1.5.3 pyproj : 2.6.1.post1 shapely : 2.0.1 fiona : 1.9.1 geoalchemy2: None geopy : 2.2.0 matplotlib : 3.7.1 mapclassify: 2.5.0 pygeos : None pyogrio : None psycopg2 : None pyarrow : None rtree : 1.0.1
Solution
I have no issue running your code.
According to the error message:
File pyproj/_transformer.pyx:459, in pyproj._transformer._Transformer._transform() ...,
the module pyproj
may cause the errors. Maybe it is too old (version 2.6.1.post1). Try upgrade it to more recent version and rerun.
Answered By - swatchai
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.