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.

Import order for fiona and rasterio

See original GitHub issue

With the current binary wheels on PyPI, the order that fiona and rasterio are imported into a script/module is important.

Good:

import fiona
import rasterio

Bad:

import rasterio
import fiona

Steps to reproduce

To reproduce the issue (on linux), use a virtual environment to install the current binary wheels from pip:

$ python3 -m venv /tmp/venv
$ . /tmp/venv/bin/activate
(venv) $ pip install fiona rasterio

(installs Fiona-1.8.18-cp36-cp36m-manylinux1_x86_64.whl, rasterio-1.2.1-cp36-cp36m-manylinux1_x86_64.whl, and dependancies)

Importing rasterio before fiona is no good

(venv) $ python -c "import rasterio; import fiona"
ERROR 4: Unable to open EPSG support file gcs.csv.  Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.

The transform module does not work well:

(venv) $ python -c "import rasterio; from fiona.transform import transform; print(transform('EPSG:3857', 'EPSG:4326', [19455906], [-5026598]))"
ERROR 4: Unable to open EPSG support file gcs.csv.  Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.
ERROR 4: Unable to open EPSG support file gcs.csv.  Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.
ERROR 4: Unable to open EPSG support file gcs.csv.  Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.
ERROR 6: No translation for an empty SRS to PROJ.4 format is known.
ERROR 10: Pointer 'hTransform' is NULL in 'OCTTransform'.

([19455906.0], [-5026598.0])

these are the same coordinates as the input, as it’s a failed operation.

Importing fiona before rasterio is OK

(venv) $ python -c "import fiona; import rasterio"

shows no error message, and the transform module works as expected:

(venv) $ python -c "from fiona.transform import transform; import rasterio; print(transform('EPSG:3857', 'EPSG:4326', [19455906], [-5026598]))"
([174.77537726192696], [-41.09658239799418])

these are the expected long, lat coords.

Other discussion

This does not seem to be an issue with packages installed via conda (with conda-forge), testing with rasterio-1.2.1 and fiona-1.8.18. This appears to be an issue while setting GDAL_DATA within the pip package directory. There are some similarities to #673.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sgilliescommented, Apr 15, 2021

Fixed in 1.8.19.

1reaction
jorisvandenbosschecommented, Mar 31, 2021

Also fiona edits the environment variables:

https://github.com/Toblerity/Fiona/blob/885dbd11c5dcb2c61862faefc28bfbbff99954de/fiona/env.py#L590-L601

That could maybe also be changed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installing rasterio and Fiona together? - GIS Stack Exchange
The answer seems to be that this cannot be done, at least using the current versions of both packages. Because as, you noted, ......
Read more >
How to install Python geospatial libraries (Gdal, Fiona ...
How to install Python geospatial libraries (Gdal, Fiona, Rasterio, etc) under a Conda Env in Windows.
Read more >
Installation — rasterio documentation - Read the Docs
Rasterio is a Python C extension and to build you'll need a working compiler (XCode on OS X etc). You'll also need Numpy...
Read more >
Re-projecting using GDAL with Rasterio and Fiona - GeoPandas
The simplest method of re-projecting is GeoDataFrame.to_crs() . It uses pyproj as the engine and transforms the points within the geometries. These examples ......
Read more >
rasterio Documentation - Read the Docs
are outside the polygons defined in the shapefile. import fiona import rasterio import rasterio.mask with fiona.open("tests/data/box.shp", ...
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