Package osgeo :: Package utils :: Module gcps2wld |
[hide private]
[frames] | no frames]

# Source Code for Module osgeo.utils.gcps2wld

     1  #!/usr/bin/env python3
     2  # ******************************************************************************
     3  #  $Id$
     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  #  Copyright (c) 2009-2010, Even Rouault <even dot rouault at spatialys.com>
    14  #
    15  #  Permission is hereby granted, free of charge, to any person obtaining a
    16  #  copy of this software and associated documentation files (the "Software"),
    17  #  to deal in the Software without restriction, including without limitation
    18  #  the rights to use, copy, modify, merge, publish, distribute, sublicense,
    19  #  and/or sell copies of the Software, and to permit persons to whom the
    20  #  Software is furnished to do so, subject to the following conditions:
    21  #
    22  #  The above copyright notice and this permission notice shall be included
    23  #  in all copies or substantial portions of the Software.
    24  #
    25  #  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    26  #  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    27  #  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    28  #  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    29  #  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    30  #  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    31  #  DEALINGS IN THE SOFTWARE.
    32  # ******************************************************************************
    33
    34  import sys
    35
    36  from osgeo import gdal
    37
    38
    39 -def main(argv):
    40      if len(argv) < 2:
    41          print("Usage: gcps2wld.py source_file")
    42          sys.exit(1)
    43
    44      filename = argv[1]
    45      dataset = gdal.Open(filename)
    46      if dataset is None:
    47          print('Unable to open %s' % filename)
    48          sys.exit(1)
    49
    50      gcps = dataset.GetGCPs()
    51
    52      if gcps is None or not gcps:
    53          print('No GCPs found on file ' + filename)
    54          sys.exit(1)
    55
    56      geotransform = gdal.GCPsToGeoTransform(gcps)
    57
    58      if geotransform is None:
    59          print('Unable to extract a geotransform.')
    60          sys.exit(1)
    61
    62      print(geotransform[1])
    63      print(geotransform[4])
    64      print(geotransform[2])
    65      print(geotransform[5])
    66      print(geotransform[0] + 0.5 * geotransform[1] + 0.5 * geotransform[2])
    67      print(geotransform[3] + 0.5 * geotransform[4] + 0.5 * geotransform[5])
    68
    69
    70  if __name__ == '__main__':
    71      sys.exit(main(sys.argv))
    72