3

I spent the whole day trying to install GDAL binding for Python. And now it seems to work. At least this import statement now does not produce any error messages:

from osgeo import gdal

now I want to use this creature, which is supposed for creating tiles.I tried two different ways:

import gdal_retile

and

from osgeo import gdal_retile

But they do not work.

How can I use this functionality?

2 Answers 2

2

gdal_retile.py is a Python script that makes use of the GDAL Python bindings but cannot be imported as a class or function. Depending on your GDAL version (>2.0) you can import most gdal utilities (gdalwarp, gdal_translate, ...) but not the Python scripts.

You can look at the source code of gdal_retile.py and pick out the functions you want to use and import them.

Alternatively you can call it as is (a command line utility) with subprocess.

0
0

@Kersten is right. Create a folder with a custom library name. Copy gdal_retile.py into this folder. Within this folder, create any empty python file init.py.

mygdal
 __init__.py 
 my_gdal_retile.py

Start using this library in your code by importing it. The example below is for the simple task of generating tiles.

  from mygdal import my_gdal_retile
    from mygdal.my_gdal_retile import *
    import pandas as pd
    from osgeo import gdal
    command="gdal_retile.py  -ps 512 512 -overlap 128  \
           -targetDir  MyTiles  MyGeotiff.tif -v"    
    my_gdal_retile.main(command.split())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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