{ "cells": [ { "cell_type": "markdown", "id": "68b4877a-d595-47b4-988f-b470eb4251e5", "metadata": {}, "source": [ "# North America Roads\n", "\n", "This example uses data from [Natural Earth](https://www.naturalearthdata.com/) to plot the road network in North America. Refer to the [data documentation](https://www.naturalearthdata.com/downloads/10m-cultural-vectors/roads/) for more information about this dataset." ] }, { "cell_type": "markdown", "id": "c4f33772-767a-4f79-ab31-b75ddb07089d", "metadata": {}, "source": [ "## Dependencies\n", "\n", "- lonboard\n", "- pyogrio" ] }, { "cell_type": "markdown", "id": "d404b794-1456-42ee-9161-c50b70c831ef", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "id": "51abc06e-0d06-40ef-aea6-19130e88bce3", "metadata": {}, "outputs": [], "source": [ "import geopandas as gpd\n", "import palettable.colorbrewer.diverging\n", "\n", "from lonboard import Map, PathLayer\n", "from lonboard.colormap import apply_continuous_cmap" ] }, { "cell_type": "markdown", "id": "d4ddc6c3-7538-44cd-a082-912aa5aef1cc", "metadata": {}, "source": [ "The \"public\" URL for this dataset from the Natural Earth website is\n", "```\n", "https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_roads_north_america.zip\n", "```\n", "That doesn't appear to work directly inside a notebook, so we'll use the URL the above redirects to:\n", "\n", "```\n", "https://naciscdn.org/naturalearth/10m/cultural/ne_10m_roads_north_america.zip\n", "```\n", "\n", "It's possible this \"private\" URL will change in the future." ] }, { "cell_type": "code", "execution_count": 2, "id": "ce868022-f3e4-4db5-83d7-af65b5e2f959", "metadata": {}, "outputs": [], "source": [ "url = 'https://naciscdn.org/naturalearth/10m/cultural/ne_10m_roads_north_america.zip'" ] }, { "cell_type": "markdown", "id": "6d77aa88-6d94-4eac-a5c7-e52efcc93930", "metadata": {}, "source": [ "We'll use GeoPandas to fetch this data (45MB) over the internet and load it into a `GeoDataFrame`. This uses the [`pyogrio` engine](https://geopandas.org/en/stable/docs/reference/api/geopandas.read_file.html), which is faster. Ensure you have [`pyogrio`](https://github.com/geopandas/pyogrio) installed. " ] }, { "cell_type": "code", "execution_count": 3, "id": "c97da98c-cce8-4f66-b598-59eef05367de", "metadata": {}, "outputs": [], "source": [ "gdf = gpd.read_file(url, engine=\"pyogrio\")" ] }, { "cell_type": "markdown", "id": "f4a9b9a1-9d78-42a3-be88-60ac550a84de", "metadata": {}, "source": [ "This dataframe has a variety of attributes, plus a geometry column with a `LineString` type." ] }, { "cell_type": "code", "execution_count": 4, "id": "14d60ee4-4006-48b3-8ddb-52e3ae6002da", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
| \n", " | prefix | \n", "number | \n", "class | \n", "type | \n", "divided | \n", "country | \n", "state | \n", "note | \n", "scalerank | \n", "uident | \n", "length | \n", "rank | \n", "continent | \n", "geometry | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "None | \n", "None | \n", "Other | \n", "Unpaved | \n", "None | \n", "United States | \n", "California | \n", "None | \n", "12 | \n", "0 | \n", "10.373500 | \n", "0 | \n", "North America | \n", "LINESTRING (-119.63954 37.85634, -119.63954 37... | \n", "
| 1 | \n", "None | \n", "None | \n", "Other | \n", "Other Paved | \n", "None | \n", "United States | \n", "Nevada | \n", "None | \n", "12 | \n", "1 | \n", "2.307760 | \n", "0 | \n", "North America | \n", "LINESTRING (-119.76779 39.14514, -119.74707 39... | \n", "
| 2 | \n", "None | \n", "S2 | \n", "Other | \n", "Other Paved | \n", "None | \n", "Mexico | \n", "None | \n", "None | \n", "11 | \n", "2 | \n", "92.178100 | \n", "-1 | \n", "North America | \n", "LINESTRING (-116.47485 33.09658, -116.46246 33... | \n", "
| 3 | \n", "None | \n", "S1 | \n", "Other | \n", "Other Paved | \n", "None | \n", "United States | \n", "California | \n", "None | \n", "11 | \n", "3 | \n", "46.124100 | \n", "0 | \n", "North America | \n", "LINESTRING (-116.56070 33.01205, -116.55359 33... | \n", "
| 4 | \n", "None | \n", "S1 | \n", "Other | \n", "Secondary | \n", "Undivided | \n", "United States | \n", "California | \n", "None | \n", "10 | \n", "4 | \n", "0.305463 | \n", "0 | \n", "North America | \n", "LINESTRING (-116.50827 32.81225, -116.50820 32... | \n", "