In ArcGIS Pro, if I have two feature layers with overlapping features, I can calculate the percentage of overlap with the TabulateIntersections function. For example, if I have two layers, one named Parcels and one named Zoning, I can figure out the zoning of particular parcels with:
import arcpy
arcpy.analysis.TabulateIntersection("Parcels", "PAN", "Zoning",
r"C:\path\to\Default.gdb\tablename",
["ZONE", "ZONE_DESC"])
I'm curious if there is a way to do this in ArcGIS Online Notebooks, where the result table would be a table in ArcGIS Online?
Solved! Go to Solution.
Just in case someone needs this answer. 🙂 My coworker came up with the follow and it appears to work exactly as needed:
#!/usr/bin/env python
# coding: utf-8
# ## Welcome to your notebook.
#
# #### Run this cell to connect to your GIS and get started:
# In[1]:
from arcgis.gis import GIS
import arcgis
import arcpy
import os
gis = GIS("home")
# #### Now you are ready to start!
# #### Directories & Paths
# In[2]:
directory = "/arcgis/home/"
zones_shp = os.path.join(directory, "zones")
parcels_shp = os.path.join(directory, "parcels")
zone_csv = os.path.join(directory, "ZonePercentages.csv")
# #### Dataframes & Data Filtering
# In[3]:
zones = arcgis.features.FeatureLayer("https://url.to.stuff.com/Zoning_Districts/FeatureServer/1").query().sdf[["ZONE", "ZONE_DESC", "SHAPE"]]
parcels = arcgis.features.FeatureLayer("https://url.to.stuff.com/Parcels_with_TaxInfo/FeatureServer/1").query().sdf[["PAN", "SHAPE"]]
# #### Shapefile Creation
# In[4]:
zones = zones.spatial.to_featureclass(zones_shp)
parcels = parcels.spatial.to_featureclass(parcels_shp)
# #### Tabulate Intersection
# In[5]:
zone_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", zones, zone_csv, ["ZONE", "ZONE_DESC"], out_units="ACRES")
# #### Upload Zone Percentages to ArcGIS Online
# In[6]:
zone_percentages_item = gis.content.add({}, zone_csv)
# #### Truncate Zone Percentages
# In[7]:
fl = arcgis.features.FeatureLayer("https://url.to.stuff.com/Zone_Percentages/FeatureServer/0")
fl.manager.truncate()
# #### Append New Data
# In[8]:
fl.append(item_id = zone_percentages_item.itemid, upload_format = "csv", source_table_name = "ZonePercentages", source_info = gis.content.analyze(item = zone_percentages_item.itemid))
# #### Delete Temporary Files
# In[9]:
zone_percentages_item.delete()
for f in os.listdir(directory):
if ".snapshot" not in f:
print(f)
if os.path.isfile(os.path.join(directory, f)):
os.remove(os.path.join(directory, f))
elif os.path.isdir(os.path.join(directory, f)):
shutil.rmtree(os.path.join(directory, f))
Just in case someone needs this answer. 🙂 My coworker came up with the follow and it appears to work exactly as needed:
#!/usr/bin/env python
# coding: utf-8
# ## Welcome to your notebook.
#
# #### Run this cell to connect to your GIS and get started:
# In[1]:
from arcgis.gis import GIS
import arcgis
import arcpy
import os
gis = GIS("home")
# #### Now you are ready to start!
# #### Directories & Paths
# In[2]:
directory = "/arcgis/home/"
zones_shp = os.path.join(directory, "zones")
parcels_shp = os.path.join(directory, "parcels")
zone_csv = os.path.join(directory, "ZonePercentages.csv")
# #### Dataframes & Data Filtering
# In[3]:
zones = arcgis.features.FeatureLayer("https://url.to.stuff.com/Zoning_Districts/FeatureServer/1").query().sdf[["ZONE", "ZONE_DESC", "SHAPE"]]
parcels = arcgis.features.FeatureLayer("https://url.to.stuff.com/Parcels_with_TaxInfo/FeatureServer/1").query().sdf[["PAN", "SHAPE"]]
# #### Shapefile Creation
# In[4]:
zones = zones.spatial.to_featureclass(zones_shp)
parcels = parcels.spatial.to_featureclass(parcels_shp)
# #### Tabulate Intersection
# In[5]:
zone_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", zones, zone_csv, ["ZONE", "ZONE_DESC"], out_units="ACRES")
# #### Upload Zone Percentages to ArcGIS Online
# In[6]:
zone_percentages_item = gis.content.add({}, zone_csv)
# #### Truncate Zone Percentages
# In[7]:
fl = arcgis.features.FeatureLayer("https://url.to.stuff.com/Zone_Percentages/FeatureServer/0")
fl.manager.truncate()
# #### Append New Data
# In[8]:
fl.append(item_id = zone_percentages_item.itemid, upload_format = "csv", source_table_name = "ZonePercentages", source_info = gis.content.analyze(item = zone_percentages_item.itemid))
# #### Delete Temporary Files
# In[9]:
zone_percentages_item.delete()
for f in os.listdir(directory):
if ".snapshot" not in f:
print(f)
if os.path.isfile(os.path.join(directory, f)):
os.remove(os.path.join(directory, f))
elif os.path.isdir(os.path.join(directory, f)):
shutil.rmtree(os.path.join(directory, f))