2

Windows10 64bit. I did a clean Python & GDAL install using the instructions on this site, but then for the latest 3.1.2 GDAL version and Python 3.7.9.

I'm trying to run a most basic gdal2tiles.py from CMD on a georeferenced (EPSG 31370) pdf:

gdal2tiles.py myfile.pdf

I got the error code below. I also tried running from the python IDLE with os.system, which of course returns the same error. I also tried with a georeferenced tiff without succes. I noticed the same error was posted recently on the OSGeo github issues page.

ERROR 1: PROJ: proj_create_from_database: Cannot find proj.db
Traceback (most recent call last):
  File "C:\Users\myuser\AppData\Local\Programs\Python\Python37\lib\site-packages\osgeo\osr.py", line 933, in __init__
    self.this.append(this)
AttributeError: 'SpatialReference' object has no attribute 'this'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\myuser\AppData\Local\Programs\Python\Python37\Scripts\gdal2tiles.py", line 2928, in <module>
    main()
  File "C:\Users\myuser\AppData\Local\Programs\Python\Python37\Scripts\gdal2tiles.py", line 2922, in main
    single_threaded_tiling(input_file, output_folder, options)
  File "C:\Users\myuser\AppData\Local\Programs\Python\Python37\Scripts\gdal2tiles.py", line 2849, in single_threaded_tiling
    conf, tile_details = worker_tile_details(input_file, output_folder, options)
  File "C:\Users\myuser\AppData\Local\Programs\Python\Python37\Scripts\gdal2tiles.py", line 2765, in worker_tile_details
    gdal2tiles.open_input()
  File "C:\Users\myuser\AppData\Local\Programs\Python\Python37\Scripts\gdal2tiles.py", line 1535, in open_input
    self.in_srs, self.in_srs_wkt = setup_input_srs(input_dataset, self.options)
  File "C:\Users\myuser\AppData\Local\Programs\Python\Python37\Scripts\gdal2tiles.py", line 737, in setup_input_srs
    input_srs = osr.SpatialReference()
  File "C:\Users\myuser\AppData\Local\Programs\Python\Python37\lib\site-packages\osgeo\osr.py", line 934, in __init__
    except __builtin__.Exception:
NameError: name '__builtin__' is not defined

Any ideas on how to fix this?

/EDIT/ I took a look at python37/lib/osgeo/site-packages/osr.py It says version 2.0.4, whereas on github the latest version is 3.0.12 I tried replacing the source code with this of version 3.0.12 This tiles are created, but throws the error below. The created tiles have the wrong numbering, so the spatialReference is still faulty.

ERROR 1: PROJ: proj_create_from_database: Cannot find proj.db
2

The steps below have fixed my problems, but I have no idea whether or not I messed up something different. Use at your own risk.

  1. Navigate to C:\Users\YOURUSER\AppData\Local\Programs\Python\Python37\Lib\site-packages. When I open osr.py I noticed this says version 2.0.4.
  2. I went to GDAL on github and looked for the source code of osr.py in GDAL 3.1. This says 3.0.12 so I replaced my local osr.py with the source code from Github
  3. Running gdal2tiles.py now gives an error ERROR 1: PROJ: proj_create_from_database: Cannot find proj.db. Tiles are created, but the geospatial reference is messed up.
  4. To fix this, I added following line to my system's environmental variables: Variable name: PROJ_LIB, variable value: C:\Program Files\GDAL\projlib

Tiles are created correctly now, though I don't know if this caused other problems.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.