Skip to content

Commit 1c41c13

Browse files
committed
Coerce ID to string
1 parent bfa3aaa commit 1c41c13

File tree

4 files changed

+188
-7
lines changed

4 files changed

+188
-7
lines changed

src/osmox/build.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def summary(self):
164164
Returbn a dict summary.
165165
"""
166166
fixed = {
167-
"id": self.idx,
167+
"id": str(self.idx),
168168
"activities": ",".join(self.activities),
169169
"geometry": self.geom.centroid,
170170
}
@@ -175,7 +175,7 @@ def single_activity_summaries(self):
175175
Yield (dict) summaries for each each activity of an object.
176176
"""
177177
for act in self.activities:
178-
fixed = {"id": self.idx, "activity": act, "geometry": self.geom.centroid}
178+
fixed = {"id": str(self.idx), "activity": act, "geometry": self.geom.centroid}
179179
yield {**fixed, **self.features}
180180

181181

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
{
2+
"filter": {
3+
"building": [
4+
"apartments",
5+
"bungalow",
6+
"detached",
7+
"dormitory",
8+
"hotel",
9+
"residential",
10+
"semidetached_house",
11+
"terrace",
12+
"commercial",
13+
"retail",
14+
"supermarket",
15+
"industrial",
16+
"office",
17+
"warehouse",
18+
"bakehouse",
19+
"firestation",
20+
"government",
21+
"cathedral",
22+
"chapel",
23+
"church",
24+
"mosque",
25+
"religous",
26+
"shrine",
27+
"synagogue",
28+
"temple",
29+
"hospital",
30+
"kindergarden",
31+
"school",
32+
"university",
33+
"college",
34+
"sports_hall",
35+
"stadium",
36+
"yes"
37+
]
38+
},
39+
40+
"object_features": ["units", "levels", "area", "floor_area"],
41+
42+
"distance_to_nearest": ["transit"],
43+
44+
"default_tags": [["building", "residential"]],
45+
46+
"activity_mapping": {
47+
"building": {
48+
"apartments": ["home"],
49+
"bungalow": ["home"],
50+
"detached": ["home"],
51+
"dormitory": ["home"],
52+
"hotel": ["home"],
53+
"residential": ["home"],
54+
"semidetached_house": ["home"],
55+
"terrace": ["home"],
56+
"commercial": ["shop", "work", "delivery"],
57+
"retail": ["shop", "work", "delivery"],
58+
"supermarket": ["shop_food", "work", "delivery"],
59+
"industrial": ["work", "delivery"],
60+
"office": ["work", "delivery"],
61+
"warehouse": ["work", "depot", "delivery"],
62+
"bakehouse": ["work", "depot", "delivery"],
63+
"firestation": ["work"],
64+
"government": ["work"],
65+
"cathedral": ["religous"],
66+
"chapel": ["religous"],
67+
"church": ["religous"],
68+
"mosque": ["religous"],
69+
"religous": ["religous"],
70+
"shrine": ["religous"],
71+
"synagogue": ["religous"],
72+
"temple": ["religous"],
73+
"hospital": ["health", "work"],
74+
"kindergarden": ["education", "work"],
75+
"school": ["education", "work"],
76+
"university": ["education", "work"],
77+
"college": ["education", "work"],
78+
"sports_hall": ["leisure", "work"],
79+
"stadium": ["leisure", "work"]
80+
},
81+
"amenity": {
82+
"bar": ["social", "work", "delivery"],
83+
"pub": ["social", "work", "delivery"],
84+
"cafe": ["social", "work", "delivery", "food_shop"],
85+
"fast_food": ["work", "delivery", "food_shop"],
86+
"food_court": ["work", "delivery", "food_shop"],
87+
"ice_cream": ["work", "delivery", "food_shop"],
88+
"restaurant": ["work", "delivery", "food_shop"],
89+
"college": ["education", "work"],
90+
"kindergarten": ["education", "work"],
91+
"language_school": ["education", "work"],
92+
"library": ["leisure", "work"],
93+
"music_school": ["leisure", "work"],
94+
"school": ["leisure", "work"],
95+
"university": ["leisure", "work"],
96+
"bank": ["personal_business", "work"],
97+
"clinic": ["health", "work"],
98+
"dentist": ["health", "work"],
99+
"doctors": ["health", "work"],
100+
"hospital": ["health", "work"],
101+
"pharmacy": ["shop", "work"],
102+
"social_facility": ["health", "work"],
103+
"vetinary": ["personal_business", "work"],
104+
"arts_centre": ["leisure", "work"],
105+
"casino": ["leisure", "work"],
106+
"cinema": ["leisure", "work"],
107+
"community_centre": ["leisure"],
108+
"gambling": ["leisure", "work"],
109+
"studio": ["leisure", "work"],
110+
"theatre": ["leisure", "work"],
111+
"courthouse": ["personal_business", "work"],
112+
"crematorium": ["personal_business", "work"],
113+
"embassy": ["personal_business", "work"],
114+
"fire_station": ["work"],
115+
"funeral_hall": ["personal_business", "work"],
116+
"internet_cafe": ["leisure", "work"],
117+
"marketplace": ["shop_food", "work", "delivery"],
118+
"place_of_worship": ["religous"],
119+
"police": ["personal_business", "work"],
120+
"post_box": ["personal_business", "work"],
121+
"post_depot": ["personal_business", "work"],
122+
"post_office": ["personal_business", "work"],
123+
"prison": ["personal_business", "work"],
124+
"townhall": ["personal_business", "work"]
125+
},
126+
"landuse": {
127+
"commercial": ["shop", "work", "delivery"],
128+
"industrial": ["shop", "work", "delivery", "depot"],
129+
"residential": ["home"],
130+
"retail": ["shop", "work", "delivery"],
131+
"depot": ["depot"],
132+
"port": ["depot"],
133+
"quary": ["depot"],
134+
"religous": ["religous"]
135+
},
136+
"leisure": {
137+
"adult_gaming_centre": ["leisure", "work"],
138+
"amusement_arcade": ["leisure", "work"],
139+
"beach_resort": ["leisure"],
140+
"dance": ["leisure", "work"],
141+
"escape_game": ["leisure", "work"],
142+
"fishing": ["leisure"],
143+
"fitness_centre": ["leisure", "work"],
144+
"fitness_station": ["leisure"],
145+
"garden": ["leisure"],
146+
"horse_riding": ["leisure", "work"],
147+
"ice_rink": ["leisure", "work"],
148+
"marina": ["leisure", "work"],
149+
"miniature_golf": ["leisure"],
150+
"nature_reserve": ["leisure"],
151+
"park": ["leisure"],
152+
"pitch": ["leisure"],
153+
"playground": ["leisure"],
154+
"sports_centre": ["leisure", "work"],
155+
"stadium": ["leisure", "work"],
156+
"swimming_pool": ["leisure", "work"],
157+
"track": ["leisure"],
158+
"water_park": ["leisure", "work"]
159+
},
160+
"office": {
161+
"*": ["work"]
162+
}
163+
},
164+
165+
"fill_missing_activities":
166+
[
167+
{
168+
"area_tags": [["landuse", "residential"]],
169+
"required_acts": ["home"],
170+
"new_tags": [["building", "house"]],
171+
"size": [10, 10],
172+
"spacing": [50, 50]
173+
}
174+
175+
]
176+
}

tests/test_activityhandler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def test_extract_multiuse_object_geodataframe(self, updated_handler):
361361
obj = gdf.iloc[0].to_dict()
362362
assert obj["activities"] == "a,b"
363363
assert obj["geometry"] == Point(0, 0)
364-
assert obj["id"] == 0
364+
assert obj["id"] == "0"
365365
assert obj["feature"] == 0
366366

367367
def test_extract_single_use_object_geodataframe(self, updated_handler):
@@ -372,5 +372,5 @@ def test_extract_single_use_object_geodataframe(self, updated_handler):
372372
for i in range(2):
373373
obj = gdf.iloc[i].to_dict()
374374
assert obj["geometry"] == Point(0, 0)
375-
assert obj["id"] == 0
375+
assert obj["id"] == "0"
376376
assert obj["feature"] == 0

tests/test_cli.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77
from click.testing import CliRunner
8-
from osmox import cli
8+
from osmox import cli, helpers
99

1010
logging.basicConfig(level=logging.INFO)
1111

@@ -19,7 +19,7 @@ def fixtures_root():
1919

2020
@pytest.fixture
2121
def config_path(fixtures_root):
22-
return os.path.join(fixtures_root, "test_config.json")
22+
return os.path.join(fixtures_root, "test_config_infill.json")
2323

2424

2525
@pytest.fixture
@@ -73,8 +73,13 @@ def test_cli_output_formats(
7373
[config_path, toy_osm_path, path_output_dir, "-f", output_format, "-crs", "epsg:4326"],
7474
)
7575
check_exit_code(result)
76+
new_file = default_output_file_path.with_suffix(MAP_EXTENSIONS[output_format])
77+
assert new_file.exists()
7678

77-
assert default_output_file_path.with_suffix(MAP_EXTENSIONS[output_format]).exists()
79+
# Check the saved files have data and they preserve the datatype of ID
80+
new_gdf = helpers.read_geofile(new_file)
81+
assert not new_gdf.empty
82+
assert new_gdf["id"].apply(lambda x: isinstance(x, str)).all()
7883

7984

8085
@pytest.mark.parametrize("crs", ["epsg:27700"])

0 commit comments

Comments
 (0)