Skip to content

Commit

Permalink
ENH: Add support for PROJ_DATA environment variable (#1128)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Aug 2, 2022
1 parent 9d06389 commit 4fdd651
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
# Additional env variables
echo "GDAL_DATA=$GDALINST/gdal-$GDALVERSION/share/gdal" >> $GITHUB_ENV
echo "PROJ_LIB=$GDALINST/gdal-$GDALVERSION/share/proj" >> $GITHUB_ENV
echo "PROJ_DATA=$GDALINST/gdal-$GDALVERSION/share/proj" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$GDALINST/gdal-$GDALVERSION/lib:$GDALINST/proj-$PROJVERSION/lib:$FILEGDB/lib:\$LD_LIBRARY_PATH" >> $GITHUB_ENV
# Add PATH
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ Note: The following environment variables needs to be set so that Fiona works co
Windows ``PATH`` (e.g. ``C:\gdal\bin``).
* The gdal-data directory needs to be in your Windows ``PATH`` or the environment variable
``GDAL_DATA`` must be set (e.g. ``C:\gdal\bin\gdal-data``).
* The environment variable ``PROJ_LIB`` must be set to the proj library directory (e.g.
* The environment variable ``PROJ_LIB`` (PROJ < 9.1) | ``PROJ_DATA`` (PROJ 9.1+) must be set to the proj data directory (e.g.
``C:\gdal\bin\proj6\share``)

The `Appveyor CI build <https://ci.appveyor.com/project/sgillies/fiona/history>`__
Expand Down
8 changes: 7 additions & 1 deletion fiona/_env.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,13 @@ cdef class GDALEnv(ConfigEnv):
log.debug("GDAL data found in other locations: path=%r.", path)
self.update_config_options(GDAL_DATA=path)

if 'PROJ_LIB' in os.environ:
if 'PROJ_DATA' in os.environ:
# PROJ 9.1+
log.debug("PROJ_DATA found in environment.")
path = os.environ["PROJ_DATA"]
set_proj_data_search_path(path)
elif 'PROJ_LIB' in os.environ:
# PROJ < 9.1
log.debug("PROJ_LIB found in environment.")
path = os.environ["PROJ_LIB"]
set_proj_data_search_path(path)
Expand Down
8 changes: 7 additions & 1 deletion fiona/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,13 @@ def wrapper(*args, **kwds):
set_gdal_config("GDAL_DATA", path)
log.debug("GDAL data found in other locations: path=%r.", path)

if "PROJ_LIB" in os.environ:
if 'PROJ_DATA' in os.environ:
# PROJ 9.1+
path = os.environ["PROJ_DATA"]
set_proj_data_search_path(path)

elif "PROJ_LIB" in os.environ:
# PROJ < 9.1
path = os.environ["PROJ_LIB"]
set_proj_data_search_path(path)

Expand Down
2 changes: 1 addition & 1 deletion fiona/fio/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ def env(ctx, key):
elif key == 'gdal_data':
click.echo(os.environ.get('GDAL_DATA') or GDALDataFinder().search())
elif key == 'proj_data':
click.echo(os.environ.get('PROJ_LIB') or PROJDataFinder().search())
click.echo(os.environ.get('PROJ_DATA', os.environ.get('PROJ_LIB')) or PROJDataFinder().search())
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def copy_data_tree(datadir, destdir):
log.info("Copying gdal data from %s" % gdal_data)
copy_data_tree(gdal_data, destdir)

# Conditionally copy PROJ.4 data.
projdatadir = os.environ.get('PROJ_LIB', '/usr/local/share/proj')
# Conditionally copy PROJ DATA.
projdatadir = os.environ.get('PROJ_DATA', os.environ.get('PROJ_LIB', '/usr/local/share/proj'))
if os.path.exists(projdatadir):
log.info("Copying proj data from %s" % projdatadir)
copy_data_tree(projdatadir, 'fiona/proj_data')
Expand Down
7 changes: 5 additions & 2 deletions tests/test_data_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ def test_env_gdal_data_environ(monkeypatch):
assert result.output.strip() == '/foo/bar'


def test_env_proj_data_environ(monkeypatch):
monkeypatch.setenv('PROJ_LIB', '/foo/bar')
@pytest.mark.parametrize("data_directory_env", ["PROJ_LIB", "PROJ_DATA"])
def test_env_proj_data_environ(data_directory_env, monkeypatch):
monkeypatch.delenv('PROJ_DATA', raising=False)
monkeypatch.delenv('PROJ_LIB', raising=False)
monkeypatch.setenv(data_directory_env, '/foo/bar')
runner = CliRunner()
result = runner.invoke(main_group, ['env', '--proj-data'])
assert result.exit_code == 0
Expand Down

0 comments on commit 4fdd651

Please sign in to comment.