Blog · Apache Sedona · Databricks · H3

Arquitetura medalhão para dado geoespacial com Apache SedonaA medallion architecture for geospatial data with Apache Sedona

Mapa bonito é a última etapa. Antes dele, a geometria precisa ser válida, estar no CRS certo, ter índice espacial e ser resumida na escala que o mapa aguenta. É o mesmo raciocínio Bronze, Silver e Gold que já usamos para tabelas, aplicado a polígonos e pontos.

A pretty map is the last step. Before it, geometry must be valid, in the right CRS, spatially indexed and summarised at a scale the map can bear. It is the same Bronze, Silver and Gold thinking we use for tables, applied to polygons and points.

Por que o dado geoespacial pede cuidado próprioWhy geodata needs its own care

A arquiteturaThe architecture

SourcesGeoJSON · ShapefileCSV · Sinan · IBGE Bronzeraw files, untouchedST_GeomFromGeoJSON SilverST_MakeValid · CRSarea · centroid · DRS GoldH3 · union · hulldistance · classes Pythongeopandas ServeGeoJSON · tiles

Sedona leva as funções ST_* do PostGIS para o Spark SQL, então o mesmo código roda de um notebook até um data lake. O que o Sedona não faz (densidade de núcleo, quebras naturais de Fisher-Jenks) fica no cliente Python, depois de agregar em H3.

Sedona brings PostGIS-style ST_* functions to Spark SQL, so the same code runs from a notebook to a data lake. What Sedona does not do (kernel density, Fisher-Jenks natural breaks) stays on the Python client, after aggregating into H3.

Widget: explore as camadasWidget: explore the layers

Escolha uma camada para ver o SQL do Sedona, o que ela garante e uma amostra dos dados de São Paulo.

Pick a layer to see the Sedona SQL, what it guarantees and a sample of the São Paulo data.

O que foi executado. As figuras do blog foram geradas por Python (geopandas, shapely, h3, matplotlib) sobre os mesmos dados. O SQL do Sedona 1.7.1 está no notebook notebooks/sedona_geo_medallion.py, escrito para Databricks, com verificações de paridade contra os números do Python. Eu não executei esse notebook em um cluster Spark.

What was executed. The figures on this blog were produced by Python (geopandas, shapely, h3, matplotlib) over the same data. The Sedona 1.7.1 SQL is in notebooks/sedona_geo_medallion.py, written for Databricks, with parity checks against the Python numbers. I have not run that notebook on a Spark cluster.

Rodando no DatabricksRunning on Databricks

No cluster (modo de acesso dedicado), instale apache-sedona do PyPI e as bibliotecas Maven abaixo, compatíveis com o Spark 3.5 do runtime. Depois crie o contexto e use sedona.sql.

On the cluster (dedicated access mode), install apache-sedona from PyPI and the Maven libraries below, matching the runtime's Spark 3.5. Then create the context and use sedona.sql.

org.apache.sedona:sedona-spark-shaded-3.5_2.12:1.7.1
org.datasyslab:geotools-wrapper:1.7.1-28.5

from sedona.spark import SedonaContext
sedona = SedonaContext.create(spark)
sedona.read.format("geojson").option("multiLine", "true").load(path)

Os GeoJSON de São PauloThe São Paulo GeoJSON files

Quatro divisões territoriais, cada uma em GeoJSON e em TopoJSON (menor). Coordenadas em WGS84 (longitude, latitude).

Four territorial divisions, each as GeoJSON and as the smaller TopoJSON. Coordinates in WGS84 (longitude, latitude).

DownloadsDownloads

Propriedades: municípios CD_MUN (código IBGE de 7 dígitos); DRS DRS_ID, DRS_NOME; RRAS RRAS_ID, RRAS_NOME; regiões de saúde RS_ID, RS_NOME. Divisões territoriais do estado de São Paulo, como usadas no projeto Mapa da Saúde.

Properties: municipalities CD_MUN (7-digit IBGE code); DRS DRS_ID, DRS_NOME; RRAS RRAS_ID, RRAS_NOME; health regions RS_ID, RS_NOME. Territorial divisions of the state of São Paulo, as used in the Mapa da Saúde project.

Próximo: as 286 amostras do Azure Maps, refeitas em Python.

Next: the 286 Azure Maps samples, re-done in Python.