diff --git a/.github/workflows/ci_linux.yml b/.github/workflows/ci_linux.yml index fd7ef29be..305c30e2d 100644 --- a/.github/workflows/ci_linux.yml +++ b/.github/workflows/ci_linux.yml @@ -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 diff --git a/README.rst b/README.rst index f9b2160bb..3c3975dec 100644 --- a/README.rst +++ b/README.rst @@ -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 `__ diff --git a/fiona/_env.pyx b/fiona/_env.pyx index f388ddd26..49f86509f 100644 --- a/fiona/_env.pyx +++ b/fiona/_env.pyx @@ -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) diff --git a/fiona/env.py b/fiona/env.py index fe9b97903..e531d3d72 100644 --- a/fiona/env.py +++ b/fiona/env.py @@ -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) diff --git a/fiona/fio/env.py b/fiona/fio/env.py index a8de1b422..b7f71e93d 100644 --- a/fiona/fio/env.py +++ b/fiona/fio/env.py @@ -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()) diff --git a/setup.py b/setup.py index a0054c3d5..b5c71fbf8 100644 --- a/setup.py +++ b/setup.py @@ -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') diff --git a/tests/test_data_paths.py b/tests/test_data_paths.py index 398d65b8c..f86e23949 100644 --- a/tests/test_data_paths.py +++ b/tests/test_data_paths.py @@ -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