From 76255ddcede3129c826b90386f994d91fd1a2aa5 Mon Sep 17 00:00:00 2001 From: Taro Matsuzawa Date: Tue, 12 Mar 2024 15:15:13 +0900 Subject: [PATCH] #59 added usage --- README.md | 2 +- README.rst | 2 +- doc/index.rst | 2 +- plateauutils/parser/city_gml_parser.py | 34 +++++++++++++++---- .../parser/tests/test_city_gml_parser.py | 2 ++ 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 515c498..7f061c3 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ CityGMLのパーサーするには、以下を参照してください。 >>> parser = CityGMLParser(target_polygon) >>> result = parser.download_and_parse("https://assets.cms.plateau.reearth.io/assets/d6/70821e-7f58-4f69-bc34-341875704e78/40203_kurume-shi_2020_citygml_3_op.zip", "/tmp") >>> result -[{'gid': 'bldg_383f1804-aa34-4634-949f-f769e09fa92d', 'center': [130.41263587199947, 33.22489181671553], 'min_height': 3.805999994277954, 'measured_height': 9.3, 'building_structure_type': '非木造'}, {'gid': 'bldg_877dea60-35d0-4fd9-8b02-852e39c75d81', 'center': [130.41619367090038, 33.22492719812357], 'min_height': 4.454999923706055, 'measured_height': 3.0, 'building_structure_type': '非木造'},...] +[{'gid': 'bldg_383f1804-aa34-4634-949f-f769e09fa92d', 'center': [130.41263587199947, 33.22489181671553], 'min_height': 3.805999994277954, 'measured_height': 9.3, 'building_structure_type': '非木造', 'usage': '運輸倉庫施設'}, {'gid': 'bldg_877dea60-35d0-4fd9-8b02-852e39c75d81', 'center': [130.41619367090038, 33.22492719812357], 'min_height': 4.454999923706055, 'measured_height': 3.0, 'building_structure_type': '非木造', 'usage': '共同住宅'},...] ``` 3D都市モデルのCityGMLのZIPファイルのURLは[G空間情報センター](https://www.geospatial.jp/ckan/dataset/plateau)から取得できる。 diff --git a/README.rst b/README.rst index fe79a74..ec2cd84 100644 --- a/README.rst +++ b/README.rst @@ -26,7 +26,7 @@ CityGML parser >>> parser = CityGMLParser(target_polygon) >>> result = parser.download_and_parse("https://assets.cms.plateau.reearth.io/assets/d6/70821e-7f58-4f69-bc34-341875704e78/40203_kurume-shi_2020_citygml_3_op.zip", "/tmp") >>> result - [{'gid': 'bldg_383f1804-aa34-4634-949f-f769e09fa92d', 'center': [130.41263587199947, 33.22489181671553], 'min_height': 3.805999994277954, 'measured_height': 9.3, 'building_structure_type': '非木造'}, {'gid': 'bldg_877dea60-35d0-4fd9-8b02-852e39c75d81', 'center': [130.41619367090038, 33.22492719812357], 'min_height': 4.454999923706055, 'measured_height': 3.0, 'building_structure_type': '非木造'},...] + [{'gid': 'bldg_383f1804-aa34-4634-949f-f769e09fa92d', 'center': [130.41263587199947, 33.22489181671553], 'min_height': 3.805999994277954, 'measured_height': 9.3, 'building_structure_type': '非木造', 'usage': '運輸倉庫施設'}, {'gid': 'bldg_877dea60-35d0-4fd9-8b02-852e39c75d81', 'center': [130.41619367090038, 33.22492719812357], 'min_height': 4.454999923706055, 'measured_height': 3.0, 'building_structure_type': '非木造', 'usage': '共同住宅'},...] URLs of CityGML zip files can be found at `G空間情報センター `_. diff --git a/doc/index.rst b/doc/index.rst index 978775b..4e2f913 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -47,7 +47,7 @@ CityGML and MvtTile parsers. >>> parser = CityGMLParser(target_polygon) >>> result = parser.download_and_parse("https://assets.cms.plateau.reearth.io/assets/d6/70821e-7f58-4f69-bc34-341875704e78/40203_kurume-shi_2020_citygml_3_op.zip", "/tmp") >>> result - [{'gid': 'bldg_383f1804-aa34-4634-949f-f769e09fa92d', 'center': [130.41263587199947, 33.22489181671553], 'min_height': 3.805999994277954, 'measured_height': 9.3, 'building_structure_type': '非木造'}, {'gid': 'bldg_877dea60-35d0-4fd9-8b02-852e39c75d81', 'center': [130.41619367090038, 33.22492719812357], 'min_height': 4.454999923706055, 'measured_height': 3.0, 'building_structure_type': '非木造'},...] + [{'gid': 'bldg_383f1804-aa34-4634-949f-f769e09fa92d', 'center': [130.41263587199947, 33.22489181671553], 'min_height': 3.805999994277954, 'measured_height': 9.3, 'building_structure_type': '非木造', 'usage': '運輸倉庫施設'}, {'gid': 'bldg_877dea60-35d0-4fd9-8b02-852e39c75d81', 'center': [130.41619367090038, 33.22492719812357], 'min_height': 4.454999923706055, 'measured_height': 3.0, 'building_structure_type': '非木造', 'usage': '共同住宅'},...] >>> from plateauutils.parser.mvt_tile_parser import MvtTileParser >>> target_polygon = from_wkt("POLYGON ((130.525689 33.323966, 130.522728 33.314069, 130.511441 33.308653, 130.501013 33.30937, 130.492516 33.318516, 130.493717 33.325831, 130.504618 33.332249, 130.512857 33.332213, 130.525689 33.323966))") >>> parser = MvtTileParser(target_polygon) diff --git a/plateauutils/parser/city_gml_parser.py b/plateauutils/parser/city_gml_parser.py index 316967d..4bfcb9d 100644 --- a/plateauutils/parser/city_gml_parser.py +++ b/plateauutils/parser/city_gml_parser.py @@ -96,9 +96,9 @@ def parse(self, target_path: str = "") -> list: ) > 0 ): - ns[ - "uro" - ] = "http://www.kantei.go.jp/jp/singi/tiiki/toshisaisei/itoshisaisei/iur/uro/1.4" + ns["uro"] = ( + "http://www.kantei.go.jp/jp/singi/tiiki/toshisaisei/itoshisaisei/iur/uro/1.4" + ) version = 1 elif ( len( @@ -108,9 +108,9 @@ def parse(self, target_path: str = "") -> list: ) > 0 ): - ns[ - "uro" - ] = "https://www.chisou.go.jp/tiiki/toshisaisei/itoshisaisei/iur/uro/1.5" + ns["uro"] = ( + "https://www.chisou.go.jp/tiiki/toshisaisei/itoshisaisei/iur/uro/1.5" + ) version = 1 # versionがNoneならエラーとする if version is None: @@ -226,6 +226,27 @@ def _parse( except AttributeError: print("uro:buildingStructureType is NoneType in", gid, "in", target) building_structure_type_text = None + try: + # bldg:usageを取得 + usage = city_object_member.find(".//bldg:usage", ns) + # bldg:usageのdescriptionを取得 + usage_xml_path = os.path.normpath( + os.path.join(target, "..", "../../codelists/Building_usage.xml") + ) + usage_xml_root = ET.fromstring(zip_file.read(usage_xml_path)) + usage_text = None + for usage_xml_root_child in usage_xml_root.findall( + ".//gml:dictionaryEntry", ns + ): + gml_name = usage_xml_root_child.find(".//gml:name", ns) + if str(gml_name.text) == str(usage.text): + usage_text = str( + usage_xml_root_child.find(".//gml:description", ns).text + ) + break + except AttributeError: + print("bldg:usage is NoneType in", gid, "in", target) + usage_text = None # bldg:lod1Solidを取得 lod1_solid = city_object_member.find(".//bldg:lod1Solid", ns) # 返り値に入る値を作成 @@ -235,6 +256,7 @@ def _parse( "min_height": 10000, "measured_height": measured_height, "building_structure_type": building_structure_type_text, + "usage": usage_text, } # gml:posListを取得 pos_lists = lod1_solid.findall(".//gml:posList", ns) diff --git a/plateauutils/parser/tests/test_city_gml_parser.py b/plateauutils/parser/tests/test_city_gml_parser.py index f2f834f..994f227 100644 --- a/plateauutils/parser/tests/test_city_gml_parser.py +++ b/plateauutils/parser/tests/test_city_gml_parser.py @@ -18,6 +18,7 @@ def test_citygml_parser_v2(): assert result[0]["min_height"] == 3.805999994277954 assert result[0]["measured_height"] == 9.3 assert result[0]["building_structure_type"] == "非木造" + assert result[0]["usage"] == "運輸倉庫施設" def test_citygml_parser_v1_4(): @@ -35,3 +36,4 @@ def test_citygml_parser_v1_4(): assert result[0]["min_height"] == 4.454999923706055 assert result[0]["measured_height"] == 3.0 assert result[0]["building_structure_type"] == "非木造" + assert result[0]["usage"] == "共同住宅"