1

I recently did a clean window installed. I installed OSGeo4W via: https://trac.osgeo.org/osgeo4w/ I installed GDAL by downloading the pip wheel GDAL-2.3.2-cp36-cp36m-win_amd64.whl I also configured my django settings.py to:

if os.name == 'nt':
    import platform
    import sys

    OSGEO4W = r"C:\OSGeo4W"
    if '64' in platform.architecture()[0]:
        OSGEO4W += "64"
    assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
    os.environ['OSGEO4W_ROOT'] = OSGEO4W
    os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
    os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
    os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']
    GDAL_LIBRARY_PATH = sys.path[6] + r'\osgeo\gdal203.dll'

This configuration worked on my previous machine but when trying to edit a django model with a Point field I would get this error:

GDAL_ERROR 4: b'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 transforming geometry from srid '4326' to srid '3857' (OGR failure.)
GDAL_ERROR 4: b'Unable to open EPSG support file gcs.csv.  Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.'
Internal Server Error: /admin/event/event/31/change/

I followed the same configuration as my previous setup. Same machine but new OS so I'm a bit stomped. How can I configure the GDAL_DATA env variable? I tried the suggestion:

https://stackoverflow.com/a/52597276/9469766

setting GDAL:

GDAL_DATA= OSGEO4W + r'\share\gdal'

and

GDAL_DATA= OSGEO4W + r'\share\epsg_csv'

but both still produced the same exception.

2
  • What's the content of the directory you're pointing to? Eg, os.listdir(os.environ['GDAL_DATA']), does it contain gcs.csv? Commented Feb 27, 2020 at 9:36
  • epsg_csv contains the gcs.csv file along with 33 other files. Commented Feb 27, 2020 at 13:54

2 Answers 2

1

I was running into this issue as well. I ended up fixing it by running the web gis express install for OSGeo4W which adds the folder epsg_csv which should allow you to use:

if os.name == 'nt':
    import platform
    OSGEO4W = r"C:\OSGeo4W"
    if '64' in platform.architecture()[0]:
        OSGEO4W += "64"
    assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
    os.environ['OSGEO4W_ROOT'] = OSGEO4W
    os.environ['GDAL_DATA'] = OSGEO4W + r"\share\epsg_csv"
    os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
Sign up to request clarification or add additional context in comments.

Comments

0

May be some one have better solution but after applying number of fix I am able to find the only solution which worked for me that WSL and Remote debug in Pycharm. I have made a public gist you may try the settings. GeoDjango Configurations

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.