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

Revision 23, 2.4 KB checked in by astrid.emde, 14 years ago (diff)
Line 
1#!/usr/bin/env python
2#******************************************************************************
3#  $Id: gcps2wld.py 18194 2009-12-06 20:07:45Z rouault $
4#
5#  Name:     gcps2wld
6#  Project:  GDAL Python Interface
7#  Purpose:  Translate the set of GCPs on a file into first order approximation
8#            in world file format.
9#  Author:   Frank Warmerdam, warmerdam@pobox.com
10#
11#******************************************************************************
12#  Copyright (c) 2002, Frank Warmerdam
13#
14#  Permission is hereby granted, free of charge, to any person obtaining a
15#  copy of this software and associated documentation files (the "Software"),
16#  to deal in the Software without restriction, including without limitation
17#  the rights to use, copy, modify, merge, publish, distribute, sublicense,
18#  and/or sell copies of the Software, and to permit persons to whom the
19#  Software is furnished to do so, subject to the following conditions:
20#
21#  The above copyright notice and this permission notice shall be included
22#  in all copies or substantial portions of the Software.
23#
24#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25#  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30#  DEALINGS IN THE SOFTWARE.
31#******************************************************************************
32
33try:
34    from osgeo import gdal
35except ImportError:
36    import gdal
37
38import sys
39import os.path
40
41if len(sys.argv) < 2:
42    print("Usage: gcps2wld.py source_file")
43    sys.exit(1)
44
45   
46
47filename = sys.argv[1]
48dataset = gdal.Open( filename )
49if dataset is None:
50    print('Unable to open ', filename)
51    sys.exit(1)
52
53gcps = dataset.GetGCPs()
54
55if gcps is None or len(gcps) == 0:
56    print('No GCPs found on file ' + filename)
57    sys.exit(1)
58
59geotransform = gdal.GCPsToGeoTransform( gcps )
60
61if geotransform is None:
62    print('Unable to extract a geotransform.')
63    sys.exit( 1 )
64
65print(geotransform[1])
66print(geotransform[4])
67print(geotransform[2])
68print(geotransform[5])
69print(geotransform[0] + 0.5 * geotransform[1] + 0.5 * geotransform[2])
70print(geotransform[3] + 0.5 * geotransform[4] + 0.5 * geotransform[5])
71
72
Note: See TracBrowser for help on using the repository browser.