13

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.

Yang JongHyun
  • 133
  • 1
  • 1
  • 6

4 Answers4

19

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\"
Alfonso Tienda
  • 3,442
  • 1
  • 19
  • 34
mrHalfer
  • 191
  • 1
  • 4
8

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

Brad DePottey
  • 81
  • 1
  • 1
5

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.

elrobis
  • 1,512
  • 2
  • 16
  • 22
5

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.

mArk
  • 630
  • 8
  • 13
  • the first line was all I needed in my case. All users should be aware that moving code between machines will require the directory location to be changed here. – Theo F Feb 02 '23 at 15:58