Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 4, 2024
1 parent 191fc2c commit 41575e2
Showing 1 changed file with 58 additions and 41 deletions.
99 changes: 58 additions & 41 deletions docs/notebooks/102_fused.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "d9e87e1d",
"id": "0",
"metadata": {},
"source": [
"[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/102_fused.ipynb)\n",
Expand All @@ -22,7 +22,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d3148feb",
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -32,7 +32,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "fd0abbfd",
"id": "2",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -47,7 +47,7 @@
},
{
"cell_type": "markdown",
"id": "184a459c",
"id": "3",
"metadata": {},
"source": [
"# 1. Load Overture Buildings for drawn area\n",
Expand All @@ -60,7 +60,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "3739c910",
"id": "4",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -71,26 +71,34 @@
{
"cell_type": "code",
"execution_count": null,
"id": "2eb9ff57",
"id": "5",
"metadata": {},
"outputs": [],
"source": [
"# If no AOI is drawn, use the default AOI\n",
"\n",
"if m.user_roi is None:\n",
" m.user_roi = {'type': 'Feature',\n",
" 'properties': {},\n",
" 'geometry': {'type': 'Polygon',\n",
" 'coordinates': [[[-74.025621, 40.699967],\n",
" [-74.025621, 40.730283],\n",
" [-73.966055, 40.730283],\n",
" [-73.966055, 40.699967],\n",
" [-74.025621, 40.699967]]]}}"
" m.user_roi = {\n",
" \"type\": \"Feature\",\n",
" \"properties\": {},\n",
" \"geometry\": {\n",
" \"type\": \"Polygon\",\n",
" \"coordinates\": [\n",
" [\n",
" [-74.025621, 40.699967],\n",
" [-74.025621, 40.730283],\n",
" [-73.966055, 40.730283],\n",
" [-73.966055, 40.699967],\n",
" [-74.025621, 40.699967],\n",
" ]\n",
" ],\n",
" },\n",
" }"
]
},
{
"cell_type": "markdown",
"id": "40520eaf",
"id": "6",
"metadata": {},
"source": [
"## 1.2 Then, convert it to a GeoDataFrame."
Expand All @@ -99,21 +107,23 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ef8f03fe",
"id": "7",
"metadata": {},
"outputs": [],
"source": [
"import geopandas as gpd\n",
"\n",
"# Convert drawing to GeoDataFrame\n",
"gdf_drawing = gpd.GeoDataFrame([m.user_roi['properties']], geometry=[shape(m.user_roi['geometry'])])\n",
"gdf_drawing = gpd.GeoDataFrame(\n",
" [m.user_roi[\"properties\"]], geometry=[shape(m.user_roi[\"geometry\"])]\n",
")\n",
"\n",
"gdf_drawing"
]
},
{
"cell_type": "markdown",
"id": "d25258d6",
"id": "8",
"metadata": {},
"source": [
"## 1.3 Fetch Overture Buildings for the AOI and render them on the map\n",
Expand All @@ -124,7 +134,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "96dba5c5",
"id": "9",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -135,7 +145,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "6ac749c2",
"id": "10",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -145,7 +155,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "64621eea",
"id": "11",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -155,17 +165,22 @@
{
"cell_type": "code",
"execution_count": null,
"id": "947b3e4b",
"id": "12",
"metadata": {},
"outputs": [],
"source": [
"# Add GDF to map\n",
"m.add_gdf(gdf[['id', 'geometry', 'height', 'class']], layer_type=\"fill\", name=\"Buildings\", fill_colors=[\"red\"])"
"m.add_gdf(\n",
" gdf[[\"id\", \"geometry\", \"height\", \"class\"]],\n",
" layer_type=\"fill\",\n",
" name=\"Buildings\",\n",
" fill_colors=[\"red\"],\n",
")"
]
},
{
"cell_type": "markdown",
"id": "3c4e67d8",
"id": "13",
"metadata": {},
"source": [
"## 1.4 Visualize buildings in 3D."
Expand All @@ -174,21 +189,21 @@
{
"cell_type": "code",
"execution_count": null,
"id": "c223690b",
"id": "14",
"metadata": {},
"outputs": [],
"source": [
"m = maplibre.Map(pitch=60)\n",
"m.add_basemap(\"USGS.USImagery\")\n",
"gdf_filter = gdf[gdf.height > 0][['id', 'geometry', 'height', 'class']]\n",
"gdf_filter = gdf[gdf.height > 0][[\"id\", \"geometry\", \"height\", \"class\"]]\n",
"m.add_data(gdf_filter, column=\"height\", cmap=\"Blues\", extrude=True, name=\"Buildings\")\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0acf10c",
"id": "15",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -197,7 +212,7 @@
},
{
"cell_type": "markdown",
"id": "09bc22dd",
"id": "16",
"metadata": {},
"source": [
"# 2. Load FSQ Places POIs for drawn area\n",
Expand All @@ -210,16 +225,16 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a41a2213",
"id": "17",
"metadata": {},
"outputs": [],
"source": [
"# Fetch FSQ GDF with Fused UDF\n",
"gdf = fused.run(\"UDF_Foursquare_Open_Source_Places\", bbox=gdf_drawing)\n",
"\n",
"# `add_points_from_xy` requires latitude and longitude columns\n",
"gdf['latitude'] = gdf.geometry.y\n",
"gdf['longitude'] = gdf.geometry.x\n",
"gdf[\"latitude\"] = gdf.geometry.y\n",
"gdf[\"longitude\"] = gdf.geometry.x\n",
"\n",
"# Show place categories\n",
"set(gdf.level1_category_name.values)"
Expand All @@ -228,19 +243,21 @@
{
"cell_type": "code",
"execution_count": null,
"id": "985ac6ce",
"id": "18",
"metadata": {},
"outputs": [],
"source": [
"# Subsample the gdf\n",
"gdf_sample = gdf[['name', 'latitude', 'longitude', 'geometry']].head(200).reset_index(drop=True)\n",
"gdf_sample = (\n",
" gdf[[\"name\", \"latitude\", \"longitude\", \"geometry\"]].head(200).reset_index(drop=True)\n",
")\n",
"# gdf_sample = gdf[gdf.level1_category_name == 'Dining and Drinking'][['name', 'latitude', 'longitude']].head(1000).reset_index(drop=True)\n",
"gdf_sample"
]
},
{
"cell_type": "markdown",
"id": "41986696",
"id": "19",
"metadata": {},
"source": [
"## 2.2 Visualize the POIs on a 2d map"
Expand All @@ -249,7 +266,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "48aab2d9",
"id": "20",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -267,7 +284,7 @@
},
{
"cell_type": "markdown",
"id": "c5343bb9",
"id": "21",
"metadata": {},
"source": [
"## 2.3 Visualize POIs with OpenStreetMap vector tiles"
Expand All @@ -276,7 +293,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "f0f793e4",
"id": "22",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -287,7 +304,7 @@
},
{
"cell_type": "markdown",
"id": "87aa9834",
"id": "23",
"metadata": {},
"source": [
"## 2.4 Visualize the POIs on a 3D map with Overture buildings"
Expand All @@ -296,7 +313,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b76e9ee7",
"id": "24",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -308,7 +325,7 @@
},
{
"cell_type": "markdown",
"id": "0290ec5f",
"id": "25",
"metadata": {},
"source": [
"## 2.5 Visualize the POIs on a 3D map with [OpenFreeMap](https://openfreemap.org/) vector tiles"
Expand All @@ -317,7 +334,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "212752b7",
"id": "26",
"metadata": {},
"outputs": [],
"source": [
Expand Down

0 comments on commit 41575e2

Please sign in to comment.