-
Notifications
You must be signed in to change notification settings - Fork 763
[GH-2700] Refresh docker example notebooks: scaffolding + quickstart #2876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": "<!--\n Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License. You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing,\n software distributed under the License is distributed on an\n \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n KIND, either express or implied. See the License for the\n specific language governing permissions and limitations\n under the License.\n-->\n\n# Sedona quickstart\n\nA short, end-to-end spatial workflow. We answer:\n\n> **Which countries have the most airports per million people?**\n\nAlong the way we read two shapefiles, run a distributed spatial join, aggregate, write **GeoParquet 1.1** with auto covering-bbox metadata, read it back, and render an interactive map with **SedonaKepler**.\n\nData ships with the docker image (Natural Earth 50m admin and airports). No network required.\n\nMore use-case notebooks (vector at scale, raster pipelines, raster + vector fusion, STAC, GeoPandas-on-Spark) will land alongside this one as the docker examples are refreshed for the 1.9.x series." | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from sedona.spark import SedonaContext\n", | ||
| "\n", | ||
| "config = SedonaContext.builder().master(\"spark://localhost:7077\").getOrCreate()\n", | ||
| "sedona = SedonaContext.create(config)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Read country polygons. The shapefile reader is a first-class Spark V2 datasource\n", | ||
| "# in Sedona; no manual binary parsing.\n", | ||
| "countries = (\n", | ||
| " sedona.read.format(\"shapefile\")\n", | ||
| " .load(\"data/ne_50m_admin_0_countries_lakes\")\n", | ||
| " .selectExpr(\n", | ||
| " \"geometry\",\n", | ||
| " \"NAME as country\",\n", | ||
| " \"CONTINENT as continent\",\n", | ||
| " \"POP_EST as population\",\n", | ||
| " )\n", | ||
| ")\n", | ||
| "countries.show(5, truncate=40)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "airports = (\n", | ||
| " sedona.read.format(\"shapefile\")\n", | ||
| " .load(\"data/ne_50m_airports\")\n", | ||
| " .selectExpr(\n", | ||
| " \"geometry\",\n", | ||
| " \"name as airport\",\n", | ||
| " \"type as airport_type\",\n", | ||
| " )\n", | ||
| ")\n", | ||
| "airports.show(5, truncate=40)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Spatial join: which country contains each airport?\n", | ||
| "# Sedona inserts a broadcast spatial index when one side is small.\n", | ||
| "airports.createOrReplaceTempView(\"airports\")\n", | ||
| "countries.createOrReplaceTempView(\"countries\")\n", | ||
| "\n", | ||
| "joined = sedona.sql(\"\"\"\n", | ||
| " SELECT c.country, c.continent, c.population, a.airport\n", | ||
| " FROM countries c\n", | ||
| " JOIN airports a ON ST_Contains(c.geometry, a.geometry)\n", | ||
| "\"\"\")\n", | ||
| "joined.show(5, truncate=40)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Rank countries by airports per million people.\n", | ||
| "joined.createOrReplaceTempView(\"joined\")\n", | ||
| "\n", | ||
| "ranked = sedona.sql(\"\"\"\n", | ||
| " SELECT\n", | ||
| " country,\n", | ||
| " continent,\n", | ||
| " population,\n", | ||
| " COUNT(*) AS airport_count,\n", | ||
| " ROUND(COUNT(*) * 1e6 / NULLIF(population, 0), 2) AS airports_per_million\n", | ||
| " FROM joined\n", | ||
| " WHERE population > 1000000\n", | ||
| " GROUP BY country, continent, population\n", | ||
| " ORDER BY airports_per_million DESC\n", | ||
| "\"\"\")\n", | ||
| "ranked.show(10)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Attach the rank back onto country geometries and write GeoParquet 1.1.\n", | ||
| "# Sedona auto-populates the covering-bbox metadata and projjson CRS from the\n", | ||
| "# geometry SRID, so downstream readers can prune partitions efficiently.\n", | ||
| "import os\n", | ||
| "import shutil\n", | ||
| "\n", | ||
| "ranked.createOrReplaceTempView(\"ranked\")\n", | ||
| "ranked_geo = sedona.sql(\"\"\"\n", | ||
| " SELECT c.country, c.continent,\n", | ||
| " r.airport_count, r.airports_per_million,\n", | ||
| " c.geometry\n", | ||
| " FROM ranked r\n", | ||
| " JOIN countries c USING (country)\n", | ||
| "\"\"\")\n", | ||
| "\n", | ||
| "out_path = \"/tmp/airports_per_country.parquet\"\n", | ||
| "if os.path.exists(out_path):\n", | ||
| " shutil.rmtree(out_path)\n", | ||
| "ranked_geo.coalesce(1).write.format(\"geoparquet\").save(out_path)\n", | ||
| "\n", | ||
| "sedona.read.format(\"geoparquet\").load(out_path).show(5, truncate=40)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from sedona.spark import SedonaKepler\n", | ||
| "\n", | ||
| "ranked_geo_df = sedona.read.format(\"geoparquet\").load(out_path)\n", | ||
| "SedonaKepler.create_map(df=ranked_geo_df, name=\"airports_per_million\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": "## What just happened?\n\nIn a handful of cells we ran an end-to-end spatial workflow:\n\n1. **Read** two shapefiles directly into Spark DataFrames via Sedona's V2 shapefile datasource.\n2. **Joined** them spatially with `ST_Contains` — Sedona inserts a broadcast spatial index automatically when one side is small.\n3. **Aggregated and ranked** countries by airports per capita.\n4. **Wrote** the result as **GeoParquet 1.1**; covering-bbox metadata and projjson CRS were populated automatically from the geometry SRID. Downstream readers can prune to a bounding box without scanning every row.\n5. **Rendered** an interactive choropleth with **SedonaKepler**.\n\nThe exact same code path scales to billions of rows on a real Spark cluster — no API change, just more workers." | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.11" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 4 | ||
| } |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.