<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Tabulate Intersections in ArcGIS Online notebooks? in ArcGIS Online Developers Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-developers-questions/tabulate-intersections-in-arcgis-online-notebooks/m-p/1288800#M1228</link>
    <description>&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
arcpy.analysis.TabulateIntersection("Parcels", "PAN", "Zoning", 
                                    r"C:\path\to\Default.gdb\tablename",
                                   ["ZONE", "ZONE_DESC"])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2023 21:47:27 GMT</pubDate>
    <dc:creator>RogerAsbury</dc:creator>
    <dc:date>2023-05-12T21:47:27Z</dc:date>
    <item>
      <title>Tabulate Intersections in ArcGIS Online notebooks?</title>
      <link>https://community.esri.com/t5/arcgis-online-developers-questions/tabulate-intersections-in-arcgis-online-notebooks/m-p/1288800#M1228</link>
      <description>&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
arcpy.analysis.TabulateIntersection("Parcels", "PAN", "Zoning", 
                                    r"C:\path\to\Default.gdb\tablename",
                                   ["ZONE", "ZONE_DESC"])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 21:47:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-developers-questions/tabulate-intersections-in-arcgis-online-notebooks/m-p/1288800#M1228</guid>
      <dc:creator>RogerAsbury</dc:creator>
      <dc:date>2023-05-12T21:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Tabulate Intersections in ArcGIS Online notebooks?</title>
      <link>https://community.esri.com/t5/arcgis-online-developers-questions/tabulate-intersections-in-arcgis-online-notebooks/m-p/1289684#M1229</link>
      <description>&lt;P&gt;Just in case someone needs this answer. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; My coworker came up with the follow and it appears to work exactly as needed:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#!/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 &amp;amp; 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 &amp;amp; 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))&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 16 May 2023 17:21:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-developers-questions/tabulate-intersections-in-arcgis-online-notebooks/m-p/1289684#M1229</guid>
      <dc:creator>RogerAsbury</dc:creator>
      <dc:date>2023-05-16T17:21:11Z</dc:date>
    </item>
  </channel>
</rss>

