GDAL, ogr2ogr "Cannot find proj.db" Error
Asked Answered
C

4

14

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.

Caoutchouc answered 26/6, 2019 at 1:41 Comment(0)
R
21

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\"
Recrimination answered 9/9, 2019 at 11:52 Comment(1)
Determinant variable is PROJ_LIB, it must point the directory that contains proj.dbMetamerism
A
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.

Admiration answered 23/3, 2020 at 20:22 Comment(0)
H
6

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.

Halidom answered 16/7, 2019 at 16:25 Comment(0)
R
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.

Rollback answered 10/6, 2020 at 7:59 Comment(1)
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.Prytaneum

© 2022 - 2024 — McMap. All rights reserved.