Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Cloud-Native GIS with GeoLibre

image image

Introduction

Learning Objectives

Environment Setup

# %pip install geolibre
from geolibre import Map

Creating a Map

m = Map(center=(-100, 40), zoom=4, height="700px")
m
m.add_basemap("dark")
m.set_center(-122.4, 37.77, zoom=10)

Map Options

m = Map(
    center=(-83.92, 35.96),
    zoom=12,
    basemap="liberty",
    height="700px",
    layout="embed",  # "embed", "full", or "maponly"
    theme="light",
)
m

Adding Vector Data

url = (
    "https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson"
)
m = Map(center=(0, 20), zoom=2, height="700px")
m.add_geojson(url, name="World Cities", circleRadius=4, fillColor="#ef4444")
m
m.add_vector(
    "https://github.com/opengeos/datasets/releases/download/us/us_states.parquet",
    name="US States",
    fillOpacity=0.2,
)

Points from a CSV

m = Map(center=(-100, 40), zoom=3, height="700px")
m.add_csv(
    "https://github.com/opengeos/datasets/releases/download/world/world_cities.csv",
    x="longitude",
    y="latitude",
    name="Cities",
)
m

Marker Clusters and Heatmaps

m = Map(center=(-100, 40), zoom=3, height="700px")
m.add_marker_cluster(
    "https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson",
    name="City Clusters",
)
m
m = Map(center=(-100, 40), zoom=3, height="700px")
m.add_heatmap(
    "https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson",
    name="City Density",
    radius=30,
)
m

Data-Driven Symbology

m = Map(center=(-100, 40), zoom=4, height="700px")
m.add_choropleth(
    "https://github.com/opengeos/datasets/releases/download/us/us_counties.geojson",
    column="CENSUSAREA",
    name="County Area",
    colormap="blues",
    scheme="quantile",
    class_count=6,
)
m

Legends and Colorbars

m.add_colorbar(
    colormap="blues",
    vmin=0,
    vmax=5000,
    label="Census Area",
    units="sq mi",
)
m = Map(center=(-100, 40), zoom=4, height="700px")
m.add_cog(
    "https://github.com/opengeos/datasets/releases/download/raster/nlcd_2021_land_cover_90m.tif",
    name="NLCD 2021",
)
m.add_legend(builtin="nlcd", title="NLCD Land Cover")
m

Adding Raster Data

m = Map(center=(-119.5, 37.75), zoom=10, height="700px")
m.add_cog(
    "https://github.com/opengeos/datasets/releases/download/raster/dem.tif",
    name="DEM",
    colormap="terrain",
)
m
m.add_colorbar(colormap="terrain", vmin=0, vmax=4000, label="Elevation", units="m")

Comparing Two Rasters with a Swipe

m = Map(center=(22.6, 32.75), zoom=12, height="700px")
before = m.add_cog(
    "https://github.com/opengeos/datasets/releases/download/raster/Libya-2023-07-01.tif",
    name="Before",
)
after = m.add_cog(
    "https://github.com/opengeos/datasets/releases/download/raster/Libya-2023-09-13.tif",
    name="After",
)
m.split_map(before, after)
m

3D Visualization

m = Map(center=(-74.0, 40.72), zoom=15, basemap="dark", height="700px")
m.add_geojson(
    "https://github.com/opengeos/datasets/releases/download/places/nyc_buildings.geojson",
    name="NYC Buildings",
    extrusionEnabled=True,
    extrusionHeightProperty="height_avg",
    extrusionColor="#f59e0b",
)
m.set_pitch(60)
m.set_bearing(-20)
m

Managing Layers

m.layer_names
buildings = m.find_layer("NYC Buildings")
buildings.opacity = 0.7
buildings.set_style(extrusionColor="#22d3ee")
buildings.column("height_avg")[:10]

Two-Way Sync

project = m.to_project()
print("center:", project["mapView"]["center"])
print("zoom:", round(project["mapView"]["zoom"], 2))
print("layers:", [layer["name"] for layer in project["layers"]])
m.describe()

Saving and Reloading a Project

m.save_project("my-map.geolibre.json")
m2 = Map(height="700px")
m2.load_project("my-map.geolibre.json")
m2

Geoprocessing in the Browser

m = Map(center=(-119.5, 37.75), zoom=10, height="700px")
m
tools = m.list_whitebox_tools()
len(tools)
dem = m.get_layer(
    m.add_raster(
        "https://github.com/opengeos/datasets/releases/download/raster/dem.tif",
        name="DEM",
    )
)
result = m.run_whitebox_tool("slope", {"input": dem, "units": "degrees"})
result["resultLayerIds"]

Key Takeaways

Exercises

Exercise 1: Building a Map from Vector Data

Exercise 2: Choropleth Symbology and Legends

Exercise 3: Raster Layers and Swipe Comparison

Exercise 4: 3D Building Extrusions

Exercise 5: Saving and Sharing a Project