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.

[BUG]: "epsg:4326" not parsed correctly as a CRS

See original GitHub issue

Thank you for helping us improve solaris!

Summary of the bug

I cannot get a polygon created with ‘sol.vector.polygon.georegister_px_df’ to write out to a geojson formatted file.

Steps to reproduce the bug

I am running a notebook that identifies vineyards, based on another called “How to Segment Buildings on Drone Imagery with Fast.ai & Cloud-Native GeoData Tools”

I believe the issue is very closely related to this question on GSE.

The polygon is created as expected:

image

But, when I go to write out with result_polys.to_file (‘result_polys.geojson’) I get a CRS failure.

I think this is very similar to the issues raised in #317

# convert polys from pixel coords to geo coords: https://solaris.readthedocs.io/en/latest/api/vector.html?highlight=georegister_px_df#solaris.vector.polygon.georegister_px_df
result_polys = sol.vector.polygon.georegister_px_df(mask2poly, 
                                                   affine_obj=tile_tfm, 
                                                   crs=4326
                                                   )
---
# show tile image to raw prediction to georegistered polygons
fig, (ax1, ax2, ax3) = plt.subplots(1,3, figsize=(15,5))

ax1.imshow(test_tile)
ax2.imshow(result)
result_polys.plot(ax=ax3)

 [produces the correct plot above]
---
result_polys.to_file ('result_polys.geojson', driver='GeoJSON')

[fails]

Buggy behavior and/or error message

Please describe the buggy behavior and/or paste output here.

---------------------------------------------------------------------------
CRSError                                  Traceback (most recent call last)
<ipython-input-18-94b01e24e989> in <module>
----> 1 result_polys.to_file ('result_polys.geojson')

/opt/anaconda3/lib/python3.7/site-packages/geopandas/geodataframe.py in to_file(self, filename, driver, schema, **kwargs)
    513         from geopandas.io.file import to_file
    514 
--> 515         to_file(self, filename, driver, schema, **kwargs)
    516 
    517     def to_crs(self, crs=None, epsg=None, inplace=False):

/opt/anaconda3/lib/python3.7/site-packages/geopandas/io/file.py in to_file(df, filename, driver, schema, **kwargs)
    126     with fiona_env():
    127         with fiona.open(
--> 128             filename, "w", driver=driver, crs=df.crs, schema=schema, **kwargs
    129         ) as colxn:
    130             colxn.writerecords(df.iterfeatures())

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

/opt/anaconda3/lib/python3.7/site-packages/fiona/__init__.py in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, **kwargs)
    262             c = Collection(path, mode, crs=crs, driver=driver, schema=this_schema,
    263                            encoding=encoding, layer=layer, enabled_drivers=enabled_drivers, crs_wkt=crs_wkt,
--> 264                            **kwargs)
    265         else:
    266             raise ValueError(

/opt/anaconda3/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)
    143             self._check_schema_driver_support()
    144             if crs_wkt or crs:
--> 145                 self._crs_wkt = crs_to_wkt(crs_wkt or crs)
    146 
    147         self._driver = driver

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

CRSError: Invalid input to create CRS: epsg:4326

Expected behavior

Expected to write out ‘result_polys.geojson’

Screenshots

If applicable, add screenshots to help explain your problem.

Environment information

  • OS: ====================================== Welcome to the Google Deep Learning VM ====================================== Version: pytorch-gpu.1-3.m40 Based on: Debian GNU/Linux 9.11 (stretch) (GNU/Linux 4.9.0-11-amd64 x86_64\n)

  • solaris version: 0.2.1

  • python version: 3.7.4

  • version of any relevant dependencies (optional - we may ask for this information later if not provided) pyproj 2.4.1 fiona 1.8.13 geopandas 0.6.2

Additional context

Hoping this is a simple fix that I’ve overlooked reading through the previous questions and responses. Thank you for a really impressive project.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
alrikscommented, Feb 14, 2020

Also, that export restriction issue is… incredible.

1reaction
alrikscommented, Feb 14, 2020

NIck,

Thank you for taking the time to look into this. I was just logging into gcloud console to try and remember what fixed the issue. I think it may have been going up to pyproj  2.4.2 and using this syntax:

result_polys = sol.vector.polygon.georegister_px_df(mask2poly,                                                      affine_obj=tile_tfm,                                                    crs=4326

<poof!> and the issue was gone.

My library versions now match yours.: solaris: 0.2.1 geopandas: 0.6.3 fiona: 1.8.13 pyproj: 2.4.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leaflet not getting correct bounding area for NASA GIBS map ...
CRS.EPSG4326 is giving unexpected results. I am looking at MODIS_Terra_CorrectedReflectance_Bands367. ESPG3857 ows:Bounding is below, while ...
Read more >
WMS CRS:84 is not allowed - Esri Community
In ArcgisRuntime 10.2.7 the correct projection EPSG:4326 was used, now in Version 100.x.x always the unallowed CRS:84 is used. Solved!
Read more >
CRS & EPSG issues - main@rasterio.groups.io
CRSError: The WKT could not be parsed. OGR Error code 6. >>> crs = CRS.from_user_input("+init=epsg:4326"). Warning 1: +init=epsg:XXXX syntax is deprecated.
Read more >
Bug report #6392: CRS not recognized when opening raster ...
My theory of a bug being present is based on the fact it works correctly in Windows, and in the "Coordinate Reference System...
Read more >
How to find correct projection of the shapefile data for leaflet ...
Region is a factor and not a character variable. ... tmp<-ind_global %>% st_as_sf() %>% st_transform(crs = "+init=epsg:4326") tmp ...
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