问题
I'm trying to import a shape file and change its crs in order to get a map with the correct projection.
map_sh = gpd.read_file(r'C:\PATH\VG250_Gemeindegrenzen_2018.shp')
map_sh = map_sh.to_crs({'init' :'epsg:25832'})
When I try executing it, I will get the following error:
RuntimeError Traceback (most recent call last)
<ipython-input-7-8354f57e24ce> in <module>
----> 1 map_sh = map_sh.to_crs({'init' :'epsg:25832'})
~\AppData\Local\Continuum\miniconda3\lib\site-packages\geopandas\geodataframe.py in to_crs(self, crs, epsg, inplace)
441 else:
442 df = self.copy()
--> 443 geom = df.geometry.to_crs(crs=crs, epsg=epsg)
444 df.geometry = geom
445 df.crs = geom.crs
~\AppData\Local\Continuum\miniconda3\lib\site-packages\geopandas\geoseries.py in to_crs(self, crs, epsg)
302 except TypeError:
303 raise TypeError('Must set either crs or epsg for output.')
--> 304 proj_in = pyproj.Proj(self.crs, preserve_units=True)
305 proj_out = pyproj.Proj(crs, preserve_units=True)
306 project = partial(pyproj.transform, proj_in, proj_out)
~\AppData\Local\Continuum\miniconda3\lib\site-packages\pyproj\__init__.py in __new__(self, projparams, preserve_units, **kwargs)
360 # on case-insensitive filesystems).
361 projstring = projstring.replace('EPSG','epsg')
--> 362 return _proj.Proj.__new__(self, projstring)
363
364 def __call__(self, *args, **kw):
_proj.pyx in _proj.Proj.__cinit__()
RuntimeError: b'no arguments in initialization list'
I already had this specific error and could solve it by updating pyproj to version 2.2.1, but since yesterday I get the same error again.
What could have changed, that from one day to another the code is running into errors? How can I check which version of pyproj my code is running? I only know the command:
pip freeze
回答1:
Make sure that you are pointing to a valid epsg
file.
Depending on how you installed your packages this can be found in:
- ~\AppData\Local\Continuum\miniconda3\Library\share\gdal
- ~\AppData\Local\Continuum\miniconda3\Library\share
This can be achieved in many ways, but I generally prefer to manually point to the gdal resources I want to use. To do that, add an environment variable called GDAL_DATA, and point it to the first folder in the list above. After that, you may have to restart the python interpreter or you computer depending on what you are using.
If you are using Windows, Setting up GDAL and everything relying on that can be a painful experience, but I found installing it using those pre-compiled wheels being the easiest and most reliable solution. They are also frequently updated.
来源:https://stackoverflow.com/questions/57285978/geopandas-to-crs-running-into-errors