CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-gmaps

Google maps plugin for Jupyter notebooks with interactive visualization capabilities

Pending
Overview
Eval results
Files

geojson.mddocs/

GeoJSON Visualization

Render geographic features from GeoJSON data including countries, regions, and custom shapes with choropleth mapping capabilities and styling controls. Perfect for visualizing geographic boundaries and area-based data.

Capabilities

GeoJSON Layer Creation

Create layers from GeoJSON data with customizable styling for choropleth maps and geographic visualizations.

def geojson_layer(geojson, fill_color=None, fill_opacity=0.4, stroke_color=None, stroke_opacity=1.0, stroke_weight=1.0):
    """
    Create a GeoJSON layer.

    Parameters:
    - geojson (dict or list): GeoJSON data (FeatureCollection, Feature, or list of features)
    - fill_color (str or list, optional): Fill color for polygons
    - fill_opacity (float or list): Fill opacity (0.0-1.0)
    - stroke_color (str or list, optional): Stroke color for outlines
    - stroke_opacity (float or list): Stroke opacity (0.0-1.0)
    - stroke_weight (float or list): Stroke width in pixels

    Returns:
    GeoJson: GeoJSON layer instance
    """

GeoJSON Layer Widget

Container for GeoJSON features with styling and interaction capabilities.

class GeoJson:
    """
    GeoJSON layer widget for geographic feature visualization.
    
    Attributes:
    - features (list): List of GeoJsonFeature instances
    """

Individual GeoJSON Feature

Single GeoJSON feature with customizable styling properties.

class GeoJsonFeature:
    """
    Individual GeoJSON feature widget.
    
    Attributes:
    - feature (dict): GeoJSON feature dictionary
    - fill_color (str): Fill color for polygons
    - fill_opacity (float): Fill opacity (0.0-1.0)
    - stroke_color (str): Stroke color for outlines
    - stroke_opacity (float): Stroke opacity (0.0-1.0)
    - stroke_weight (float): Stroke width in pixels
    """

Usage Examples

Basic GeoJSON Layer

import gmaps
import gmaps.geojson_geometries

gmaps.configure(api_key="YOUR_API_KEY")

# Load built-in geometry
countries = gmaps.geojson_geometries.load_geometry('countries')

# Create GeoJSON layer
fig = gmaps.figure()
geojson_layer = gmaps.geojson_layer(countries)
fig.add_layer(geojson_layer)
fig

Styled GeoJSON Features

import gmaps
import gmaps.geojson_geometries

gmaps.configure(api_key="YOUR_API_KEY")

# Load geometry data
us_states = gmaps.geojson_geometries.load_geometry('us-states')

# Create styled layer
fig = gmaps.figure()
geojson_layer = gmaps.geojson_layer(
    us_states,
    fill_color='lightblue',
    fill_opacity=0.6,
    stroke_color='navy',
    stroke_weight=2.0
)
fig.add_layer(geojson_layer)
fig

Choropleth Map

import gmaps
import gmaps.geojson_geometries
import pandas as pd

gmaps.configure(api_key="YOUR_API_KEY")

# Load geometry and create sample data
countries = gmaps.geojson_geometries.load_geometry('countries')

# Sample population data (in practice, you'd load real data)
population_data = {
    'United States': 331000000,
    'China': 1400000000,
    'India': 1380000000,
    'Brazil': 213000000,
    # ... more countries
}

# Create color mapping based on population
def get_color(population):
    if population > 1000000000:
        return 'darkred'
    elif population > 500000000:
        return 'red'
    elif population > 100000000:
        return 'orange'
    elif population > 50000000:
        return 'yellow'
    else:
        return 'lightgreen'

# Apply colors to features
colors = []
for feature in countries['features']:
    country_name = feature['properties'].get('NAME', '')
    population = population_data.get(country_name, 0)
    colors.append(get_color(population))

fig = gmaps.figure()
geojson_layer = gmaps.geojson_layer(
    countries,
    fill_color=colors,
    fill_opacity=0.7,
    stroke_color='white',
    stroke_weight=1.0
)
fig.add_layer(geojson_layer)
fig

Custom GeoJSON Data

import gmaps

gmaps.configure(api_key="YOUR_API_KEY")

# Custom GeoJSON feature
custom_geojson = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [[
                    [-122.4194, 37.7749],  # San Francisco area
                    [-122.4094, 37.7749],
                    [-122.4094, 37.7849],
                    [-122.4194, 37.7849],
                    [-122.4194, 37.7749]
                ]]
            },
            "properties": {
                "name": "San Francisco Area",
                "population": 875000
            }
        }
    ]
}

fig = gmaps.figure()
geojson_layer = gmaps.geojson_layer(
    custom_geojson,
    fill_color='purple',
    fill_opacity=0.5,
    stroke_color='black',
    stroke_weight=2.0
)
fig.add_layer(geojson_layer)
fig

Multiple GeoJSON Layers

import gmaps
import gmaps.geojson_geometries

gmaps.configure(api_key="YOUR_API_KEY")

fig = gmaps.figure()

# Add country boundaries
countries = gmaps.geojson_geometries.load_geometry('countries')
country_layer = gmaps.geojson_layer(
    countries,
    fill_color='lightblue',
    fill_opacity=0.3,
    stroke_color='blue',
    stroke_weight=1.0
)
fig.add_layer(country_layer)

# Add state boundaries (if available)
try:
    states = gmaps.geojson_geometries.load_geometry('us-states')
    state_layer = gmaps.geojson_layer(
        states,
        fill_color='none',  # No fill, just borders
        stroke_color='red',
        stroke_weight=1.5
    )
    fig.add_layer(state_layer)
except:
    pass  # Geometry not available

fig

Interactive GeoJSON with Hover Effects

import gmaps
import gmaps.geojson_geometries

gmaps.configure(api_key="YOUR_API_KEY")

# Load geometry
regions = gmaps.geojson_geometries.load_geometry('world-regions')

# Create features with hover information
features = []
for feature in regions['features']:
    # Add hover information to properties
    feature['properties']['hover_text'] = f"Region: {feature['properties'].get('name', 'Unknown')}"
    features.append(feature)

updated_geojson = {
    "type": "FeatureCollection",
    "features": features
}

fig = gmaps.figure()
geojson_layer = gmaps.geojson_layer(
    updated_geojson,
    fill_color='green',
    fill_opacity=0.4,
    stroke_color='darkgreen',
    stroke_weight=2.0
)
fig.add_layer(geojson_layer)
fig

Install with Tessl CLI

npx tessl i tessl/pypi-gmaps

docs

datasets.md

directions.md

drawing.md

figure-map.md

geojson.md

heatmap.md

index.md

markers.md

transportation.md

tile.json