Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS API for Python

Download the samples Try it live

Designate Bike Routes for Commuting Professionals

Traffic congestion has been increasing in cities due to long commutes to and from work. A simple measure of using bicycles for commuting can prove to be a very effective solution for this problem. This will also be a healthy option for individuals by making them physically active. In order to encourage citizens to use bicycles for commute, cities need to ensure that there are adequate number of safe bike lanes.

This sample uses ArcGIS API for Python to analyze and select streets for making bike routes for people commuting to and from work in the City of Seattle, Washington. It will demostrate the use tools such as find_existing_locations, create_buffers, merge_layers, dissolve_boundaries, overlay_layers, enrich_layer, and attribute query. We will also be using Esri Tapestry Segmentation to perform this analysis.

The aim of this analysis is to:

  • inrease the number of bike lanes in the city
  • ensure that every residence is within 1/2 mile of a bike route
  • add protected bike lanes on busy streets that offer a barrier between the bike lanes and cars on roads, and
  • make sure that atleast 5 percent of the total length of streets have bicycle lanes. This is a figure that is at par with that of Portland, Oregon, which is one of the most bicycle-friendly cities in the United States.

Workflow

Steps

We will use the following steps for the analysis:

1) Retrieve the SeattleBikeRoutes layer.

2) Filter Seattle's zoning layer by downtown office.

3) Identify high demand neighborhood. We use the tapestry segmentation layer and visualize it on the map. We click some of the segments in the vicinity of Downtown area and choose a segment that contains young, health-conscious and environmentally-conscious professionals, i.e, Capitol Hill which serves as a good target to get started.

4) Filter neighborhoods layer by Capitol Hill.

5) Check if the bike lanes can be made on trails.

5) Use find existing_locations to get arterial streets layer. We use this tool to select the streets which will be the most appropriate for making bike lanes.

6) Select the first street from the results we got from step 5.

7) Calculate the length of the street.

8) Apply a Buffer of 0.5 miles to this street.

9) Repeat step 6, 7, 8 for the second and third street.

10) Calculate the percentage of road length used for making bike lanes

11) Merge the buffered layers and dissolve boundaries to get a single polygon.

12) Use overlay layers to clip the buffers into the shape of Capitol Hill

13) Enrich the clipped layer by population data using enrich_layer method.

14) Calculate the total population of Capitol Hill that will benefit

Necessary Imports

In [1]:
from datetime import datetime as dt

from arcgis import GIS
from arcgis.features import FeatureLayerCollection
from arcgis.features.find_locations import find_existing_locations
from arcgis.features.use_proximity import create_buffers
from arcgis.features.manage_data import merge_layers
from arcgis.features.manage_data import dissolve_boundaries
from arcgis.features.manage_data import overlay_layers
from arcgis.features.enrich_data import enrich_layer

Connect to your ArcGIS online organization

In [2]:
gis = GIS(profile="your_online_profile")

We can use the search() method of the content property of our gis object to get the Seattle Bike Routes layer. Since this is public content shared by users outside our organization, we will search for SeattleBikeRoutes and set outside_org to True.

Get the data for the analysis.

In [3]:
seattle_bike_routes = gis.content.search('title: SeattleBikeRoutes owner: api_data_owner',
                                         'Feature layer')[0]
seattle_bike_routes
Out[3]:
SeattleBikeRoutes
datascienceFeature Layer Collection by api_data_owner
Last Modified: June 13, 2019
0 comments, 0 views

We can print the names of the layers in this item and assign them to variables that will be used in our analysis.

In [4]:
for lyr in seattle_bike_routes.layers:
    print(lyr.properties.name)
SeattleBikeRoutes_street
SeattleBikeRoutes_zoning
SeattleBikeRoutes_Neighborhoods
In [5]:
bike_route_streets = seattle_bike_routes.layers[0]
In [6]:
bike_route_zoning = seattle_bike_routes.layers[1]
In [7]:
bike_route_neighbourhood = seattle_bike_routes.layers[2]

Identify expected commuter neighborhoods

We will set a filter on the Zoning layer to select the downtown office core. The downtown office core is a good starting point for creating commuter bike lanes because it is expected to have a large number of commuters each day.

In [8]:
bike_route_zoning.filter = "(ZONELUT_DE = 'Downtown Office Core 1') OR (ZONELUT_DE = 'Downtown Office Core 2')"

Apply a filter to the Neighborhoods so that only Capitol Hill shows up.

In [9]:
bike_route_neighbourhood.filter = "L_HOOD = 'CAPITOL HILL'"
In [10]:
tapestry_segmentation = gis.content.search('"2018 USA Tapestry segmentation" owner: api_data_owner',
                                           'Map Image Layer')[0]
In [11]:
tapestry_segmentation
Out[11]:
2018 USA Tapestry Segmentation
This layer shows the dominant LifeMode Summary Group in the United States in 2018 by state, county, ZIP Code, tract, and block group based on Esri's Tapestry Segmentation system. ArcGIS Online subscription required.Map Image Layer by api_data_owner
Last Modified: June 05, 2019
0 comments, 0 views
In [12]:
tapestry_map = gis.map('Seattle')
tapestry_map
Out[12]:
In [13]:
tapestry_map.add_layer(tapestry_segmentation)

The neighborhood in the 98112 ZIP Code, called Capitol Hill, contains the Urban Chic, Laptops and Lattes, and Metro Renters segments. All three of the segments designated in the ZIP Code mention environmental awareness and biking, which makes the ZIP Code a good choice to get the bike lane project started.

Identify potential bike routes

The Streets layer includes main streets, trails, and other street types. Let's look at the trails first to determine if they can be used for commuting.

Filter the Streets so that only the trails are showing, by setting a definition expression that filters the roads by the segment type of trails (SEGMENT_TY = 8).

In [14]:
bike_street_filtered_map = gis.map('Seattle')
bike_street_filtered_map
Out[14]:
In [15]:
bike_street_filtered_map.add_layer({"type":"FeatureLayer", 
               "url":bike_route_streets.url,
               "definition_expression" : "SEGMENT_TY = 8", # code for trails
              })

There are only three trails in the neighborhood and they are not long enough to be used for commuting.

As there are not enough trails in the Capitol Hill neighborhood, the bike lanes will have to be created on pre-existing streets. Since Seattle wants to build protected bike lanes, we will look at busier streets first to find the most direct routes.

Find busy streets using find_existing_locations

Let's use find_existing_locations() to select the arterial streets (where SEGMENT_TY is 1 and where ARTERIAL_C is 1).

In [16]:
busy_streets = find_existing_locations(input_layers=[{'url': bike_route_streets.url}], 
                                       expressions=[{"operator":"","layer":0,"where":"SEGMENT_TY = 1"},
                                                    {"operator":"and","layer":0,"where":"ARTERIAL_C = 1"}],
                                       output_name='ArterialStreets'+ str(dt.now().microsecond))
In [17]:
busy_streets.layers[0].query(return_geometry=False, where='1=1')
Out[17]:
<FeatureSet> 6605 features
In [18]:
busy_streets_map = gis.map('Seattle')
busy_streets_map
Out[18]: