<?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 Converting geodataframe to spatially enabled dataframe messes the polygon geometry in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1099998#M6667</link>
    <description>&lt;P&gt;I use a script to get data into our ArcGIS online organization, but it seems like the GeoAccessor function messes with the vertices and outputs wrong geometry.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Source Data:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AirspaceLinkPipeline_0-1632154476013.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/23394iA5A84968F4945684/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AirspaceLinkPipeline_0-1632154476013.png" alt="AirspaceLinkPipeline_0-1632154476013.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Polygon after adding to ArcGIS online using the script below:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AirspaceLinkPipeline_1-1632154578695.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/23395iE20D4EECD143955C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AirspaceLinkPipeline_1-1632154578695.png" alt="AirspaceLinkPipeline_1-1632154578695.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Not sure how visible it is on the screenshots here, but it seems like the 2 inner holes of this big polygon get all mesed up when converting the geodataframe to a sedf.&lt;/P&gt;&lt;P&gt;This is my script:&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;import geopandas as gpd
from arcgis import GIS
import requests
from arcgis.features import GeoAccessor


gis=GIS("https://arcgis.com",username, password)

base_url = 'https://services1.arcgis.com/Hp6G80Pky0om7QvQ/arcgis/rest/services/DoD_Sites_Boundaries_Public/FeatureServer/0/query'

payload = {
'f': 'geojson',
'where': "SITE_NAME='Eglin Air Force Base'",
'outSR': 4326,
'outFields': '*'
}
response = requests.get(base_url, params=payload)

gdf=gpd.GeoDataFrame.from_features(response.json()['features'], crs="epsg:4326")

sedf=GeoAccessor.from_geodataframe(gdf, column_name="geometry")

lyr = sedf.spatial.to_featurelayer('test_poly')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have fiddled with this for hours. I tried the&amp;nbsp;&lt;STRONG&gt;.buffer(0) &lt;/STRONG&gt;method - didn't work. I tried the &lt;STRONG&gt;make_valid()&lt;/STRONG&gt; function from shapely.validation too. Filling holes before converting to a spatially enabled dataframe worked, but it is not an acceptable solution.&amp;nbsp;&lt;BR /&gt;Any ideas? I have thought the vertices ordering might be to blame, since ESRI uses different clockwise/counterclockwise direction for exterior/interior rings, but I don't know how I would go about to change those.&lt;BR /&gt;Or maybe there is a way to bypass GeoAccessor altogether when trying to publish / append to a feature layer?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Sep 2021 17:59:30 GMT</pubDate>
    <dc:creator>ASLPipeline</dc:creator>
    <dc:date>2021-09-20T17:59:30Z</dc:date>
    <item>
      <title>Converting geodataframe to spatially enabled dataframe messes the polygon geometry</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1099998#M6667</link>
      <description>&lt;P&gt;I use a script to get data into our ArcGIS online organization, but it seems like the GeoAccessor function messes with the vertices and outputs wrong geometry.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Source Data:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AirspaceLinkPipeline_0-1632154476013.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/23394iA5A84968F4945684/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AirspaceLinkPipeline_0-1632154476013.png" alt="AirspaceLinkPipeline_0-1632154476013.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Polygon after adding to ArcGIS online using the script below:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AirspaceLinkPipeline_1-1632154578695.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/23395iE20D4EECD143955C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AirspaceLinkPipeline_1-1632154578695.png" alt="AirspaceLinkPipeline_1-1632154578695.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Not sure how visible it is on the screenshots here, but it seems like the 2 inner holes of this big polygon get all mesed up when converting the geodataframe to a sedf.&lt;/P&gt;&lt;P&gt;This is my script:&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;import geopandas as gpd
from arcgis import GIS
import requests
from arcgis.features import GeoAccessor


gis=GIS("https://arcgis.com",username, password)

base_url = 'https://services1.arcgis.com/Hp6G80Pky0om7QvQ/arcgis/rest/services/DoD_Sites_Boundaries_Public/FeatureServer/0/query'

payload = {
'f': 'geojson',
'where': "SITE_NAME='Eglin Air Force Base'",
'outSR': 4326,
'outFields': '*'
}
response = requests.get(base_url, params=payload)

gdf=gpd.GeoDataFrame.from_features(response.json()['features'], crs="epsg:4326")

sedf=GeoAccessor.from_geodataframe(gdf, column_name="geometry")

lyr = sedf.spatial.to_featurelayer('test_poly')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have fiddled with this for hours. I tried the&amp;nbsp;&lt;STRONG&gt;.buffer(0) &lt;/STRONG&gt;method - didn't work. I tried the &lt;STRONG&gt;make_valid()&lt;/STRONG&gt; function from shapely.validation too. Filling holes before converting to a spatially enabled dataframe worked, but it is not an acceptable solution.&amp;nbsp;&lt;BR /&gt;Any ideas? I have thought the vertices ordering might be to blame, since ESRI uses different clockwise/counterclockwise direction for exterior/interior rings, but I don't know how I would go about to change those.&lt;BR /&gt;Or maybe there is a way to bypass GeoAccessor altogether when trying to publish / append to a feature layer?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 17:59:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1099998#M6667</guid>
      <dc:creator>ASLPipeline</dc:creator>
      <dc:date>2021-09-20T17:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Converting geodataframe to spatially enabled dataframe messes the polygon geometry</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1100091#M6669</link>
      <description>&lt;P&gt;related?&amp;nbsp;&lt;A href="https://github.com/Esri/arcgis-python-api/issues/931" target="_blank"&gt;spatial.from_geodataframe() mangles geometries · Issue #931 · Esri/arcgis-python-api (github.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;you might want to start an "Issue" there to narrow down the possibilities.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 20:32:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1100091#M6669</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-09-20T20:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Converting geodataframe to spatially enabled dataframe messes the polygon geometry</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1100196#M6673</link>
      <description>&lt;P&gt;Have you tried repairing the geometry first?&amp;nbsp; Admittedly I mix the API with ArcPy, but to dissolve groups of polygons I had to run&amp;nbsp;arcpy.management.RepairGeometry (used OGC validation) first.&lt;BR /&gt;So I had sqlite - gdf - sedf - fc - repair geoms - dissolve.&amp;nbsp; Maybe not 100% related, but sometimes shifting formats/APIs can bypass the problem.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 07:22:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1100196#M6673</guid>
      <dc:creator>Webturtles</dc:creator>
      <dc:date>2021-09-21T07:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: Converting geodataframe to spatially enabled dataframe messes the polygon geometry</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1100271#M6675</link>
      <description>&lt;P&gt;I tried to repair geometries using shapely functions, thing is, by the time I would be able to use arcpy repair - the geometries are already mangled. But yes, that is my thought too.. I need to get there using different formats/APIs, I am trying to add the data to a regular dataframe&amp;nbsp; instead of geodataframe at the moment, but that gives me some other errors.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 13:35:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1100271#M6675</guid>
      <dc:creator>ASLPipeline</dc:creator>
      <dc:date>2021-09-21T13:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: Converting geodataframe to spatially enabled dataframe messes the polygon geometry</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1100277#M6676</link>
      <description>&lt;P&gt;Looking more at this, I am pretty sure it's a bug.. Thanks for sending that link!&amp;nbsp;I don't even know if I should be glad or cry, these probably take a while to get solved.&amp;nbsp;&lt;BR /&gt;Do you know of any other way to publish a geodataframe as a feature layer?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 13:40:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1100277#M6676</guid>
      <dc:creator>ASLPipeline</dc:creator>
      <dc:date>2021-09-21T13:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Converting geodataframe to spatially enabled dataframe messes the polygon geometry</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1113189#M6777</link>
      <description>&lt;P&gt;While my Issue on the Esri's Github is still "under consideration" (&lt;A title="Github issue" href="https://github.com/Esri/arcgis-python-api/issues/1096" target="_blank" rel="noopener"&gt;link here&lt;/A&gt;), I have found a workaround that does the job for us. Basically I bypass GeoAccessor.from_geodataframe() function altogether and append the data to an existing feature layer using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Target_Layer = gis.content.get('{}'.format(layerid))
json_gdf=gdf.to_json()
insights_dict=json.loads(json_gdf)

# create FeatureSet from json dict and append data to the target layer
fset=FeatureSet.from_geojson(insights_dict)
for feature in fset:
    add_result = Target_Layer.layers[0].edit_features(adds=[feature])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 14:07:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1113189#M6777</guid>
      <dc:creator>ASLPipeline</dc:creator>
      <dc:date>2021-11-02T14:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Converting geodataframe to spatially enabled dataframe messes the polygon geometry</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1113492#M6782</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/473693"&gt;@ASLPipeline&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;There is also a simpler way of implementing this process. You don't need to use neither Geopandas nor GeoAccessor:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer

gis=GIS("https://arcgis.com",username, password)
Target_Layer = gis.content.get('{}'.format(layerid))

flyr = FeatureLayer("https://services1.arcgis.com/Hp6G80Pky0om7QvQ/arcgis/rest/services/DoD_Sites_Boundaries_Public/FeatureServer/0", gis=gis)
features = flyr.query(where="SITE_NAME='Eglin Air Force Base'")
for feature in features:
    add_result = Target_Layer.layers[0].edit_features(adds=[feature])&lt;/LI-CODE&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Mehdi&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 02:43:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1113492#M6782</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2021-11-03T02:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: Converting geodataframe to spatially enabled dataframe messes the polygon geometry</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1145591#M7136</link>
      <description>&lt;P&gt;Thank you for sharing this. In reality, my code was much more complicated than the snippet I posted here, and I needed to process large amounts of data, not just copy them from one source to another. The query only works for 2k features and I wasn't able to find a way to buffer a FeatureSet, so I had to use a Geodataframe.. but that's already off topic.&lt;BR /&gt;&lt;BR /&gt;In the meantime, I received an email from the developers that the GeoAccessor bug was fixed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 14:34:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/converting-geodataframe-to-spatially-enabled/m-p/1145591#M7136</guid>
      <dc:creator>ASLPipeline</dc:creator>
      <dc:date>2022-02-18T14:34:56Z</dc:date>
    </item>
  </channel>
</rss>

