GDAL, ogr2ogr "Cannot find proj.db" Error

Viewed 23219

I've tried to extract certain country from the world shp file from natural earth.

I am currently using windows 10, so I installed python 3.7, gdal to use the ogr2ogr.

I typed the below code in the command to extract the south korea

ogr2ogr -f GeoJSON -where "geonunit='South Korea'" korea-geo.json ne_10m_admin_1_states_provinces.shp

But the below errors are coming out.

ERROR 1: PROJ: proj_create_from_wkt: Cannot find proj.db

ERROR 1: PROJ: proj_identify: Cannot find proj.db

I already set up the environmental variables for Gdal..

C:\Program Files\GDAL\gdal-data

C:\Program Files\GDAL\gdalplugins

Please guide me to solve this problem.

4 Answers

Check your environment_variable:

setx GDAL_DATA "C:\Program Files\GDAL\gdal-data"

setx GDAL_DRIVER_PATH "C:\Program Files\GDAL\gdalplugins"

setx PROJ_LIB "C:\Program Files\GDAL\projlib"

setx PYTHONPATH "C:\Program Files\GDAL\"

Adding PROJ_DEBUG=3 to your environment_variable is very useful. The error message will then tell you where PROJ is expecting the file.

You might need to set the PROJ_LIB environment variable. But I'm not sure where that data lives on your system. It could also be affected by how you installed GDAL.

If you go into your C:\Program Files\GDAL directory, do you have a folder called proj? If so, see if it has proj.db file in it. If it does, that's your PROJ_LIB path value. You might also find it in some kind of share folder.

If you don't find it nested somewhere in your GDAL directory, try searching your system for the proj.db file, and ,if you find it, set that directory (NOT the full file path) as your PROJ_LIB value, reboot, and see if things start working.

Add these commands to your code at the beginning before importing GDAL. Your issue will be solved.

import os
os.environ['PROJ_LIB'] = 'C:\\Users\\Sai kiran\\anaconda3\\envs\\sai\\Library\\share\\proj'
os.environ['GDAL_DATA'] = 'C:\\Users\\Sai kiran\\anaconda3\\envs\sai\\Library\\share'

import gdal

Search for the location of your proj.db file in your anaconda directory and replace the same location with C:\\Users\\Sai kiran\\anaconda3\\envs\\sai\\Library\\share\\projin the above command. Also, replace the location of gdal folder in the anaconda directory as in the above example.

Related