Skip to content

Commit

Permalink
#59 added usage
Browse files Browse the repository at this point in the history
  • Loading branch information
smellman committed Mar 12, 2024
1 parent fa56771 commit 76255dd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)から取得できる。
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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空間情報センター <https://www.geospatial.jp/ckan/dataset/plateau>`_.

Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 28 additions & 6 deletions plateauutils/parser/city_gml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down Expand Up @@ -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)
# 返り値に入る値を作成
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions plateauutils/parser/tests/test_city_gml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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"] == "共同住宅"

0 comments on commit 76255dd

Please sign in to comment.