@@ -24,7 +24,7 @@ class ParseOptions:
24
24
25
25
26
26
class Feature (TypedDict ):
27
- """GeoJSON Feature """
27
+ """GeoJSON-like feature representation """
28
28
29
29
type : str
30
30
geometry : Dict [str , list ]
@@ -95,7 +95,6 @@ def _parse_curves(
95
95
96
96
curve_id = curve .attrib ["id" ]
97
97
assert x is not None and y is not None
98
- assert curve_id not in curves
99
98
100
99
curves [curve_id ] = (x , y )
101
100
@@ -107,23 +106,32 @@ def _parse_surfaces(
107
106
) -> Dict [str , Surface ]:
108
107
surfaces : Dict [str , Surface ] = {}
109
108
for surface in spatial_elem .iterfind ("./zmn:GM_Surface" , _NS ):
110
- assert surface .find (".//zmn:GM_SurfaceBoundary.exterior" , _NS ) is not None
111
109
polygons = surface .findall ("./zmn:GM_Surface.patch/zmn:GM_Polygon" , _NS )
112
110
assert len (polygons ) == 1
113
111
polygon = polygons [0 ]
114
-
115
112
surface_id = surface .attrib ["id" ]
116
- surface_curves : list [tuple [float , float ]] = []
117
- for cc in polygon .iterfind (".//zmn:GM_CompositeCurve.generator" , _NS ):
113
+ rings : list [list [tuple [float , float ]]] = []
114
+
115
+ exterior = polygon .find (".//zmn:GM_SurfaceBoundary.exterior" , _NS )
116
+ ring : list [tuple [float , float ]] = []
117
+ for cc in exterior .find (".//zmn:GM_Ring" , _NS ):
118
118
curve_id = cc .attrib ["idref" ]
119
119
assert curve_id in curves
120
- assert surface_id not in surface_curves
121
- surface_curves .append (curves [curve_id ])
120
+ ring .append (curves [curve_id ])
121
+ ring .append (ring [0 ])
122
+ rings .append (ring )
123
+
124
+ for interior in polygon .iterfind (".//zmn:GM_SurfaceBoundary.interior" , _NS ):
125
+ ring : list [tuple [float , float ]] = []
126
+ for cc in interior .find (".//zmn:GM_Ring" , _NS ):
127
+ curve_id = cc .attrib ["idref" ]
128
+ assert curve_id in curves
129
+ ring .append (curves [curve_id ])
130
+ ring .append (ring [0 ])
131
+ rings .append (ring )
122
132
123
133
assert surface_id not in surfaces
124
- assert len (surface_curves ) > 0 , surface_id
125
- surface_curves .append (surface_curves [0 ])
126
- surfaces [surface_id ] = [[surface_curves ]]
134
+ surfaces [surface_id ] = [rings ]
127
135
128
136
return surfaces
129
137
@@ -189,18 +197,16 @@ def parse_raw(content: bytes, options: ParseOptions) -> List[Feature]:
189
197
"""Parse raw XML content and get a list of features."""
190
198
doc = et .fromstring (content , None )
191
199
192
- # 基本情報を取得
193
- base_props = _parse_base_properties (doc )
200
+ # このファイルの座標参照系を取得する
194
201
source_crs = CRS_MAP [doc .find ("./座標系" , _NS ).text ]
195
-
196
202
if (not options .include_arbitrary_crs ) and source_crs is None :
197
203
return []
198
204
199
205
spatial_elem = doc .find ("./空間属性" , _NS )
200
206
points = _parse_points (spatial_elem )
201
207
curves = _parse_curves (spatial_elem , points )
202
208
203
- # 平面直交座標系を WGS84 に変換する
209
+ # 平面直角座標系を WGS84 に変換する
204
210
if source_crs is not None :
205
211
transformer = pyproj .Transformer .from_crs (
206
212
source_crs , "epsg:4326" , always_xy = True
@@ -245,6 +251,7 @@ def parse_raw(content: bytes, options: ParseOptions) -> List[Feature]:
245
251
)
246
252
247
253
# XMLのルート要素にある属性情報をFeatureのプロパティに追加する
254
+ base_props = _parse_base_properties (doc )
248
255
for feature in features :
249
256
feature ["properties" ].update (base_props )
250
257
0 commit comments