question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QST:Weird Bug - Invalid input to create CRS

See original GitHub issue

This the first time I writing here so please excuse me if I don’t know all the drill.

I could not find a solution to my weird problem anywhere.

I am using a macOS 10.15.7 I have an issue that when I run the code in VS code Exporting in GeoPandas works well, however when I switch to Jupyter Lab or Jupyter Notebook (in any environment), I keep getting this Pyproj or Fiona error (not sure where it’s pinpointed) I receive the following error:

---------------------------------------------------------------------------
CRSError                                  Traceback (most recent call last)
<ipython-input-21-d74275096d91> in <module>
----> 1 file_3.to_file('test2.shp')

~/anaconda3/envs/geo_env/lib/python3.7/site-packages/geopandas/geodataframe.py in to_file(self, filename, driver, schema, index, **kwargs)
    744         from geopandas.io.file import _to_file
    745 
--> 746         _to_file(self, filename, driver, schema, index, **kwargs)
    747 
    748     def set_crs(self, crs=None, epsg=None, inplace=False, allow_override=False):

~/anaconda3/envs/geo_env/lib/python3.7/site-packages/geopandas/io/file.py in _to_file(df, filename, driver, schema, index, mode, crs, **kwargs)
    253             crs_wkt = crs.to_wkt("WKT1_GDAL")
    254         with fiona.open(
--> 255             filename, mode=mode, driver=driver, crs_wkt=crs_wkt, schema=schema, **kwargs
    256         ) as colxn:
    257             colxn.writerecords(df.iterfeatures())

~/anaconda3/envs/geo_env/lib/python3.7/site-packages/fiona/env.py in wrapper(*args, **kwargs)
    398     def wrapper(*args, **kwargs):
    399         if local._env:
--> 400             return f(*args, **kwargs)
    401         else:
    402             if isinstance(args[0], str):

~/anaconda3/envs/geo_env/lib/python3.7/site-packages/fiona/__init__.py in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, **kwargs)
    272             c = Collection(path, mode, crs=crs, driver=driver, schema=this_schema,
    273                            encoding=encoding, layer=layer, enabled_drivers=enabled_drivers, crs_wkt=crs_wkt,
--> 274                            **kwargs)
    275         else:
    276             raise ValueError(

~/anaconda3/envs/geo_env/lib/python3.7/site-packages/fiona/collection.py in __init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, **kwargs)
    151             self._check_schema_driver_support()
    152             if crs_wkt or crs:
--> 153                 self._crs_wkt = crs_to_wkt(crs_wkt or crs)
    154 
    155         self._driver = driver

fiona/_crs.pyx in fiona._crs.crs_to_wkt()

CRSError: Invalid input to create CRS: GEOGCRS["WGS 84",DATUM["World Geodetic System 1984",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["Horizontal component of 3D system."],AREA["World."],BBOX[-90,-180,90,180]],ID["EPSG",4326]]

I was able to fix the problem for a period following the discussion on CRS here and also about changing the location of the pyproj directory (in the pyrpoj guide), I guess I am having duplication problem.

why is it working properly in VS code and not in Jupyter? here is a sample of my code to explain:

import geopandas as gpd
import pyproj
#setting the pyrpoj directory
#in the past I was able to solve the error this way, but not anymore.
pyproj.datadir.set_data_dir('/Users/shai/anaconda3/envs/geo_env/share/proj')
file_ = gpd.read_file('test.shp')
file_2 = file_.to_crs('EPSG:4326') #works!
file_2.to_file('test2.shp')
# at this point I received the invalid input create CRS error!!!

Thanks in advance and excuse me for now understanding the code or the rules of writing this is my first time. Stay Safe,

Shai.

Deatails

SYSTEM INFO

python : 3.7.9 | packaged by conda-forge | (default, Dec 9 2020, 20:58:55) [Clang 11.0.0 ]
executable : /Users/shai/anaconda3/envs/geo_env/bin/python
machine : Darwin-19.6.0-x86_64-i386-64bit

GEOS, GDAL, PROJ INFO

GEOS : 3.8.0
GEOS lib : /opt/local/lib/libgeos_c.dylib
GDAL : 3.1.4
GDAL data dir: /Users/shai/anaconda3/envs/geo_env/share/gdal
PROJ : 7.2.0
PROJ data dir: /Users/shai/anaconda3/envs/geo_env/share/proj

PYTHON DEPENDENCIES

geopandas : 0.8.1
pandas : 1.2.1
fiona : 1.8.18
numpy : 1.20.0
shapely : 1.7.1
rtree : 0.9.7
pyproj : 3.0.0.post1
matplotlib : 3.3.2
mapclassify: None
geopy : 2.1.0
psycopg2 : None
geoalchemy2: None
pyarrow : None"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jorisvandenbosschecommented, Feb 11, 2021

Alright here is my wall of shame, should I start spring cleaning?

No worries, my base env is also a mess 😉

I had the problem before as well that I had a newer PROJ version in my geo env, and an older in my base env (what you also have). When working in a notebook, I also needed to include pyproj.datadir.set_data_dir('.../envs/geo_env/share/proj') in my notebooks to avoid pyproj raising errors (I think because it incorrectly found the base env PROJ intead of the geo env’s one). The main problem is that in a notebook, at least if you are using multiple environments as multiple kernels, the environment doesn’t get properly activated.

But here it’s not pyproj raising an error, but fiona / gdal.

I don’t know if fiona has API to specify this directory as well.

I have an issue that when I run the code in VS code Exporting in GeoPandas works well, however when I switch to Jupyter Lab or Jupyter Notebook (in any environment), I keep getting this Pyproj or Fiona error (not sure where it’s pinpointed)

When you are getting this error with jupyter, are you using the jupyter notebook/lab installed in the geo_env, or in the base env?

1reaction
Shai2ucommented, Feb 11, 2021

Joris, That was an excellent question! huh!

I lunched Jupyter Lab and notebook both from base environment. My Notebook is defined both to work with geo_env I redirected pyproj to geo_env and as far as I can tell out of two tests I had no problem… So before we close this question. I want to see that I have a full day of work with to see if the problem is patched.

secondly I would like to hear any comments how to create a real fix and not a patch. because I am assembling a dynamic workflow that sends and receives data both ways with GeoPandas.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CRS error working with Solaris [closed] - GIS Stack Exchange
I'm one of the maintainers for the solaris project. I tried to reproduce your error in my environment but could not.
Read more >
Issue create fails with "Invalid Input" error | Jira Cloud
Issue Summary. “issue creation” fails with error as “Invalid Input” when a multi-line custom field and is used in create issue screen.
Read more >
CRSError: Invalid projection: epsg:4326: for geopandas
I am using anaconda for geopandas. However, everytime I try to use epsg:4326:, it gives an error. CRSError: Invalid projection: epsg:4326: ...
Read more >
Commas in check boxes field of forms module throws "invalid ...
The following error is thrown when submitting a response: field input is invalid. Steps to Reproduce. 1. Create a new MVC form 2....
Read more >
Ceilometer error messages "Invalid Input, extra keys are not ...
Bug 1953424 - Ceilometer error messages "Invalid Input, extra keys are not allowed ... 01:01:04.584 61 ERROR ceilometer.publisher.gnocchi [-] Error creating ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found