1

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
Xzatar
  • 67
  • 1
  • 6
  • How did you install `geopandas`? Projection issue is quite common, but usually avoidable via installing whole env from `conda-forge`. You can try `pyproj.__version__` to check the version. What could have changed from previous day is the provider of this particular CRS - one works, other does not. – martinfleis Jul 31 '19 at 08:26
  • I'm not sure how I've installed it. Probably suing pip install .... When I run pyproj.__version__ I get v1.9.6. That will be the problem. But how can I update it? I've tried conda install -c conda-forge pyproj but then I only get the message, that the package is already installed – Xzatar Jul 31 '19 at 08:52

1 Answers1

0

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.

Alessio Arena
  • 390
  • 2
  • 8
  • But how can one add an Environment Variable? How to do it? Where to put it? – Philipe Riskalla Leal Dec 17 '19 at 14:42
  • Depends on your system, but for Windows you can just search for "environment variables" from your Start menu. This will open your System properties, where you will be able to set your new environment variable GDAL_DATA – Alessio Arena Jan 10 '20 at 05:32