forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosr_xml.py
executable file
·225 lines (197 loc) · 8.38 KB
/
osr_xml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env python
###############################################################################
# $Id$
#
# Project: GDAL/OGR Test Suite
# Purpose: Test OSR XML import/export
# Author: Even Rouault, <even dot rouault at mines dash paris dot org>
#
###############################################################################
# Copyright (c) 2009, Even Rouault <even dot rouault at mines-paris dot org>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
###############################################################################
import re
import sys
sys.path.append('../pymod')
import gdaltest
from osgeo import osr
###############################################################################
# Test the osr.SpatialReference.ImportFromXML() function.
#
def osr_xml_1():
gdaltest.srs_xml = """<gml:ProjectedCRS>
<gml:srsName>WGS 84 / UTM zone 31N</gml:srsName>
<gml:srsID>
<gml:name codeSpace="urn:ogc:def:crs:EPSG::">32631</gml:name>
</gml:srsID>
<gml:baseCRS>
<gml:GeographicCRS>
<gml:srsName>WGS 84</gml:srsName>
<gml:srsID>
<gml:name codeSpace="urn:ogc:def:crs:EPSG::">4326</gml:name>
</gml:srsID>
<gml:usesEllipsoidalCS>
<gml:EllipsoidalCS>
<gml:csName>ellipsoidal</gml:csName>
<gml:csID>
<gml:name codeSpace="urn:ogc:def:cs:EPSG::">6402</gml:name>
</gml:csID>
<gml:usesAxis>
<gml:CoordinateSystemAxis gml:uom="urn:ogc:def:uom:EPSG::9102">
<gml:name>Geodetic latitude</gml:name>
<gml:axisID>
<gml:name codeSpace="urn:ogc:def:axis:EPSG::">9901</gml:name>
</gml:axisID>
<gml:axisAbbrev>Lat</gml:axisAbbrev>
<gml:axisDirection>north</gml:axisDirection>
</gml:CoordinateSystemAxis>
</gml:usesAxis>
<gml:usesAxis>
<gml:CoordinateSystemAxis gml:uom="urn:ogc:def:uom:EPSG::9102">
<gml:name>Geodetic longitude</gml:name>
<gml:axisID>
<gml:name codeSpace="urn:ogc:def:axis:EPSG::">9902</gml:name>
</gml:axisID>
<gml:axisAbbrev>Lon</gml:axisAbbrev>
<gml:axisDirection>east</gml:axisDirection>
</gml:CoordinateSystemAxis>
</gml:usesAxis>
</gml:EllipsoidalCS>
</gml:usesEllipsoidalCS>
<gml:usesGeodeticDatum>
<gml:GeodeticDatum>
<gml:datumName>WGS_1984</gml:datumName>
<gml:datumID>
<gml:name codeSpace="urn:ogc:def:datum:EPSG::">6326</gml:name>
</gml:datumID>
<gml:usesPrimeMeridian>
<gml:PrimeMeridian>
<gml:meridianName>Greenwich</gml:meridianName>
<gml:meridianID>
<gml:name codeSpace="urn:ogc:def:meridian:EPSG::">8901</gml:name>
</gml:meridianID>
<gml:greenwichLongitude>
<gml:angle uom="urn:ogc:def:uom:EPSG::9102">0</gml:angle>
</gml:greenwichLongitude>
</gml:PrimeMeridian>
</gml:usesPrimeMeridian>
<gml:usesEllipsoid>
<gml:Ellipsoid>
<gml:ellipsoidName>WGS 84</gml:ellipsoidName>
<gml:ellipsoidID>
<gml:name codeSpace="urn:ogc:def:ellipsoid:EPSG::">7030</gml:name>
</gml:ellipsoidID>
<gml:semiMajorAxis uom="urn:ogc:def:uom:EPSG::9001">6378137</gml:semiMajorAxis>
<gml:secondDefiningParameter>
<gml:inverseFlattening uom="urn:ogc:def:uom:EPSG::9201">298.257223563</gml:inverseFlattening>
</gml:secondDefiningParameter>
</gml:Ellipsoid>
</gml:usesEllipsoid>
</gml:GeodeticDatum>
</gml:usesGeodeticDatum>
</gml:GeographicCRS>
</gml:baseCRS>
<gml:definedByConversion>
<gml:Conversion>
<gml:coordinateOperationName>Transverse_Mercator</gml:coordinateOperationName>
<gml:usesMethod xlink:href="urn:ogc:def:method:EPSG::9807" />
<gml:usesValue>
<gml:value uom="urn:ogc:def:uom:EPSG::9102">0</gml:value>
<gml:valueOfParameter xlink:href="urn:ogc:def:parameter:EPSG::8801" />
</gml:usesValue>
<gml:usesValue>
<gml:value uom="urn:ogc:def:uom:EPSG::9102">3</gml:value>
<gml:valueOfParameter xlink:href="urn:ogc:def:parameter:EPSG::8802" />
</gml:usesValue>
<gml:usesValue>
<gml:value uom="urn:ogc:def:uom:EPSG::9001">0.9996</gml:value>
<gml:valueOfParameter xlink:href="urn:ogc:def:parameter:EPSG::8805" />
</gml:usesValue>
<gml:usesValue>
<gml:value uom="urn:ogc:def:uom:EPSG::9001">500000</gml:value>
<gml:valueOfParameter xlink:href="urn:ogc:def:parameter:EPSG::8806" />
</gml:usesValue>
<gml:usesValue>
<gml:value uom="urn:ogc:def:uom:EPSG::9001">0</gml:value>
<gml:valueOfParameter xlink:href="urn:ogc:def:parameter:EPSG::8807" />
</gml:usesValue>
</gml:Conversion>
</gml:definedByConversion>
<gml:usesCartesianCS>
<gml:CartesianCS>
<gml:csName>Cartesian</gml:csName>
<gml:csID>
<gml:name codeSpace="urn:ogc:def:cs:EPSG::">4400</gml:name>
</gml:csID>
<gml:usesAxis>
<gml:CoordinateSystemAxis gml:uom="urn:ogc:def:uom:EPSG::9001">
<gml:name>Easting</gml:name>
<gml:axisID>
<gml:name codeSpace="urn:ogc:def:axis:EPSG::">9906</gml:name>
</gml:axisID>
<gml:axisAbbrev>E</gml:axisAbbrev>
<gml:axisDirection>east</gml:axisDirection>
</gml:CoordinateSystemAxis>
</gml:usesAxis>
<gml:usesAxis>
<gml:CoordinateSystemAxis gml:uom="urn:ogc:def:uom:EPSG::9001">
<gml:name>Northing</gml:name>
<gml:axisID>
<gml:name codeSpace="urn:ogc:def:axis:EPSG::">9907</gml:name>
</gml:axisID>
<gml:axisAbbrev>N</gml:axisAbbrev>
<gml:axisDirection>north</gml:axisDirection>
</gml:CoordinateSystemAxis>
</gml:usesAxis>
</gml:CartesianCS>
</gml:usesCartesianCS>
</gml:ProjectedCRS>
"""
gdaltest.srs_wkt = """PROJCS["WGS 84 / UTM zone 31N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1],AUTHORITY["EPSG","32631"]]"""
srs = osr.SpatialReference()
srs.ImportFromXML(gdaltest.srs_xml)
got = srs.ExportToWkt()
expected = gdaltest.srs_wkt
if got != expected:
print(got)
return 'fail'
return 'success'
###############################################################################
# Test the osr.SpatialReference.ExportToXML() function.
#
def osr_xml_2():
srs = osr.SpatialReference()
srs.ImportFromWkt(gdaltest.srs_wkt)
expected = gdaltest.srs_xml
got = srs.ExportToXML()
# Strip the gml:id tags
got = re.sub(r' gml:id="[^"]*"', '', got, 0)
expected = re.sub(r' gml:id="[^"]*"', '', expected, 0)
if got != expected:
print(got)
return 'fail'
return 'success'
gdaltest_list = [
osr_xml_1,
osr_xml_2]
if __name__ == '__main__':
gdaltest.setup_run('osr_xml')
gdaltest.run_tests(gdaltest_list)
gdaltest.summarize()