@@ -50,25 +50,16 @@ def parse(self, target_path: str = "") -> list:
50
50
for target in self .targets :
51
51
path = os .path .join ("udx" , "bldg" , target + "_bldg" )
52
52
if name .find (path ) >= 0 :
53
- hit_targets .append (target )
53
+ hit_targets .append (name )
54
54
if len (hit_targets ) == 0 :
55
55
raise ValueError (f"target_path: { target_path } is not target" )
56
- # zipファイルを解凍する
57
- unarchived_dir = target_path .replace (".zip" , "" )
58
- shutil .unpack_archive (target_path , unarchived_dir )
59
56
# 返り値を作成
60
57
return_list = []
61
- # 解凍したファイルをパースする
62
- for target in hit_targets :
63
- # ファイルパスを作成
64
- target_file_path = os .path .join (
65
- unarchived_dir , "*" , "udx" , "bldg" , target + "_bldg_*.gml"
66
- )
67
- # ファイルが二つ以上ある場合に対応させる
68
- for file_path in glob .glob (target_file_path ):
58
+ with zipfile .ZipFile (target_path ) as zip_file :
59
+ # 解凍したファイルをパースする
60
+ for target in hit_targets :
69
61
# XMLのオブジェクトとして読み込む
70
- tree = ET .parse (file_path )
71
- root = tree .getroot ()
62
+ root = ET .fromstring (zip_file .read (target ))
72
63
# namespaceを作成
73
64
ns = {
74
65
"core" : "http://www.opengis.net/citygml/2.0" ,
@@ -127,7 +118,7 @@ def parse(self, target_path: str = "") -> list:
127
118
if version is None :
128
119
raise ValueError ("version is None" )
129
120
# パース処理を実施する
130
- ret = self ._parse (root , file_path , ns , version )
121
+ ret = self ._parse (root , target , zip_file , ns , version )
131
122
# 返り値に追加
132
123
return_list .extend (ret )
133
124
# 返り値を返却
@@ -175,7 +166,14 @@ def _target_list(self, polygon: Polygon = None) -> list:
175
166
# 返り値を返す
176
167
return return_list
177
168
178
- def _parse (self , root : ET .Element , file_path : str , ns : dict , version : int ) -> list :
169
+ def _parse (
170
+ self ,
171
+ root : ET .Element ,
172
+ target : str ,
173
+ zip_file : zipfile .ZipFile ,
174
+ ns : dict ,
175
+ version : int ,
176
+ ) -> list :
179
177
# 返り値を作成
180
178
return_list = []
181
179
# core:cityObjectMemberの一覧を取得
@@ -206,12 +204,10 @@ def _parse(self, root: ET.Element, file_path: str, ns: dict, version: int) -> li
206
204
# uro:codeSpaceを取得
207
205
code_space = building_structure_type .get ("codeSpace" )
208
206
# codeSpaceから値を取得
209
- code_space_root = ET .parse (
210
- os .path .abspath (os .path .join (file_path , ".." , code_space ))
211
- )
212
- code_space_root_root = code_space_root .getroot ()
207
+ code_space_path = os .path .normpath (os .path .join (target , ".." , code_space ))
208
+ code_space_root = ET .fromstring (zip_file .read (code_space_path ))
213
209
building_structure_type_text = None
214
- for code_space_root_root_child in code_space_root_root .findall (
210
+ for code_space_root_root_child in code_space_root .findall (
215
211
".//gml:dictionaryEntry" , ns
216
212
):
217
213
gml_name = code_space_root_root_child .find (".//gml:name" , ns )
0 commit comments