forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ogr_gml_fgd_read.py
executable file
·118 lines (85 loc) · 3.98 KB
/
ogr_gml_fgd_read.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
#!/usr/bin/env pytest
# -*- coding: utf-8 -*-
###############################################################################
# $Id$
#
# Project: GDAL/OGR Test Suite
# Purpose: GML Reading Driver for Japanese FGD GML v4 testing.
# Author: Hiroshi Miura <[email protected]>
#
###############################################################################
# Copyright (c) 2017, Hiroshi Miura <[email protected]>
#
# 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 gdaltest
import ogrtest
from osgeo import gdal
from osgeo import ogr
from osgeo import osr
import pytest
###############################################################################
# Test reading Japanese FGD GML (v4) files
###############################################################################
_fgd_dir = 'data/gml_jpfgd/'
###############################################################################
# Test reading Japanese FGD GML (v4) ElevPt file
def test_ogr_gml_fgd_1():
gdaltest.have_gml_fgd_reader = 0
# open FGD GML file
ds = ogr.Open(_fgd_dir + 'ElevPt.xml')
if ds is None:
if gdal.GetLastErrorMsg().find('Xerces') != -1:
pytest.skip()
pytest.fail('failed to open test file.')
# we have gml reader for fgd
gdaltest.have_gml_fgd_reader = 1
# check number of layers
assert ds.GetLayerCount() == 1, 'Wrong layer count'
lyr = ds.GetLayer(0)
# check the SRS
sr = osr.SpatialReference()
sr.ImportFromEPSG(6668) # JGD2011
assert sr.IsSame(lyr.GetSpatialRef(), options = ['IGNORE_DATA_AXIS_TO_SRS_AXIS_MAPPING=YES']), 'Wrong SRS'
# check the first feature
feat = lyr.GetNextFeature()
assert not ogrtest.check_feature_geometry(feat, 'POINT (133.123456789 34.123456789)'), \
'Wrong geometry'
assert feat.GetField('devDate') == '2015-01-07', 'Wrong attribute value'
###############################################################################
# Test reading Japanese FGD GML (v4) BldA file
def test_ogr_gml_fgd_2():
if not gdaltest.have_gml_fgd_reader:
pytest.skip()
# open FGD GML file
ds = ogr.Open(_fgd_dir + 'BldA.xml')
# check number of layers
assert ds.GetLayerCount() == 1, 'Wrong layer count'
lyr = ds.GetLayer(0)
# check the SRS
sr = osr.SpatialReference()
sr.ImportFromEPSG(6668) # JGD2011
assert sr.IsSame(lyr.GetSpatialRef(), options = ['IGNORE_DATA_AXIS_TO_SRS_AXIS_MAPPING=YES']), 'Wrong SRS'
wkt = 'POLYGON ((139.718509733734 35.6952171397133,139.718444177734 35.6953121947133,139.718496754142 35.6953498949667,139.718550483734 35.6952359447133,139.718509733734 35.6952171397133))'
# check the first feature
feat = lyr.GetNextFeature()
assert not ogrtest.check_feature_geometry(feat, wkt), 'Wrong geometry'
assert feat.GetField('devDate') == '2017-03-07', 'Wrong attribute value'
###############################################################################
# List test cases