Skip to content

Commit 8f06634

Browse files
committed
Fix Putrajaya, Malaysia
Ensures we can run the analysis for the city of Putrajaya, Malaysia. Drive-by: - Improves the console output. Fixes: PeopleForBikes/PeopleForBikes.github.io#863 Signed-off-by: Rémy Greinhofer <remy.greinhofer@gmail.com>
1 parent 5fea198 commit 8f06634

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

brokenspoke_analyzer/cli/importer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ def all(
2222
) -> None:
2323
"""Import all files into database."""
2424
# Make MyPy happy.
25-
if not region:
26-
raise ValueError("`region` must be set")
2725
if not fips_code:
2826
raise ValueError("`fips_code` must be set")
2927
if not lodes_year:
3028
raise ValueError("`lodes_year` must be set")
3129
if not buffer:
3230
raise ValueError("`buffer` must be set")
3331

32+
# Set the region as the country if it was not provided.
33+
if not region:
34+
region = country
35+
3436
ingestor.all_wrapper(
3537
database_url=database_url,
3638
input_dir=input_dir,

brokenspoke_analyzer/cli/prepare.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ async def prepare_(
124124
boundary_file = output_dir / f"{slug}.shp"
125125

126126
# Download the OSM region file.
127+
osm_region = region if region else country
127128
console.log(
128-
f"[green]Fetching the OSM region file for {region}...",
129+
f"[green]Fetching the OSM region file for {osm_region}...",
129130
)
130131
with console.status("Downloading..."):
131132
try:

brokenspoke_analyzer/cli/run_with.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,11 @@ def run_(
253253

254254
# Prepare the Rich output.
255255
console = rich.get_console()
256-
console.log(
257-
f"[bold bright_blue]Processing {country}, {region}, {city} ({fips_code})"
258-
)
256+
msg = [f"[bold bright_blue]Processing {country}"]
257+
if region:
258+
msg.append(region)
259+
msg.append(f"{city} ({fips_code})")
260+
console.log(", ".join(msg))
259261

260262
# Prepare.
261263
logger.debug(f"{output_dir=}")

brokenspoke_analyzer/core/analysis.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def osmnx_query(country: str, city: str, state: str | None) -> typing.Tuple[str,
3333
3434
Returns: the OSMNX query and its slugified version.
3535
"""
36+
if country == state:
37+
state = None
3638
query = ", ".join(filter(None, [city, state, country]))
3739
slug = slugify(query)
3840
return (query, slug)
@@ -240,6 +242,11 @@ def simulate_census_blocks(
240242

241243
def retrieve_region_file(region: str, output_dir: pathlib.Path) -> pathlib.Path:
242244
"""Retrieve the region file from Geofabrik or BBike."""
245+
# As per https://github.com/PeopleForBikes/brokenspoke-analyzer/issues/863
246+
# we must define an exception for the countries of Malaysia, Singapore and
247+
# Brunei as they have been grouped together in the Geofabrik dataset.
248+
if region in {"malaysia", "singapore", "brunei"}:
249+
region = "malaysia_singapore_brunei"
243250
dataset = utils.normalize_unicode_name(region)
244251
dataset_file = data.get_data(dataset, directory=output_dir) # type: ignore
245252
region_file_path: pathlib.Path = pathlib.Path(dataset_file)

0 commit comments

Comments
 (0)