[23] | 1 | #!/usr/bin/env python |
---|
| 2 | #****************************************************************************** |
---|
| 3 | # $Id: esri2wkt.py 18194 2009-12-06 20:07:45Z rouault $ |
---|
| 4 | # |
---|
| 5 | # Project: GDAL |
---|
| 6 | # Purpose: Simple command line program for translating ESRI .prj files |
---|
| 7 | # into WKT. |
---|
| 8 | # Author: Frank Warmerdam, warmerda@home.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 | |
---|
| 32 | try: |
---|
| 33 | from osgeo import osr |
---|
| 34 | except ImportError: |
---|
| 35 | import osr |
---|
| 36 | |
---|
| 37 | import sys |
---|
| 38 | import string |
---|
| 39 | |
---|
| 40 | if len(sys.argv) < 2: |
---|
| 41 | print('Usage: esri2wkt.py <esri .prj file>') |
---|
| 42 | sys.exit(1) |
---|
| 43 | |
---|
| 44 | prj_fd = open( sys.argv[1] ) |
---|
| 45 | prj_lines = prj_fd.readlines() |
---|
| 46 | prj_fd.close() |
---|
| 47 | |
---|
| 48 | for i in range(len(prj_lines)): |
---|
| 49 | prj_lines[i] = string.rstrip( prj_lines[i] ) |
---|
| 50 | |
---|
| 51 | prj_srs = osr.SpatialReference() |
---|
| 52 | err = prj_srs.ImportFromESRI( prj_lines ) |
---|
| 53 | if err != 0: |
---|
| 54 | print('Error = ', err) |
---|
| 55 | else: |
---|
| 56 | print(prj_srs.ExportToPrettyWkt()) |
---|
| 57 | |
---|