Mapping Overture Buildings and Foursquare Places with Leafmap + Fused
Fetch data by calling Fused UDFs and render it on a Leafmap map.
This notebook shows how you can:
# %pip install fused>=1.11.1 "leafmap[maplibre]" -q
import os
import pandas as pd
import geopandas as gpd
from shapely.geometry import shape
import fused
import leafmap
import leafmap.maplibregl as maplibre
First draw a bounding box over an area of interest (AOI) and create a GeoDataFrame with it. Then, run the Overture UDF to fetch data for that AOI.
m = leafmap.Map(center=[40.713370, -73.996181], zoom=14)
m
# If no AOI is drawn, use the default AOI
if m.user_roi is None:
m.user_roi = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-74.025621, 40.699967],
[-74.025621, 40.730283],
[-73.966055, 40.730283],
[-73.966055, 40.699967],
[-74.025621, 40.699967],
]
],
},
}
import geopandas as gpd
# Convert drawing to GeoDataFrame
gdf_drawing = gpd.GeoDataFrame(
[m.user_roi["properties"]], geometry=[shape(m.user_roi["geometry"])]
)
gdf_drawing
The data comes from calling the "Overture Maps Example" public UDF with fused.run
.
# Fetch Overture Buildings GDF with Fused UDF
gdf = fused.run("UDF_Overture_Maps_Example", bbox=gdf_drawing)
gdf.head()
print(f"The number of buildings within the AOI: {len(gdf)}")
# Add GDF to map
m.add_gdf(
gdf[["id", "geometry", "height", "class"]],
layer_type="fill",
name="Buildings",
fill_colors=["red"],
)
m = maplibre.Map(pitch=60)
m.add_basemap("USGS.USImagery")
gdf_filter = gdf[gdf.height > 0][["id", "geometry", "height", "class"]]
m.add_data(gdf_filter, column="height", cmap="Blues", extrude=True, name="Buildings")
m
m.layer_interact()
The data comes from calling the "Foursquare Open Source Places" public UDF with fused.run
.
# Fetch FSQ GDF with Fused UDF
gdf = fused.run("UDF_Foursquare_Open_Source_Places", bbox=gdf_drawing)
# `add_points_from_xy` requires latitude and longitude columns
gdf["latitude"] = gdf.geometry.y
gdf["longitude"] = gdf.geometry.x
# Show place categories
set(gdf.level1_category_name.values)
# Subsample the gdf
gdf_sample = (
gdf[["name", "latitude", "longitude", "geometry"]].head(200).reset_index(drop=True)
)
# gdf_sample = gdf[gdf.level1_category_name == 'Dining and Drinking'][['name', 'latitude', 'longitude']].head(1000).reset_index(drop=True)
gdf_sample
m = leafmap.Map(center=[40.713370, -73.996181], zoom=14)
# Add as marker cluster
m.add_points_from_xy(
gdf_sample,
x="longitude",
y="latitude",
spin=False,
add_legend=True,
)
m
m = maplibre.Map(pitch=60, style="https://maps.gishub.org/styles/openstreetmap.json")
m.add_gdf(gdf_sample, name="Places")
m
m = maplibre.Map(zoom=18, pitch=60, style="positron")
m.add_overture_3d_buildings()
m.add_gdf(gdf_sample, name="Places")
m
m = maplibre.Map(pitch=60, style="liberty")
m.add_gdf(gdf_sample, name="Places")
m