Visualizing Geospatial Data in Jupyter with Kepler.gl: A Comprehensive Guide

Geospatial data is taking the world by storm. From location tracking and location-based marketing to urban planning and navigation, the applications of geospatial data are virtually limitless. As the volume and variety of geospatial data increases, so does the need for powerful tools to explore, analyze and visualize this data.

This is where kepler.gl comes in. Kepler.gl is a high-performance, web-based application for visual exploration of large-scale geospatial datasets. Developed by Uber‘s visualization team, kepler.gl leverages deck.gl, Mapbox GL and React to provide a highly interactive and immersive experience for visualizing geospatial data.

In this article, we‘ll take a deep dive into kepler.gl and learn how to use it to visualize geospatial data in Jupyter notebooks. We‘ll walk through a real-world case study of visualizing taxi trip data in New York City and learn how to create stunning 3D maps, apply filters, customize layers and more. By the end, you‘ll have a solid understanding of how to use kepler.gl to uncover insights from your geospatial data. Let‘s get started!

What is Kepler.gl?

Before we jump into the tutorial, let‘s briefly go over what kepler.gl is and why you should use it for geospatial data visualization.

Kepler.gl is an open-source geospatial analysis tool for large-scale datasets. It couples a powerful backend with a sleek frontend to provide a highly interactive and immersive experience for visualizing and exploring geospatial data.

Some key features of kepler.gl include:

  • GPU-powered rendering engine for visualizing millions of points
  • A rich set of map layers including arcs, heatmaps, hexbins, points, polygons and more
  • Filters for exploring subsets of data
  • Ability to style map elements and customize colors
  • 3D mapping support with zoom, pan and tilt controls
  • Easy integration with Jupyter notebooks and other Python-based tools

Kepler.gl is used by a wide range of organizations and individuals for geospatial data visualization, from urban planners and logistics firms to academic researchers and data journalists. Its ease of use and powerful features make it an excellent choice for anyone working with location data.

Installing Kepler.gl

Now that we have a sense of what kepler.gl is, let‘s see how to install and use it in a Jupyter notebook. Kepler.gl can be installed via pip:

!pip install keplergl

Once installed, we can import keplergl into our notebook:

import keplergl

We‘re now ready to start visualizing geospatial data with kepler.gl!

Case Study: Visualizing NYC Taxi Trip Data

To see kepler.gl in action, let‘s walk through a real-world example of visualizing a geospatial dataset. We‘ll be working with data on over 97,000 taxi trips in New York City from January 15, 2015.

The Dataset

The dataset contains the following fields:

  • pickup_datetime: timestamp of the taxi pickup
  • dropoff_datetime: timestamp of the taxi dropoff
  • passenger_count: number of passengers on the trip
  • trip_distance: distance of the trip in miles
  • pickup_longitude: longitude coordinate of the pickup location
  • pickup_latitude: latitude coordinate of the pickup location
  • dropoff_longitude: longitude coordinate of the dropoff location
  • dropoff_latitude: latitude coordinate of the dropoff location
  • fare_amount: the base fare of the trip
  • tip_amount: the tip given for the trip
  • total_amount: the total amount charged for the trip

Here‘s a sample of what the data looks like:

Visualizing Pickup and Dropoff Locations

To start, let‘s visualize the pickup and dropoff locations of the taxi trips on a map. We can do this by creating a POINT layer in kepler.gl.

First, we create a kepler.gl instance in our notebook:

map = keplergl.KeplerGl(height=600)

This creates a blank map in our notebook that is 600 pixels high. We can now add our taxi data to the map using the add_data method:

map.add_data(data=df, name=‘taxi_data‘)

Kepler.gl will automatically detect the latitude and longitude columns in our data and plot the points on the map. We can then open the Layers panel and create a new Point layer:

In the Point layer settings, we can style the points, such as changing the color based on whether the point is a pickup or dropoff location:

Here‘s what the final plot looks like:

We can see the pickup locations in blue and the dropoff locations in orange. Already we start to notice some interesting patterns, like how pickup locations are concentrated in Manhattan while dropoffs are more spread out.

Visualizing Trip Arcs

To visualize the trips themselves, let‘s plot them as arcs on the map, with the arc starting at the pickup location and ending at the dropoff point.

In kepler.gl, we can do this by adding an Arc layer and setting the start and end points:

And here‘s the result:

The yellow arcs trace out the path of each individual taxi trip, giving us a sense of the flow of traffic from pickups to dropoffs. Longer arcs indicate longer trips. We can see that most trips are concentrated in lower and midtown Manhattan.

To make the arcs more visually striking, let‘s convert the map to 3D:

The 3D arcs really highlight the journeys and add a whole new dimension to the visualization. The longer arcs are shown rising higher off the map.

Adding Filters

Kepler.gl also allows us to filter the data in various ways to explore different subsets and slices. For example, we can filter trips by distance by adding a range filter on the trip_distance column:

Here‘s the result after filtering for just long trips over 18 miles:

The 3D arcs for the long trips extend high into the air, with many traveling to and from the airports. Filtering allows us to focus on specific segments of interest.

Customizing the Map

Finally, let‘s customize the background map style for a finishing touch. Kepler.gl provides a variety of map styles to choose from:

For this visualization, let‘s go with a dark, high-contrast basemap:

The dark basemap makes the trip arcs really pop visually and highlights the glowing city lights. We can pan, zoom and tilt the map to explore the trips from any angle.

Saving and Exporting

Once you‘ve created your visualization in kepler.gl, you‘ll likely want to save it to return to later or share with others. Kepler.gl provides a few different options for saving and exporting your visualizations.

To save the current state of your map, you can simply click the "Save" button in the kepler.gl toolbar:

This will save the map config (the layers, filters, map style, etc.) to the notebook as a JSON object. You can reload this any time to pick up where you left off.

You can also export the map to HTML or as an image. To export to HTML, run:

map.save_to_html(file_name=‘my_map.html‘)

This saves an interactive version of your map that can be opened and explored in any web browser.

Finally, you can also export the map as a static image in PNG or SVG format:

map.save_as_html(file_name=‘my_map.png‘)

The exported image will capture the current view of the map.

Conclusion

Geospatial data visualization is a powerful way to explore and make sense of location-based datasets. Kepler.gl makes the process of visualizing geospatial data simple and intuitive, while still providing a wide range of customization and styling options.

In this tutorial, we walked through how to use kepler.gl in a Jupyter notebook to visualize a real-world dataset of taxi trips in New York City. We learned how to create different types of map layers, customize the map style, filter the data, and export our visualizations.

The kepler.gl tool offers a ton of possibilities for geospatial data visualization and the framework shared here can be applied to any location dataset. I encourage you to try it out with your own data and see what insights you can uncover!

To learn more about kepler.gl, check out these additional resources:

Happy mapping!

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Similar Posts