source: branches/0.5/win/PostNAS-0.5/bin/gdalimport.py @ 23

Revision 23, 2.9 KB checked in by astrid.emde, 14 years ago (diff)
Line 
1#!/usr/bin/env python
2#******************************************************************************
3#  $Id: gdalimport.py 18194 2009-12-06 20:07:45Z rouault $
4#
5#  Name:     gdalimport
6#  Project:  GDAL Python Interface
7#  Purpose:  Import a GDAL supported file to Tiled GeoTIFF, and build overviews
8#  Author:   Frank Warmerdam, warmerdam@pobox.com
9#
10#******************************************************************************
11#  Copyright (c) 2000, Frank Warmerdam
12#
13#  Permission is hereby granted, free of charge, to any person obtaining a
14#  copy of this software and associated documentation files (the "Software"),
15#  to deal in the Software without restriction, including without limitation
16#  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17#  and/or sell copies of the Software, and to permit persons to whom the
18#  Software is furnished to do so, subject to the following conditions:
19#
20#  The above copyright notice and this permission notice shall be included
21#  in all copies or substantial portions of the Software.
22#
23#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24#  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29#  DEALINGS IN THE SOFTWARE.
30#******************************************************************************
31
32try:
33    from osgeo import gdal
34except ImportError:
35    import gdal
36
37import sys
38import os.path
39
40gdal.AllRegister()
41argv = gdal.GeneralCmdLineProcessor( sys.argv )
42if argv is None:
43    sys.exit( 0 )
44
45if len(argv) < 2:
46    print("Usage: gdalimport.py [--help-general] source_file [newfile]")
47    sys.exit(1)
48
49def progress_cb( complete, message, cb_data ):
50    print(cb_data, complete)
51   
52
53filename = argv[1]
54dataset = gdal.Open( filename )
55if dataset is None:
56    print('Unable to open ', filename)
57    sys.exit(1)
58
59geotiff = gdal.GetDriverByName("GTiff")
60if geotiff is None:
61    print('GeoTIFF driver not registered.')
62    sys.exit(1)
63
64if len(argv) < 3:
65    newbase, ext = os.path.splitext(os.path.basename(filename))
66    newfile = newbase + ".tif"
67    i = 0
68    while os.path.isfile(newfile):
69        i = i+1
70        newfile = newbase+"_"+str(i)+".tif"
71else:
72    newfile = argv[2]
73
74print('Importing to Tiled GeoTIFF file:', newfile)
75new_dataset = geotiff.CreateCopy( newfile, dataset, 0,
76                                  ['TILED=YES',],
77                                  callback = progress_cb,
78                                  callback_data = 'Translate: ' )
79dataset = None
80
81print('Building overviews')
82new_dataset.BuildOverviews( "average", callback=progress_cb,
83                            callback_data = 'Overviews: ' )
84new_dataset = None
85
86print('Done')
87
88
89
Note: See TracBrowser for help on using the repository browser.