Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiona from wheel does not set its GDAL_DATA path #731

Closed
kannes opened this issue Mar 8, 2019 · 3 comments
Closed

Fiona from wheel does not set its GDAL_DATA path #731

kannes opened this issue Mar 8, 2019 · 3 comments
Assignees
Labels
Milestone

Comments

@kannes
Copy link
Contributor

kannes commented Mar 8, 2019

Again/still struggling with the gdal and proj stuff (re #673 and #691).

From what I read, Fiona should set GDAL_PATH and PROJ_LIB to its own paths if there were no such paths defined in the environment yet.

I do not have GDAL_PATH or PROJ_LIB set, but Fiona still does not work :o)

I installed the latest version from pypi at https://pypi.org/project/Fiona/#files

pip install --user --upgrade https://files.pythonhosted.org/packages/b8/55/fdcd9a45b39a4fe50d79041d1194c2ebefcc7ef44958d54ad2b815129f02/Fiona-1.8.4-cp37-cp37m-manylinux1_x86_64.whl
import os

def checkpaths():
    gdal_data = os.environ.get('GDAL_DATA')
    if gdal_data:
      print(f"GDAL_DATA is set to {gdal_data}")
      if os.path.exists(gdal_data+"/gcs.csv"):
        print("GDAL_DATA seems correct")
      else:
        print("GDAL_DATA seems BROKEN")
    else:
      print(f"GDAL_DATA is NOT set")

    proj_lib = os.environ.get('PROJ_LIB')
    if proj_lib:
      print(f"PROJ_LIB is set to {proj_lib}")
      if os.path.exists(proj_lib+"/epsg"):
        print("PROJ_LIB seems correct")
      else:
        print("PROJ_LIB seems BROKEN")
    else:
      print(f"PROJ_LIB is NOT set")
>>> checkpaths()                                                                         
GDAL_DATA is NOT set
PROJ_LIB is NOT set

Importing Fiona now should have it update the paths to its own env, but it only sets the PROJ_LIB one.

>>> import fiona                                                                         

>>> checkpaths()                                                                         
GDAL_DATA is NOT set
PROJ_LIB is set to /home/kannes/.local/lib/python3.7/site-packages/fiona/proj_data
PROJ_LIB seems correct

This means that e.g. transformations will fail:

import fiona
from fiona.transform import transform_geom
from fiona.crs import from_epsg

eiffel_tower = {'type': 'Point', 'coordinates': (2.2945, 48.858222)}

crs_source_epsg = from_epsg(4326)
crs_target_epsg = from_epsg(25831)

transformed = transform_geom(crs_source_epsg, crs_target_epsg, eiffel_tower)
print(transformed)

prints:

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.
{'type': 'Point', 'coordinates': (2.2945, 48.858222)}

If I manually set the correct GDAL_PATH before importing Fiona everything works fine:

# you MUST use a pristine Python session for this
import os

os.environ['GDAL_DATA'] = "/home/hannes/.local/lib/python3.7/site-packages/fiona/gdal_data"

import fiona
from fiona.transform import transform_geom
from fiona.crs import from_epsg

eiffel_tower = {'type': 'Point', 'coordinates': (2.2945, 48.858222)}

crs_source_epsg = from_epsg(4326)
crs_target_epsg = from_epsg(25831)

transformed = transform_geom(crs_source_epsg, crs_target_epsg, eiffel_tower)
print(transformed)

prints
{'type': 'Point', 'coordinates': (448251.81788407586, 5411935.123097671)}

@sgillies
Copy link
Member

sgillies commented Mar 8, 2019

I got this straightened out in Rasterio, but haven't ported it here yet. Will do so for 1.8.5.

@sgillies sgillies self-assigned this Mar 8, 2019
@sgillies sgillies added the bug label Mar 8, 2019
@sgillies sgillies added this to the 1.8.5 milestone Mar 8, 2019
@kannes
Copy link
Contributor Author

kannes commented Mar 8, 2019

you rock

@felixink
Copy link

felixink commented Mar 8, 2019

Could we use fiona._env.GDALDataFinder (private class) to mitigate this issue prior to the update (3/11/2018)?

import fiona
import os
os.environ['GDAL_DATA'] = fiona._env.GDALDataFinder.search_wheel(
    'literally any string')
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants