Overture Maps Loader¶
OvertureMapsLoader
can download the Overture Maps data from the s3 bucket for a given region.
It is a wrapper around the OvertureMaestro
library that can download the data in the original format but also have some advanced functions.
In the SRAI
context, OvertureMapsLoader
utilizes so-called wide format for returning features with columns representing potential categories of the object. If you want to read more in-depth about this format, you can checkout this OvertureMaestro's docs page.
from shapely.geometry import box
from srai.constants import GEOMETRY_COLUMN
from srai.loaders import OvertureMapsLoader
from srai.regionalizers import geocode_to_region_gdf
Using OvertureMapsLoader to download data for a specific area¶
Download all available features in Paris, France¶
loader = OvertureMapsLoader()
paris = geocode_to_region_gdf("Paris")
paris_features_gdf = loader.load(paris)
paris_features_gdf
Finished operation in 0:00:43
geometry | base|infrastructure|aerialway | base|infrastructure|airport | base|infrastructure|barrier | base|infrastructure|bridge | base|infrastructure|communication | base|infrastructure|emergency | base|infrastructure|manhole | base|infrastructure|pedestrian | base|infrastructure|pier | ... | places|place|professional_services | places|place|public_service_and_government | places|place|real_estate | places|place|religious_organization | places|place|retail | places|place|structure_and_geography | places|place|travel | transportation|segment|rail | transportation|segment|road | transportation|segment|water | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
feature_id | |||||||||||||||||||||
31d28436-ea6c-483a-88f0-6fb1145b2c1a | LINESTRING (2.37171 48.83528, 2.37198 48.8349,... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | True | False | False |
4eb47351-cb60-4f39-9164-e64c29f4a455 | LINESTRING (2.39569 48.7034, 2.39595 48.70368,... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | True | False | False |
8827d68e-3a3b-4ba5-b6be-d25663c99bd4 | LINESTRING (2.34467 48.71413, 2.34689 48.71419... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | True | False | False |
0dda05d4-383c-49cb-98d3-de39089731ec | LINESTRING (2.34272 48.71403, 2.34457 48.71407... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | True | False | False |
0c96af77-6d6e-4d2d-a665-d71e9bfb0105 | LINESTRING (2.3131 48.83479, 2.31293 48.83465,... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | True | False | False |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
ffe9791c-ab34-4ad8-9571-f75160b266d7 | LINESTRING (2.46279 48.81615, 2.46274 48.81618... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | True | False |
f2a003c4-1c0f-3a83-ade9-d2d72d693541 | POLYGON ((2.44096 48.79352, 2.44117 48.79358, ... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
a240a455-c942-5153-a34a-f7fdb83be034 | POLYGON ((2.59505 48.69138, 2.59534 48.69082, ... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
435e082c-50d5-5118-a0d5-0ea061edfad1 | POLYGON ((2.34001 48.62425, 2.39399 48.64223, ... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
8cf00307-1658-3f5e-b0dd-5b9b89fc9ecf | POLYGON ((1.99925 47.9995, 1.99925 49.0005, 2.... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
616609 rows × 116 columns
Plot features¶
Colours from the this palette: https://colorhunt.co/palette/f8ededff8225b43f3f173b45
ax = paris.plot(color="#F8EDED", figsize=(16, 16))
# plot water
water_columns = [c for c in paris_features_gdf.columns if "water" in c]
water_data = paris_features_gdf[paris_features_gdf[water_columns].any(axis=1)]
water_data.plot(ax=ax, color="#FF8225", markersize=0)
# plot_roads
roads_data = paris_features_gdf[paris_features_gdf["transportation|segment|road"]]
roads_data.plot(ax=ax, color="#B43F3F", markersize=0, linewidth=0.25)
# plot buildings
building_columns = [c for c in paris_features_gdf.columns if c.startswith("buildings")]
buildings_data = paris_features_gdf[paris_features_gdf[building_columns].any(axis=1)]
buildings_data.plot(ax=ax, color="#173B45", markersize=0)
paris.boundary.plot(ax=ax, color="#173B45", linewidth=2, alpha=0.5)
xmin, ymin, xmax, ymax = paris.total_bounds
ax.set_xlim(xmin - 0.001, xmax + 0.001)
ax.set_ylim(ymin - 0.001, ymax + 0.001)
ax.set_axis_off()
Download more detailed data with higher hierarchy value¶
By default, the hierarchy_depth
value is equal to 1
, but it can be set to None
to get a full list of all possible columns.
manhattan_bbox = box(-73.994551, 40.762396, -73.936872, 40.804239)
loader = OvertureMapsLoader(hierarchy_depth=None)
new_york_features_gdf = loader.load(manhattan_bbox)
new_york_features_gdf
Finished operation in 0:00:50
geometry | base|infrastructure|aerialway|aerialway_station | base|infrastructure|aerialway|cable_car | base|infrastructure|aerialway|chair_lift | base|infrastructure|aerialway|drag_lift | base|infrastructure|aerialway|gondola | base|infrastructure|aerialway|goods | base|infrastructure|aerialway|j-bar | base|infrastructure|aerialway|magic_carpet | base|infrastructure|aerialway|mixed_lift | ... | transportation|segment|road|service|parking_aisle | transportation|segment|road|steps | transportation|segment|road|tertiary | transportation|segment|road|tertiary|link | transportation|segment|road|track | transportation|segment|road|trunk | transportation|segment|road|trunk|link | transportation|segment|road|unclassified | transportation|segment|road|unknown | transportation|segment|water | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
feature_id | |||||||||||||||||||||
a4a63a32-5056-3572-8ca9-d84e88840108 | LINESTRING (-73.88819 40.77247, -73.88914 40.7... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
989bb1fa-f802-495c-b0ce-35500cae6bde | POLYGON ((-73.93704 40.76232, -73.93691 40.762... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
8120dcbf-8e80-4060-b34a-88933bd294a9 | LINESTRING (-73.93721 40.76233, -73.93711 40.7... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
0b1c1c72-6e71-49e4-bbe2-cd45f56bafea | POLYGON ((-73.93762 40.76256, -73.93749 40.762... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
b0469ded-719b-37a8-b7fc-e5ba7f8dde87 | POINT (-73.93791 40.76259) | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
584a8403-df0d-3a7c-afc0-f6fb55d582f7 | LINESTRING (-74.01917 40.1595, -45.87335 43.51... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
8ff5a5f5-ad57-35c6-92a6-e49faf84d63e | LINESTRING (-74.01882 40.16003, -20.00572 48.0... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
caf076ce-6598-33ca-80db-31e73d099de7 | LINESTRING (-20.03283 45.32375, -74.01984 40.1... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
82e32eff-68b1-3a9d-a541-9de8a0c09652 | LINESTRING (-74.23212 39.56648, -42.21708 42.8... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
6f69fb5a-6e3a-5a3d-85e9-89283369ca6c | POLYGON ((-82.43406 27.02879, -82.30827 26.867... | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
66822 rows × 2644 columns
As you can see, there are over 2600
columns available.
Let's see top 20 most popular columns.
new_york_features_gdf.drop(columns=GEOMETRY_COLUMN).sum().sort_values(ascending=False).head(20)
buildings|building 12464 base|land|tree|tree 6033 base|infrastructure|transportation|crossing 3898 transportation|segment|road|footway 3503 base|infrastructure|barrier|kerb 3170 places|place|health_and_medical 2811 places|place|health_and_medical|doctor 2171 transportation|segment|road|footway|sidewalk 2007 buildings|building|residential|apartments 1714 places|place|eat_and_drink|restaurant 1601 transportation|segment|road|footway|crosswalk 1541 places|place|professional_services 1492 base|infrastructure|pedestrian|bench 1046 base|infrastructure|transit|bicycle_parking 1007 base|infrastructure|transportation|traffic_signals 1000 places|place|beauty_and_spa 854 transportation|segment|road|residential 833 places|place|health_and_medical|hospital 819 places|place|beauty_and_spa|beauty_salon 817 places|place|attractions_and_activities|landmark_and_historical_building 714 dtype: int64
Configure places dataset¶
Places schema is the only one that is treated differently than other data types.
By default, places use both primary
and alternate
categories to define a feature.
Additionally, there is a filter applied to get only features with confidence score >= 0.75
.
There are two dedicated parameters: places_minimal_confidence
and places_use_primary_category_only
to configure how the data should be transformed.
Let's do example with both of these parameters. We will also use a theme_type_pairs
parameter to limit the scope of the downloaded data.
default_confidence_loader = OvertureMapsLoader(
theme_type_pairs=[("places", "place")], places_use_primary_category_only=True
)
strict_confidence_loader = OvertureMapsLoader(
theme_type_pairs=[("places", "place")],
places_minimal_confidence=0.99,
places_use_primary_category_only=True,
)
songpa = geocode_to_region_gdf("Songpa-gu, Seoul")
songpa_default_confidence_features_gdf = default_confidence_loader.load(songpa)
songpa_strict_confidence_features_gdf = strict_confidence_loader.load(songpa)
print(f"Default confidence score: {len(songpa_default_confidence_features_gdf)}")
print(f"Strict confidence score: {len(songpa_strict_confidence_features_gdf)}")
Finished operation in 0:00:08
Finished operation in 0:00:08
Default confidence score: 5165 Strict confidence score: 7
Let's see the count of categories in the places dataset with confidence score >= 0.99
.
songpa_strict_confidence_features_df = songpa_strict_confidence_features_gdf.drop(
columns=GEOMETRY_COLUMN
)
songpa_strict_confidence_features_df.sum().loc[lambda x: x > 0].sort_values(ascending=False)
places|place|retail 7 dtype: int64
Plot features¶
Now we will see the difference between default list of places (gray dots) and strict ones (coloured circles)
m = songpa_default_confidence_features_gdf.loc[
songpa_default_confidence_features_gdf.index.difference(
songpa_strict_confidence_features_gdf.index
)
].geometry.explore(
tiles="CartoDB Voyager",
color="gray",
tooltip=False,
style_kwds=dict(opacity=0.25, stroke=False),
)
songpa.boundary.explore(m=m, color="black")
songpa_gdf_with_categories = songpa_strict_confidence_features_gdf.join(
songpa_strict_confidence_features_df.dot(songpa_strict_confidence_features_df.columns).rename(
"category"
)
)
songpa_gdf_with_categories.geometry.explore(
m=m,
tooltip=False,
marker_kwds=dict(radius=6),
style_kwds=dict(color="black", fillOpacity=1),
)
songpa_gdf_with_categories[[GEOMETRY_COLUMN, "category"]].explore(
m=m,
column="category",
tooltip=["feature_id", "category"],
cmap="tab20",
marker_kwds=dict(radius=4),
style_kwds=dict(fillOpacity=1),
)