Data Summarization - Construction permits, part 2/2

In the "Explore and analyze construction permits" notebook, we explored your data and learned a little about the spatial and temporal trends of permit activity in Montgomery County. In this lesson, we'll move beyond exploration and run spatial analysis tools to answer specific questions that can't be answered by the data itself. In particular, we want to know why permits spiked in Germantown in 2011 and predict where future permit spikes - and, by extension, future growth - are likely to occur.

First, we'll aggregate the points by ZIP Code. We'll enrich each ZIP Code with demographic information and learn more about the demographic conditions that led to such rapid growth in such a short time. Once you determine why growth occurred where and when it did, we'll locate other ZIP Codes with similar demographic characteristics to predict future growth.

Aggregate points

Input
from arcgis import GIS
Input
gis = GIS('home')
Input
data = gis.content.search("Commercial_Permits_since_2010 owner:api_data_owner",
                          'Feature layer',
                           outside_org=True)
data[0]
Output
Commercial_Permits_since_2010
test dataFeature Layer Collection by api_data_owner
Last Modified: July 01, 2019
0 comments, 1 views
Input
permits = data[0]
permit_layer = permits.layers[0]
Input
zip_code = gis.content.search('title:ZIP Code Boundaries 2017 owner:esri_dm', 'Feature layer',
                           outside_org=True)
zip_code[0]
Output
United States ZIP Code Boundaries 2017
This layer shows the ZIP Code level boundaries of United States in 2017. The boundaries are optimized to improve Data Enrichment analysis performance.Feature Layer Collection by esri_dm
Last Modified: June 21, 2019
0 comments, 69,632 views
Input
zip_item = zip_code[0]

The USA_ZIP_Code layer is added as a new item. Since the item is a feature layer collection, using the layers property will give us a list of layers.

Input
for lyr in zip_item.layers:
    print(lyr.properties.name)
USA_Country
USA_State
USA_County
USA_ZipCode
USA_Tract
USA_BlockGroup
Input
zip_code_layer = zip_item.layers[3]

Next, you'll use this layer to aggregate permit points. By default, the parameters are set to use the ZIP Codes as the area layer, the permits as the layer to be aggregated, and the layer style to be based on permit count. These parameters are exactly what you want.

Input
from arcgis.features.summarize_data import aggregate_points
from datetime import datetime as dt
Input
permit_agg_by_zip = aggregate_points(permit_layer, zip_code_layer, 
                                     keep_boundaries_with_no_points=False,
                                     output_name='zipcode_aggregate' + str(dt.now().microsecond))
Input
permit_agg_by_zip
Output
zipcode_aggregate760079
Feature Layer Collection by arcgis_python
Last Modified: April 13, 2020
0 comments, 1 views

Aggregation results

Input
agg_map = gis.map('Maryland')
agg_map
Output
Input
agg_map.add_layer(permit_agg_by_zip)

The new layer looks like a point layer, but it's actually a polygon layer with a point symbology. Each point represents the number of permits per ZIP Code area. Larger points indicate ZIP Codes with more permits.

Input
import pandas as pd
Input
sdf = pd.DataFrame.spatial.from_layer(permit_agg_by_zip.layers[0])
Input
sdf.head(10)
Output
AnalysisArea OBJECTID POPULATION PO_NAME Point_Count SHAPE SQMI STATE ZIP_CODE
0 2.356814 1 14652 Washington 6 {"rings": [[[-77.0266270001359, 38.98455799965... 2.36 DC 20012
1 6.248092 2 48592 Hyattsville 1 {"rings": [[[-76.9414389999099, 39.02912599996... 6.26 MD 20783
2 0.191061 3 219 Glen Echo 1 {"rings": [[[-77.1384300001444, 38.96841399980... 0.19 MD 20812
3 5.168331 4 30017 Bethesda 1145 {"rings": [[[-77.0943629995527, 39.02250799964... 5.17 MD 20814
4 5.360828 5 30001 Chevy Chase 586 {"rings": [[[-77.0635971995511, 39.01197539974... 5.35 MD 20815
5 4.607703 6 16967 Bethesda 154 {"rings": [[[-77.1429960002652, 38.97162000016... 4.61 MD 20816
6 13.889993 7 38385 Bethesda 732 {"rings": [[[-77.1267290001432, 39.02947299977... 13.89 MD 20817
7 0.978536 8 1383 Cabin John 13 {"rings": [[[-77.1573989998639, 38.98250600035... 0.98 MD 20818
8 9.426954 9 26858 Olney 216 {"rings": [[[-77.0921479999302, 39.16957599993... 9.43 MD 20832
9 22.871336 10 8380 Brookeville 40 {"rings": [[[-77.0616859999089, 39.27760500037... 22.87 MD 20833
Input
sdf.reset_index(inplace=True)
Input
sdf.head()
Output
index AnalysisArea OBJECTID POPULATION PO_NAME Point_Count SHAPE SQMI STATE ZIP_CODE
0 0 2.356814 1 14652 Washington 6 {"rings": [[[-77.0266270001359, 38.98455799965... 2.36 DC 20012
1 1 6.248092 2 48592 Hyattsville 1 {"rings": [[[-76.9414389999099, 39.02912599996... 6.26 MD 20783
2 2 0.191061 3 219 Glen Echo 1 {"rings": [[[-77.1384300001444, 38.96841399980... 0.19 MD 20812
3 3 5.168331 4 30017 Bethesda 1145 {"rings": [[[-77.0943629995527, 39.02250799964... 5.17 MD 20814
4 4 5.360828 5 30001 Chevy Chase 586 {"rings": [[[-77.0635971995511, 39.01197539974... 5.35 MD 20815

Review some basic statistics about the data.

Input
sdf['Point_Count'].mean()
Output
249.42222222222222
Input
sdf['Point_Count'].max()
Output
1145
Input
sdf['Point_Count'].min()
Output
1
Input
agg_layer = permit_agg_by_zip.layers[0]

Although most of the large point symbols on the map are in the southeast corner, near Washington, D.C., there are a few large points in the northwest. In particular, there is a very large circle in the ZIP Code located in Clarksburg. (If you're using different ZIP Code data, this area may be identified as ZIP Code 20871 instead.) The ZIP code has 948 permits. Additionally, this area geographically corresponds to the hot spot you identified in the previous lesson. This ZIP Code is one that you'll focus on when you enrich your layer with demographic data.

Enrich the data

Are there demographic characteristics about the Clarksburg ZIP Code that contributed to its high growth? If so, are there other areas with those characteristics that may experience growth in the future? To answer these questions, you'll use the Enrich Data analysis tool. This tool adds demographic attributes of your choice to your data. Specifically, you'll add Tapestry information to each ZIP Code. Tapestry is a summary of many demographic and socioeconomic variables, including age groups and lifestyle choices. It'll teach you more about the types of people who live in your area of interest and help you better understand the reasons why growth happened where it did.

Input
from arcgis.features.enrich_data import enrich_layer
Input
enrich_aggregate = enrich_layer(agg_layer, 
                                analysis_variables=["AtRisk.TSEGNAME"],
                                output_name="added_tapestry_var" + str(dt.now().microsecond))
Input
enrich_aggregate
Output
added_tapestry_var285913
Feature Layer Collection by arcgis_python
Last Modified: April 13, 2020
0 comments, 0 views
Input
agg_lyr = enrich_aggregate.layers[0]
Input
sdf = pd.DataFrame.spatial.from_layer(agg_lyr)
Input
sdf.head()
Output
AnalysisArea ENRICH_FID HasData ID OBJECTID POPULATION PO_NAME Point_Count SHAPE SQMI STATE TSEGNAME ZIP_CODE aggregationMethod apportionmentConfidence populationToPolygonSizeRating sourceCountry
0 2.356814 1 1 0 1 14652 Washington 6 {"rings": [[[-77.026627, 38.9845580000001], [-... 2.36 DC City Lights 20012 BlockApportionment:US.BlockGroups 2.576 2.191 US
1 6.248092 2 1 1 2 48592 Hyattsville 1 {"rings": [[[-76.9414389999999, 39.02912600000... 6.26 MD NeWest Residents 20783 BlockApportionment:US.BlockGroups 2.576 2.191 US
2 0.191061 3 1 2 3 219 Glen Echo 1 {"rings": [[[-77.13843, 38.9684140000001], [-7... 0.19 MD Urban Chic 20812 BlockApportionment:US.BlockGroups 2.576 2.191 US
3 5.168331 4 1 3 4 30017 Bethesda 1145 {"rings": [[[-77.094363, 39.0225080000001], [-... 5.17 MD Metro Renters 20814 BlockApportionment:US.BlockGroups 2.576 2.191 US
4 5.360828 5 1 4 5 30001 Chevy Chase 586 {"rings": [[[-77.0635971999999, 39.0119754], [... 5.35 MD Top Tier 20815 BlockApportionment:US.BlockGroups 2.576 2.191 US
Input
enrich_aggregate_map = gis.map('Maryland')
Input
enrich_aggregate_map
Output
Input
sdf.spatial.plot(kind='map', map_widget=enrich_aggregate_map,
        renderer_type='u',
        col='TSEGNAME') 
Output
True

Click some of the ZIP Codes.

The Tapestry segment is displayed when you click a ZIP Code. The Tapestry segments have names such as Enterprising Professionals and Savvy Suburbanites. You can look up more information about each segment, including its specific demographic characteristics, on the Tapestry Segmentation help page.

What Tapestry segment is dominant for the Clarksburg ZIP Code where major growth occurred? Click the Clarksburg ZIP Code to find out. According to the pop-up, Boomburbs is the dominant Tapestry segment for the ZIP Code. Boomburbs have many young professionals with families living in affordable new housing. This description may explain why the area saw such rapid residential growth in 2011. It's possible that other ZIP Codes with similar demographic profiles may experience rapid growth in the near future.

Click the ZIP Code directly southwest of Clarksburg.

This ZIP Code is in Boyds. It also has the Boomburbs Tapestry segment. However, its number of permits has been relatively low since 2010. The county may be able to anticipate a similar spike in permit activity in this area.

Although Tapestry segments are based on several demographic characteristics, you could also perform this analysis with other variables. For instance, you could determine if there is a correlation between high permit activity and high population growth. Is a young population or a high income level a stronger indicator of growth? You can answer these questions and others with the analysis tools at your disposal. For the purposes of this lesson, however, your results are satisfactory.

Input
enrich_aggregate_map.add_layer(agg_lyr, {'renderer':'ClassedSizeRenderer',
                                             'field_name':'POPULATION',
                                             'opacity':0.75})

Share your work

We've analyzed your data and come to a couple conclusions about your data. Next, we'll share your results online. Currently, our result layers are layers that are accessible only to you. Sharing our data will make it easier for county officials to use your data in other ArcGIS applications and communicate key information to the public. In particular, we'll share your work to ArcGIS Online. We'll share your enriched ZIP Codes dataset as feature layers that can be added to any web map.

The layer contains fields for both the count of permits per ZIP Code and the dominant Tapestry segment—basically all of the result data we created in your analysis. We'll only need to share this layer, not the original aggregation layer.

Using the share() method you can share your work with others.

Input
enrich_aggregate.share(everyone=True)
Output
{'notSharedWith': [], 'itemId': '0ad0439ef9394afd96ebb6d16e3653b2'}

In this notebook, we used ArcGIS API for Python to explore and analyze permit data for Montgomery County, Maryland. You answered questions about your data's spatial and temporal trends and located areas of the county with rapid growth. We compared your findings with demographic data, came to conclusions about the possible causes of growth, and even predicted an area that may experience similar growth in the future based on shared demographic characteristics. With ArcGIS API for Python, we can perform a similar workflow on any of your data to better understand what it contains and what questions it can answer.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.