gdal2tilesp icon indicating copy to clipboard operation
gdal2tilesp copied to clipboard

Allow gdal2tilesp to be called directly from Python

Open mairsbw opened this issue 8 years ago • 0 comments

Instead of calling it from the command line I want to call it directly with Python like:

import gdal2tilesp

args = ['gdal2tiles', '-w', 'none', '-r', 'cubic', '-v', '--zoom', 'my_img.tf', 'results']
gdal2tilesp.main(args)

The patch is as follows:

From 2d7db54b02632535bf3c244dcfa4e9ab0aa8df7e Mon Sep 17 00:00:00 2001
From: Bryant Mairs <[email protected]>
Date: Thu, 8 Sep 2016 15:26:17 -0700
Subject: [PATCH] Support calling gdal2tiles through Python directly.

---
 gdal2tilesp.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gdal2tilesp.py b/gdal2tilesp.py
index ffc867b..4e9cd1c 100755
--- a/gdal2tilesp.py
+++ b/gdal2tilesp.py
@@ -2308,8 +2308,8 @@ def worker_overview_tiles(argv, cpu, tz):
    gdal2tiles.open_input()
    gdal2tiles.generate_overview_tiles(cpu, tz)

-if __name__=='__main__':
-   argv = gdal.GeneralCmdLineProcessor( sys.argv )
+def main(args):
+   argv = gdal.GeneralCmdLineProcessor( args )
    if argv:
        gdal2tiles = GDAL2Tiles( argv[1:] ) # handle command line options

@@ -2361,6 +2361,8 @@ if __name__=='__main__':
                    pass
            pool.join()

+if __name__=='__main__':
+   main(sys.argv)

 #############
 # vim:noet
-- 
1.9.1

mairsbw avatar Sep 08 '16 22:09 mairsbw