Lonboard

“Lonboard” is a new binding to the deck.gl geospatial data visualization library. A “deck” is the part of a skateboard you ride on. What’s a fast, geospatial skateboard? A lonboard.

It’s a play on words with “longboard” – a type of “long” skateboard especially designed for its speed.

This is a “longboard” Credit: Linpaul Rodney

Here is a short snippet of code that will assign a unique color to each line/polyline. It could also be adapted for other features.

import geopandas as gpd
import random
from lonboard import Map, PathLayer

# Load your geospatial data into a GeoPandas DataFrame
url = r"C:\data\shapefile.zip" # adapt this path.
gdf = gpd.read_file(url, engine="pyogrio")

# Get unique names from the 'name' column
unique_names = gdf['name'].unique()

# Create an empty list to hold all PathLayer instances
layers = []

# Generate random colors for each unique name
random_colors = {}
for name in unique_names:
    random_colors[name] = [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)]

# Loop through unique names and create PathLayer for each
for name in unique_names:
    subset = gdf[gdf['name'] == name]
    layer = PathLayer.from_geopandas(subset, width_min_pixels=0.8)
    
    # Assign random color based on the name
    layer.get_color = random_colors[name]
    
    # Append the layer to the list of layers
    layers.append(layer)

# Initialize the map with all layers
map_ = Map(layers=layers)

# Display the map
map_

Read more about lonboard at: https://developmentseed.org/lonboard


Comments

Leave a comment