source: branches/0.5/win/PostNAS-0.5/bin/gdalchksum.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: gdalchksum.py 18194 2009-12-06 20:07:45Z rouault $
4#
5#  Project:  GDAL
6#  Purpose:  Application to checksum a GDAL image file.
7#  Author:   Frank Warmerdam, warmerdam@pobox.com
8#
9#******************************************************************************
10#  Copyright (c) 2003, Frank Warmerdam <warmerdam@pobox.com>
11#
12#  Permission is hereby granted, free of charge, to any person obtaining a
13#  copy of this software and associated documentation files (the "Software"),
14#  to deal in the Software without restriction, including without limitation
15#  the rights to use, copy, modify, merge, publish, distribute, sublicense,
16#  and/or sell copies of the Software, and to permit persons to whom the
17#  Software is furnished to do so, subject to the following conditions:
18#
19#  The above copyright notice and this permission notice shall be included
20#  in all copies or substantial portions of the Software.
21#
22#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23#  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28#  DEALINGS IN THE SOFTWARE.
29#******************************************************************************
30
31try:
32    from osgeo import gdal
33except ImportError:
34    import gdal
35
36import sys
37
38def Usage():
39    print('Usage: gdalchksum.py [-b band] [-srcwin xoff yoff xsize ysize] file')
40    sys.exit(1)
41
42# =============================================================================
43#       Mainline
44# =============================================================================
45
46srcwin = None
47bands = []
48
49filename = None
50
51gdal.AllRegister()
52argv = gdal.GeneralCmdLineProcessor( sys.argv )
53if argv is None:
54    sys.exit( 0 )
55
56# Parse command line arguments.
57i = 1
58while i < len(argv):
59    arg = argv[i]
60
61    if arg == '-b':
62        i = i + 1
63        bands.append( int(argv[i]) )
64
65    elif arg == '-srcwin':
66        srcwin = [int(argv[i+1]),int(argv[i+2]),
67                  int(argv[i+3]),int(argv[i+3]) ]
68        i = i + 4
69
70    elif filename is None:
71        filename = argv[i]
72
73    else:
74        Usage()
75
76    i = i + 1
77
78if filename is None:
79    Usage()
80   
81# Open source file
82
83ds = gdal.Open( filename )
84if ds is None:
85    print('Unable to open ', filename)
86    sys.exit(1)
87
88# Default values
89
90if srcwin is None:
91    srcwin = [ 0, 0, ds.RasterXSize, ds.RasterYSize ]
92
93if len(bands) == 0:
94    bands = list(range(1,(ds.RasterCount+1)))
95
96
97# Generate checksums
98
99for band_num in bands:
100    oBand = ds.GetRasterBand( band_num )
101    result = oBand.Checksum( srcwin[0], srcwin[1], srcwin[2], srcwin[3] )
102    print(result)
103
104ds = None
105
106
107
108
109
110
111
112
Note: See TracBrowser for help on using the repository browser.