<?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 Re: Can I dissolve polygons in spatially enabled dataframe? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/can-i-dissolve-polygons-in-spatially-enabled/m-p/1116427#M6811</link>
    <description>&lt;P&gt;You can use Shapely's unary_union to dissolve geometries. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.features import FeatureLayer
from shapely.ops import unary_union
from arcgis.geometry import Geometry

# query some counties
counties_layer = FeatureLayer('https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Counties_Generalized/FeatureServer/0')
counties = counties_layer.query(
    where="STATE_NAME IN ('California', 'Oregon', 'Washington')",
    out_fields='NAME,STATE_NAME',
    as_df=True
)

# function to dissolve polygons
def dissolve_polys(polys):
    # convert to shapely polygons, using the buffer(0) trick to correct invalid polygons
    shapely_polys = [s.as_shapely.buffer(0) for s in polys]
    # union polygons
    dissolved_poly = unary_union(shapely_polys)
    # convert back to arcgis geometry
    return Geometry(dissolved_poly.__geo_interface__, spatialReference=polys.iloc[0].spatialReference)

# dissolve county polygons by state
counties_dissolve = counties\
    .groupby('STATE_NAME')\
    .apply(lambda x: dissolve_polys(x.SHAPE))\
    .reset_index(name='SHAPE')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;NOTE: There &lt;A href="https://community.esri.com/t5/arcgis-api-for-python-questions/issues-with-shapely-and-polygons-having-holes/td-p/796832" target="_self"&gt;can be issues&lt;/A&gt;&amp;nbsp;converting between Shapely and Esri polygons, so check your output shapes. In the counties example above, several island polygons (such California's Channel Islands) don't get included in the dissolved polygon.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Nov 2021 18:07:31 GMT</pubDate>
    <dc:creator>J_R_Matchett</dc:creator>
    <dc:date>2021-11-12T18:07:31Z</dc:date>
    <item>
      <title>Can I dissolve polygons in spatially enabled dataframe?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/can-i-dissolve-polygons-in-spatially-enabled/m-p/1115729#M6805</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Do &lt;A href="https://developers.arcgis.com/python/guide/introduction-to-the-spatially-enabled-dataframe/" target="_blank" rel="noopener"&gt;Spatially Enabled Dataframes&lt;/A&gt; have an equivalent to &lt;A href="https://geopandas.org/en/stable/docs/user_guide/aggregation_with_dissolve.html" target="_blank" rel="noopener"&gt;Geopandas .dissolve()&lt;/A&gt; method?&lt;/P&gt;&lt;P&gt;I've looked through the API documentation under both GeoAccessor and GeoSeriesAccessor but cannot find any classess or methods to dissolve/aggregate polygons for an SEDF.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE - I tried doing the dissolve in geopandas and just exporting the dissolved result&amp;nbsp; to an SEDF using the &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.GeoAccessor.from_geodataframe" target="_blank" rel="noopener"&gt;from_geodataframe&lt;/A&gt; method, but long story short, I've been having some problems with Geopandas and getting it to play nice with the arcgis python environment.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 17:30:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/can-i-dissolve-polygons-in-spatially-enabled/m-p/1115729#M6805</guid>
      <dc:creator>DarrenConly</dc:creator>
      <dc:date>2021-11-10T17:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can I dissolve polygons in spatially enabled dataframe?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/can-i-dissolve-polygons-in-spatially-enabled/m-p/1115741#M6806</link>
      <description>&lt;P&gt;Based on what I have read, Esri is focused on updating a new set of objects called&amp;nbsp;&lt;STRONG&gt;GeoAcessors.&amp;nbsp;&lt;/STRONG&gt; They are a lot like Geopandas and have the ability to apply both Shapely and Esri methods. Unfortunately .dissolve() is not one that is supported.&lt;/P&gt;&lt;P&gt;I think what you can get what you are looking for though by converting to a Feature collection or layer and then applying a .dissolve_boundries() &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.manage_data.html#dissolve-boundaries" target="_self"&gt;https://developers.arcgis.com/python/api-reference/arcgis.features.manage_data.html#dissolve-boundaries&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 17:50:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/can-i-dissolve-polygons-in-spatially-enabled/m-p/1115741#M6806</guid>
      <dc:creator>GregoryAgamalian</dc:creator>
      <dc:date>2021-11-10T17:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can I dissolve polygons in spatially enabled dataframe?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/can-i-dissolve-polygons-in-spatially-enabled/m-p/1116427#M6811</link>
      <description>&lt;P&gt;You can use Shapely's unary_union to dissolve geometries. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.features import FeatureLayer
from shapely.ops import unary_union
from arcgis.geometry import Geometry

# query some counties
counties_layer = FeatureLayer('https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Counties_Generalized/FeatureServer/0')
counties = counties_layer.query(
    where="STATE_NAME IN ('California', 'Oregon', 'Washington')",
    out_fields='NAME,STATE_NAME',
    as_df=True
)

# function to dissolve polygons
def dissolve_polys(polys):
    # convert to shapely polygons, using the buffer(0) trick to correct invalid polygons
    shapely_polys = [s.as_shapely.buffer(0) for s in polys]
    # union polygons
    dissolved_poly = unary_union(shapely_polys)
    # convert back to arcgis geometry
    return Geometry(dissolved_poly.__geo_interface__, spatialReference=polys.iloc[0].spatialReference)

# dissolve county polygons by state
counties_dissolve = counties\
    .groupby('STATE_NAME')\
    .apply(lambda x: dissolve_polys(x.SHAPE))\
    .reset_index(name='SHAPE')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;NOTE: There &lt;A href="https://community.esri.com/t5/arcgis-api-for-python-questions/issues-with-shapely-and-polygons-having-holes/td-p/796832" target="_self"&gt;can be issues&lt;/A&gt;&amp;nbsp;converting between Shapely and Esri polygons, so check your output shapes. In the counties example above, several island polygons (such California's Channel Islands) don't get included in the dissolved polygon.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 18:07:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/can-i-dissolve-polygons-in-spatially-enabled/m-p/1116427#M6811</guid>
      <dc:creator>J_R_Matchett</dc:creator>
      <dc:date>2021-11-12T18:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: Can I dissolve polygons in spatially enabled dataframe?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/can-i-dissolve-polygons-in-spatially-enabled/m-p/1116706#M6816</link>
      <description>&lt;P&gt;Thanks Gregory,&lt;/P&gt;&lt;P data-unlink="true"&gt;I tried running &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.GeoAccessor.to_feature_collection" target="_self"&gt;sedf.spatial.to_feature_collection()&lt;/A&gt; like so:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fcn = "feat_colln"
sedf.spatial.to_feature_collection(fcn)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;But I got this error message:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;KeyError                                  Traceback (most recent call last)
&amp;lt;ipython-input-32-1c370e0f59c6&amp;gt; in &amp;lt;module&amp;gt;
      4 import arcgis
      5 fcn = "feat_colln"
----&amp;gt; 6 sedf.spatial.to_feature_collection(fcn)
      7 
      8 # arcgis.features.manage_data.dissolve_boundaries(fcn)

~\AppData\Local\ESRI\conda\envs\arcgispro-nov042021\lib\site-packages\arcgis\features\geo\_accessor.py in to_feature_collection(self, name, drawing_info, extent, global_id_field)
   2798                 "spatialReference" : self.sr
   2799             }
-&amp;gt; 2800         fs = self.__feature_set__
   2801         fields = []
   2802         for fld in fs['fields']:

~\AppData\Local\ESRI\conda\envs\arcgispro-nov042021\lib\site-packages\arcgis\features\geo\_accessor.py in __feature_set__(self)
   2530             "globalIdFieldName" : "",
   2531             "displayFieldName" : "",
-&amp;gt; 2532             "geometryType" : _geom_types[type(self._data[self.name][self._data[self.name].first_valid_index()])],
   2533             "spatialReference" : sr,
   2534             "fields" : [],

KeyError: &amp;lt;class 'pandas.core.series.Series'&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it helps, here are the first few rows of the SEDF:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DarrenConly_0-1636933852852.png" style="width: 753px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/27385iFEB0558A7E4A8AD4/image-dimensions/753x151?v=v2" width="753" height="151" role="button" title="DarrenConly_0-1636933852852.png" alt="DarrenConly_0-1636933852852.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 23:51:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/can-i-dissolve-polygons-in-spatially-enabled/m-p/1116706#M6816</guid>
      <dc:creator>DarrenConly</dc:creator>
      <dc:date>2021-11-14T23:51:20Z</dc:date>
    </item>
  </channel>
</rss>

