Spatial analytics on Apache Superset

Spatial analytics on Apache Superset

Apache superset offers deck.gl spatial visualizations. Here are a set of examples possible: deck.gl Demo (datatest.ch)

We don’t have to store data in a spatial database like PostGIS to do spatial analytics on Superset.

For spatial charts like scatter plots, heatmaps, screen grids, arcs and point clusters, all we need are two floating point columns in our relational database (or a CSV upload/Google Sheets Connector): Latitude and Longitude.

Heatmaps and Screen grids

For charts like Choropleths and Paths we will have to convert the polygon and lines into a specific format: [[lon1, lat1], [lon2, lat2]…..] (List of polygon vertices)

Here is a small code snippet to convert a Polygon layer (GeoJSON) to a CSV with a text column containing the polygon vertices

gdf = gpd.read_file("polygons.geojson")

# Function to convert geometry to text
def geometry_to_text(geom):
    coords = list(geom.exterior.coords) if geom.geom_type == 'Polygon' else list(geom.coords)
    return str([[lon, lat] for lon, lat in coords])

# Apply the function to create a new column
gdf['polygons'] = gdf['geometry'].apply(geometry_to_text)

gdf.drop('geometry', axis=1).to_csv('polygons.csv')        

Upload this CSV into any relational database and connect it to Superset. When building a choropleth, we can choose this polygon vertices column.


Choropleths

Multiple spatial layers can be overlaid as well

Overlaid a scatter plot on a screengrid

The view port of the map can also be modified. Pitch and Bearing can be changed to give a 3D perspective.

All of it without having a spatial extension to your database!

要查看或添加评论,请登录

社区洞察

其他会员也浏览了