import geoviews as gv
print(gv.__version__)
1.14.0
Bhavy Mishra, Chirag Vinayak Mahale, Parth Kale
February 25, 2025
GeoViews is a powerful Python library for visualizing geographic data interactively. Built on top of HoloViews and Bokeh, it allows you to create stunning maps with minimal code.
Unlike traditional mapping tools, GeoViews integrates seamlessly with Pandas and Xarray, making it easy to work with geospatial datasets. Whether you’re plotting earthquake locations, climate data, or population trends, GeoViews helps you visualize and explore spatial patterns effortlessly.
Before installing GeoViews, it’s recommended to create a virtual environment to keep dependencies organized.
GeoViews can be installed via pip or conda depending on your preference
Since GeoViews relies on HoloViews, Cartopy, and Bokeh, it’s a good practice to install them explicitly:
If you’re using Jupyter Notebook, enable GeoViews with the following command:
GeoViews supports multiple map projections, including Mercator, Robinson, and Plate Carrée, making it adaptable for various mapping needs. Changing projections is simple—just specify the desired projection, and GeoViews handles the rest.
For example, to switch to the Robinson projection, you can use gv.tile_sources.EsriImagery.opts(projection=ccrs.Robinson()). This flexibility allows for better representation of global datasets, minimizing distortions based on your analysis needs. Now, let’s see it in action!”
# Create a world map with Robinson projection
gv.tile_sources.EsriImagery.opts(projection=ccrs.Robinson(), width=600, height=400)
GeoViews allows you to overlay multiple map elements, such as land, oceans, rivers, and borders, to create detailed geographic visualizations with ease
A)(i) Interactive Mapping with GeoViews
GeoViews enables seamless integration with interactive tile maps, allowing users to visualize geospatial data dynamically.
This example plots data points with different sizes and colors based on magnitude, using an OSM basemap and interactive hover tools for better insight
import geoviews as gv
import geoviews.tile_sources as gts
import cartopy.crs as ccrs
import pandas as pd
gv.extension('bokeh')
# Define city coordinates
cities = pd.DataFrame({
'City': ['Delhi', 'Mumbai', 'Chennai', 'Kolkata'],
'Longitude': [77.1025, 72.8777, 80.2707, 88.3639],
'Latitude': [28.7041, 19.0760, 13.0827, 22.5726]
})
# Create points for the cities
points = gv.Points(cities, ['Longitude', 'Latitude'], 'City', crs=ccrs.PlateCarree()).opts(
size=10, color='red', tools=['hover']
)
# Create a path connecting the cities
route = gv.Path([list(zip(cities['Longitude'], cities['Latitude']))], crs=ccrs.PlateCarree()).opts(
color='blue', linewidth=2
)
# Use the correct Esri satellite imagery
satellite_map = gts.EsriImagery * route * points
satellite_map.opts(width=800, height=500, title="Satellite Map of India with Connected Cities")
GeoViews allows you to plot points with varying sizes and colors based on data values, making it easy to visualize intensity or magnitude differences across locations
import geoviews as gv
import geoviews.tile_sources as gts
gv.extension('bokeh')
# Sample data (random points)
longitudes = [-100, -50, 0, 50, 100]
latitudes = [40, 10, 0, -10, -40]
magnitudes = [2, 4, 6, 8, 10] # Example sizes
# Create interactive map with points
points = gv.Points((longitudes, latitudes, magnitudes), vdims="Magnitude")
interactive_map = gts.EsriImagery * points.opts(color='Magnitude', cmap='reds', tools=['hover'], size=gv.dim('Magnitude')*3)
interactive_map.opts(width=800, height=500, title="Interactive Map with Points")
B)(i) Interactive Data set Visualization
GeoViews and HoloViews enable dynamic mapping of global data, allowing users to explore earthquake intensities interactively with color-coded magnitude representation.
This visualization overlays data locations on an OpenStreetMap (OSM) basemap, using GeoViews’ powerful spatial mapping capabilities to enhance geospatial analysis.
import pandas as pd
import geoviews as gv
import holoviews as hv
from holoviews import opts
from cartopy import crs as ccrs
from bokeh.models import ColorBar
# Enable GeoViews and HoloViews extensions
gv.extension('bokeh')
# Load the earthquake dataset
file_path = '2.5_month.csv' # Adjust the path if necessary
data = pd.read_csv(file_path)
# Filter relevant columns: latitude, longitude, and magnitude
data = data[['latitude', 'longitude', 'mag']].dropna()
# Create a GeoViews Points object for the earthquake locations
points = gv.Points(data, kdims=['longitude', 'latitude'], vdims=['mag'], crs=ccrs.PlateCarree())
# Define options for the plot with properly labeled color bar
points = points.opts(
color='mag', # Use magnitude for color intensity
cmap='viridis', # 'viridis' gives clear intensity contrast (Blue=Low, Yellow=High)
colorbar=True,
colorbar_opts={'title': 'Earthquake Magnitude'}, # Correct way to label the color bar
size=8, # Adjust size of points based on magnitude if needed
tools=['hover'], # Add hover tool for interactivity
title='Earthquake Intensities',
width=800,
height=400,
)
# Add a basemap (OpenStreetMap)
tiles = gv.tile_sources.EsriImagery
# Combine the basemap with the earthquake points
visualization = tiles * points
# Display the visualization
visualization
C)(i) Interactive Climate Data Visualization
GeoViews and HoloViews enable dynamic exploration of geospatial climate data, allowing users to interact with surface temperature variations over time using a slider.
This example leverages Xarray datasets to efficiently handle multi-dimensional climate data and render it as an interactive heatmap overlaid with coastlines.
import panel as pn
import logging
gv.extension('bokeh')
hv.extension('bokeh')
logging.getLogger("param").setLevel(logging.ERROR)
logging.getLogger("bokeh").setLevel(logging.ERROR)
geo_dims = ['longitude', 'latitude']
xr_ensembles = xr.open_dataset('ensemble.nc', decode_timedelta=True)
time_values = list(xr_ensembles.time.values)
time_slider = pn.widgets.DiscreteSlider(name="Time", options=time_values, value=time_values[0])
def plot_surface_temperature(value):
xr_single_time = xr_ensembles.sel(time=value)
dataset = gv.Dataset(xr_single_time, kdims=geo_dims, vdims='surface_temperature')
image = dataset.to(gv.Image, geo_dims).opts(
width=1000, height=600, colorbar=True, cmap='viridis', tools=['hover']
)
return image * gf.coastline.opts(line_width=1)
dynamic_map = hv.DynamicMap(plot_surface_temperature, streams=[hv.streams.Params(time_slider, ['value'])])
pn.Row(time_slider, dynamic_map).servable()
Due to limitations of Static Notebook the plot is not being displayed. Please visit Google Colab. As Dataset isnt loaded, please do not run the cell.
GeoViews allows mapping of earthquake locations using real-world coordinates.
You can visualize earthquake magnitudes with color-coded points to identify high-risk zones.
Display temperature variations across the world using heatmaps.
Interactive time sliders help analyze trends in global warming over different years.
Use choropleth maps to highlight population density across cities and countries.
Helps urban planners allocate resources and design infrastructure effectively.
Track seasonal migration of birds and animals using GPS location data.
Conservationists can analyze movement patterns to protect endangered species.
Map real-time traffic congestion and transportation routes in urban areas.
Airlines and shipping companies can visualize flight paths and cargo movement.
There are also other practical use cases of GeoViews but we have only included a few of them here.
GeoViews is a fantastic tool for creating interactive geographical visualizations with ease. By following this guide, you should now have GeoViews installed and ready to use. With its support for multiple backends and seamless integration with HoloViews, it’s a great choice for spatial data analysis and visualization.
Official GeoViews Documentation: GeoViews Documentation
Official HoloViews Documentation: HoloViews Documentation