Skip to content

Commit

Permalink
Merge pull request #52 from arup-group/fix-parquet-save
Browse files Browse the repository at this point in the history
Coerce ID to string
  • Loading branch information
brynpickering authored Apr 5, 2024
2 parents bfa3aaa + 1c41c13 commit 2699b81
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/osmox/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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}


Expand Down
176 changes: 176 additions & 0 deletions tests/fixtures/test_config_infill.json
Original file line number Diff line number Diff line change
@@ -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]
}

]
}
4 changes: 2 additions & 2 deletions tests/test_activityhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
11 changes: 8 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit 2699b81

Please sign in to comment.