From 1c41c131d1cc208fa1f579832723f6883ee67a4a Mon Sep 17 00:00:00 2001 From: Bryn Pickering <17178478+brynpickering@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:12:49 +0200 Subject: [PATCH] Coerce ID to string --- src/osmox/build.py | 4 +- tests/fixtures/test_config_infill.json | 176 +++++++++++++++++++++++++ tests/test_activityhandler.py | 4 +- tests/test_cli.py | 11 +- 4 files changed, 188 insertions(+), 7 deletions(-) create mode 100644 tests/fixtures/test_config_infill.json diff --git a/src/osmox/build.py b/src/osmox/build.py index 455ffeb..f67f7cb 100644 --- a/src/osmox/build.py +++ b/src/osmox/build.py @@ -164,7 +164,7 @@ def summary(self): Returbn a dict summary. """ fixed = { - "id": self.idx, + "id": str(self.idx), "activities": ",".join(self.activities), "geometry": self.geom.centroid, } @@ -175,7 +175,7 @@ def single_activity_summaries(self): Yield (dict) summaries for each each activity of an object. """ for act in self.activities: - fixed = {"id": self.idx, "activity": act, "geometry": self.geom.centroid} + fixed = {"id": str(self.idx), "activity": act, "geometry": self.geom.centroid} yield {**fixed, **self.features} diff --git a/tests/fixtures/test_config_infill.json b/tests/fixtures/test_config_infill.json new file mode 100644 index 0000000..0e51c61 --- /dev/null +++ b/tests/fixtures/test_config_infill.json @@ -0,0 +1,176 @@ +{ + "filter": { + "building": [ + "apartments", + "bungalow", + "detached", + "dormitory", + "hotel", + "residential", + "semidetached_house", + "terrace", + "commercial", + "retail", + "supermarket", + "industrial", + "office", + "warehouse", + "bakehouse", + "firestation", + "government", + "cathedral", + "chapel", + "church", + "mosque", + "religous", + "shrine", + "synagogue", + "temple", + "hospital", + "kindergarden", + "school", + "university", + "college", + "sports_hall", + "stadium", + "yes" + ] + }, + + "object_features": ["units", "levels", "area", "floor_area"], + + "distance_to_nearest": ["transit"], + + "default_tags": [["building", "residential"]], + + "activity_mapping": { + "building": { + "apartments": ["home"], + "bungalow": ["home"], + "detached": ["home"], + "dormitory": ["home"], + "hotel": ["home"], + "residential": ["home"], + "semidetached_house": ["home"], + "terrace": ["home"], + "commercial": ["shop", "work", "delivery"], + "retail": ["shop", "work", "delivery"], + "supermarket": ["shop_food", "work", "delivery"], + "industrial": ["work", "delivery"], + "office": ["work", "delivery"], + "warehouse": ["work", "depot", "delivery"], + "bakehouse": ["work", "depot", "delivery"], + "firestation": ["work"], + "government": ["work"], + "cathedral": ["religous"], + "chapel": ["religous"], + "church": ["religous"], + "mosque": ["religous"], + "religous": ["religous"], + "shrine": ["religous"], + "synagogue": ["religous"], + "temple": ["religous"], + "hospital": ["health", "work"], + "kindergarden": ["education", "work"], + "school": ["education", "work"], + "university": ["education", "work"], + "college": ["education", "work"], + "sports_hall": ["leisure", "work"], + "stadium": ["leisure", "work"] + }, + "amenity": { + "bar": ["social", "work", "delivery"], + "pub": ["social", "work", "delivery"], + "cafe": ["social", "work", "delivery", "food_shop"], + "fast_food": ["work", "delivery", "food_shop"], + "food_court": ["work", "delivery", "food_shop"], + "ice_cream": ["work", "delivery", "food_shop"], + "restaurant": ["work", "delivery", "food_shop"], + "college": ["education", "work"], + "kindergarten": ["education", "work"], + "language_school": ["education", "work"], + "library": ["leisure", "work"], + "music_school": ["leisure", "work"], + "school": ["leisure", "work"], + "university": ["leisure", "work"], + "bank": ["personal_business", "work"], + "clinic": ["health", "work"], + "dentist": ["health", "work"], + "doctors": ["health", "work"], + "hospital": ["health", "work"], + "pharmacy": ["shop", "work"], + "social_facility": ["health", "work"], + "vetinary": ["personal_business", "work"], + "arts_centre": ["leisure", "work"], + "casino": ["leisure", "work"], + "cinema": ["leisure", "work"], + "community_centre": ["leisure"], + "gambling": ["leisure", "work"], + "studio": ["leisure", "work"], + "theatre": ["leisure", "work"], + "courthouse": ["personal_business", "work"], + "crematorium": ["personal_business", "work"], + "embassy": ["personal_business", "work"], + "fire_station": ["work"], + "funeral_hall": ["personal_business", "work"], + "internet_cafe": ["leisure", "work"], + "marketplace": ["shop_food", "work", "delivery"], + "place_of_worship": ["religous"], + "police": ["personal_business", "work"], + "post_box": ["personal_business", "work"], + "post_depot": ["personal_business", "work"], + "post_office": ["personal_business", "work"], + "prison": ["personal_business", "work"], + "townhall": ["personal_business", "work"] + }, + "landuse": { + "commercial": ["shop", "work", "delivery"], + "industrial": ["shop", "work", "delivery", "depot"], + "residential": ["home"], + "retail": ["shop", "work", "delivery"], + "depot": ["depot"], + "port": ["depot"], + "quary": ["depot"], + "religous": ["religous"] + }, + "leisure": { + "adult_gaming_centre": ["leisure", "work"], + "amusement_arcade": ["leisure", "work"], + "beach_resort": ["leisure"], + "dance": ["leisure", "work"], + "escape_game": ["leisure", "work"], + "fishing": ["leisure"], + "fitness_centre": ["leisure", "work"], + "fitness_station": ["leisure"], + "garden": ["leisure"], + "horse_riding": ["leisure", "work"], + "ice_rink": ["leisure", "work"], + "marina": ["leisure", "work"], + "miniature_golf": ["leisure"], + "nature_reserve": ["leisure"], + "park": ["leisure"], + "pitch": ["leisure"], + "playground": ["leisure"], + "sports_centre": ["leisure", "work"], + "stadium": ["leisure", "work"], + "swimming_pool": ["leisure", "work"], + "track": ["leisure"], + "water_park": ["leisure", "work"] + }, + "office": { + "*": ["work"] + } + }, + + "fill_missing_activities": + [ + { + "area_tags": [["landuse", "residential"]], + "required_acts": ["home"], + "new_tags": [["building", "house"]], + "size": [10, 10], + "spacing": [50, 50] + } + + ] +} \ No newline at end of file diff --git a/tests/test_activityhandler.py b/tests/test_activityhandler.py index a9aa9f3..d0f83ee 100644 --- a/tests/test_activityhandler.py +++ b/tests/test_activityhandler.py @@ -361,7 +361,7 @@ def test_extract_multiuse_object_geodataframe(self, updated_handler): obj = gdf.iloc[0].to_dict() assert obj["activities"] == "a,b" assert obj["geometry"] == Point(0, 0) - assert obj["id"] == 0 + assert obj["id"] == "0" assert obj["feature"] == 0 def test_extract_single_use_object_geodataframe(self, updated_handler): @@ -372,5 +372,5 @@ def test_extract_single_use_object_geodataframe(self, updated_handler): for i in range(2): obj = gdf.iloc[i].to_dict() assert obj["geometry"] == Point(0, 0) - assert obj["id"] == 0 + assert obj["id"] == "0" assert obj["feature"] == 0 diff --git a/tests/test_cli.py b/tests/test_cli.py index d086030..08ba118 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -5,7 +5,7 @@ import pytest from click.testing import CliRunner -from osmox import cli +from osmox import cli, helpers logging.basicConfig(level=logging.INFO) @@ -19,7 +19,7 @@ def fixtures_root(): @pytest.fixture def config_path(fixtures_root): - return os.path.join(fixtures_root, "test_config.json") + return os.path.join(fixtures_root, "test_config_infill.json") @pytest.fixture @@ -73,8 +73,13 @@ def test_cli_output_formats( [config_path, toy_osm_path, path_output_dir, "-f", output_format, "-crs", "epsg:4326"], ) check_exit_code(result) + new_file = default_output_file_path.with_suffix(MAP_EXTENSIONS[output_format]) + assert new_file.exists() - assert default_output_file_path.with_suffix(MAP_EXTENSIONS[output_format]).exists() + # Check the saved files have data and they preserve the datatype of ID + new_gdf = helpers.read_geofile(new_file) + assert not new_gdf.empty + assert new_gdf["id"].apply(lambda x: isinstance(x, str)).all() @pytest.mark.parametrize("crs", ["epsg:27700"])