12

I start using GDAL 3.0.0 using conda build. I successfully installed GDAL on my laptop (Windows 10) and I am trying to ingest MapInfo tab file into Elasticsearch index. I understood that I have to create mapping first before ingesting it into Elasticsearch.

ogr2ogr -progress -lco MAPPING="D:\mymappings\map.text" -f "ElasticSearch" http://localhost:9700 "D:\MIProTab.tab"

But when I try to execute the above command then it is giving me the following error:

C:\Users\ABCD>ogr2ogr -progress -lco MAPPING="D:\mymappings\map.text" -f "ElasticSearch" http://localhost:9700 "D:\MIProTab.tab"
ERROR 1: PROJ: pj_obj_create: Cannot find proj.db
ERROR 1: PROJ: createGeodeticReferenceFrame: Cannot find proj.db
ERROR 1: PROJ: proj_as_wkt: Cannot find proj.db
ERROR 1: PROJ: proj_create_from_wkt: Cannot find proj.db
ERROR 1: PROJ: createGeodeticReferenceFrame: Cannot find proj.db
ERROR 1: PROJ: proj_create_from_database: Cannot find proj.db
ERROR 1: PROJ: proj_as_wkt: Cannot find proj.db
ERROR 1: PROJ: proj_create_from_wkt: Cannot find proj.db
ERROR 1: PROJ: proj_create_from_wkt: Cannot find proj.db
ERROR 1: PROJ: proj_as_wkt: Cannot find proj.db
ERROR 1: PROJ: proj_as_wkt: Cannot find proj.db
0...10...20...30...40...50...60...70...80...90...100 - done.

C:\Users\ABCD>

I checked other's solution where it is mentioned to have gdal.dll to be present on the same directory where ogr2ogr is present. Also, I have set the environment variable "PROJ_LIB" but all went in vain. What is wrong here?

Mike T
  • 42,095
  • 10
  • 126
  • 187
Praveen Kumar
  • 141
  • 1
  • 1
  • 7

6 Answers6

13

I set the PROJ_LIB environment variable to point to the PROJ.4 data directory (where proj.db lives) and this problem has been solved,hope that is useful to you.

Zzzxs
  • 131
  • 2
  • Sorry. but it didn't solve my problem. – Praveen Kumar Jul 01 '19 at 05:34
  • Yes this solved my problem. Of course you have to restart the software (including shells such as cmd boxes) to load this new environment setting into the ogr2ogr environment. – anneb Sep 14 '19 at 14:14
  • While importing pyproj in the python virtual environment the error I got was EPSG code is unknown. PROJ: proj_create_from_database: C:\Program Files\PostgreSQL\13\share\contrib\postgis-3.0\proj\proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation. The conflict was because the pyproj was also installed in PostgreSQL, I Changed environment variable to directory where pyproj was installed in the virtual environent to C:\python_envs\geocube\Lib\site-packages\pyproj\proj_dir\share\proj and it resolved the issue. – Abhilash Singh Chauhan Jul 08 '22 at 07:29
11

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\"
TomazicM
  • 25,601
  • 22
  • 29
  • 39
mrHalfer
  • 211
  • 2
  • 2
  • suggest using 'set', instead of the permanent 'setx' – Theo F Dec 17 '19 at 13:30
  • 1
    Thanks this helped. For @TheoF in windows 10 you need to use setx if you want it to be a permanent change: https://superuser.com/questions/916649/what-is-the-difference-between-setx-and-set-in-environment-variables-in-windows – HeikkiVesanto Jan 03 '20 at 11:38
  • @HeikkiVesanto yes, like I said. I suggest not using setx for testing. – Theo F Jan 03 '20 at 16:06
5

Add these commands to your code at the beginning. 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'

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, specify the location of gdal folder in the anaconda directory as in the above example.

mArk
  • 196
  • 1
  • 10
1

To use GDAL and/or PROJ from conda, you need to activate the environment, which sets the necessary environment variables (including GDAL_DATA and PROJ_LIB).

If you have conda on your path, it's simply conda activate base (or other environment).


If you don't have conda on your path, you can activate this a bit differently. For example, to activate the "base" Anaconda3 environment for Windows:

call %LOCALAPPDATA%\Continuum\anaconda3\Scripts\activate.bat base

Or for Linux:

. $HOME/anaconda3/bin/activate base
Mike T
  • 42,095
  • 10
  • 126
  • 187
0

This is fairly straightforward once you know how to prepare the command environment - that was the bit I couldn't figure out. You can do as above or if you have already installed QGIS then this should work:

ogr2ogr is the tool but in order to use it some parameters qgis takes care of must be known (like where the projection information is) by the stand alone utility:

  1. If ogr2ogr was installed with QGIS (like mine was) then start a cmd session in C:\Program Files\QGIS 3.4\bin
  2. Run o4w_env.bat - this sets all the environment variables required to use ogr at the cmd
  3. Execute your export command. In my case it was
    ogr2ogr.exe -f SQLite -dsco SPATIALITE=yes "C:\temp\osm_lines" PG:"dbname=thedbasename user=theuser password=thepwd" public.planet_osm_line
    

This link was helpful for the ogr2ogr cmd syntax.

https://trac.osgeo.org/postgis/wiki/SpatiaLite

Noura
  • 3,429
  • 3
  • 20
  • 41
kingmi
  • 138
  • 3
-1

I tried following method and succeed:

os.environ['PROJ_LIB'] = r'E:\Programs\anaconda3\envs\gis\Library\share\proj'
TomazicM
  • 25,601
  • 22
  • 29
  • 39