<?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: ArcGIS Python API Set Geometry Column of Spatially Enabled Data Frame in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858980#M4136</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After trying the geojson solution, I am falling back to using shapely and the from_shapely custom method which I took from Joel McCune.&amp;nbsp; The geojson route ended up also being slow and having lots of geometry errors anyway, so I would need to do some geometry updates either way, so sticking with the "hack".&amp;nbsp; I have posted an&lt;A _jive_internal="true" href="https://community.esri.com/ideas/15743-arcgis-python-api-spatialdataframe-loads-for-wkt-geometry"&gt; idea in ESRI Ideas&lt;/A&gt; to encourage a loads method similar to the one I am using from shapely. Thanks to Per for above recommendations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Nov 2018 16:50:45 GMT</pubDate>
    <dc:creator>NathanielEvatt</dc:creator>
    <dc:date>2018-11-02T16:50:45Z</dc:date>
    <item>
      <title>ArcGIS Python API Set Geometry Column of Spatially Enabled Data Frame</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858974#M4130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to&lt;/P&gt;&lt;P&gt;1. connect to a PostGIS database&lt;/P&gt;&lt;P&gt;2. Create a Spatially Enabled Data Frame&lt;/P&gt;&lt;P&gt;3. Export out to a feature layer&lt;/P&gt;&lt;P&gt;4. Push to AGOL.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of those steps, I have succeeded at number one, but I am getting a error in the process of setting a geometry column in the DataFrame.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the function `set_geomerty()` does not like the format of the data that i am putting in, which has been text and shapely format.&amp;nbsp; Is there an ESRI specific format that i should be using or a function that can put the geometry into that format?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IDE: Jupyter Notebook&lt;/P&gt;&lt;P&gt;python: 3.6&lt;/P&gt;&lt;P&gt;ArcGIS Python Api: 1.5.0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;import pandas as pd&lt;BR /&gt;from shapely.wkt import loads&lt;/P&gt;&lt;P&gt;conn = config.conn&lt;BR /&gt;df = pd.read_sql("select id, ST_AsText(geom) AS geometry from table where group_id = 63 limit 1", con=conn)&lt;BR /&gt;df['geometry'] = df['geometry'].apply(lambda x: loads(x))&lt;BR /&gt;sdf = df.set_geometry('geometry')&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;bmp_id geometry&lt;BR /&gt;0 Lot_5_78 POINT (-121.799248349 36.6987788232)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;~/.virtualenv/esri/lib/python3.6/site-packages/arcgis/features/_data/geodataset/geodataframe.py in set_geometry(self, col, drop, inplace, sr)&lt;BR /&gt; 1799 # Check that we are using a listlike of geometries&lt;BR /&gt; 1800 if not all(isinstance(item, GEOM_TYPES) or not item for item in level):&lt;BR /&gt;-&amp;gt; 1801 raise TypeError("Input geometry column must contain valid geometry objects.")&lt;BR /&gt; 1802 #if isinstance(frame[geo_column_name], pd.Series):&lt;BR /&gt; 1803 # frame[geo_column_name] = GeoSeries(frame[geo_column_name])&lt;/P&gt;&lt;P&gt;TypeError: Input geometry column must contain valid geometry objects.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Gracias&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Oct 2018 16:10:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858974#M4130</guid>
      <dc:creator>NathanielEvatt</dc:creator>
      <dc:date>2018-10-26T16:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Python API Set Geometry Column of Spatially Enabled Data Frame</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858975#M4131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Update:&amp;nbsp; I have been able to find a work around by following the post by Joel McCune&amp;nbsp;&lt;A href="https://joelmccune.com/arcgis-python-geometry-from-shapely/"&gt;here&lt;/A&gt;&amp;nbsp;, by first converting the PostGIS text as shapely, then converting the shapely geometry as ArcGIS geometry format, which is pretty hacky.&amp;nbsp; I am sure there is a function that convert PostGIS text / json outputs into ArcGIS geometry.&amp;nbsp; Any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also weird, after running the conversion the correct geometry format, I can run set_geometry on the geom column, publish a feature_layer to AGOL, but I cannot plot on a map within Jupyter Notebook.&amp;nbsp; I get the&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;: Spatial column not defined, please use `set_geometry`&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Even though I have run the method 2 lines above.&amp;nbsp;&amp;nbsp;¯\_(ツ)_/¯&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Full code here:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;from shapely.wkt import loads&lt;BR /&gt;from arcgis.geometry import Geometry&lt;BR /&gt;from arcgis.geometry import BaseGeometry&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@classmethod&lt;BR /&gt;def from_shapely(cls, shapely_geometry):&lt;BR /&gt; return cls(shapely_geometry.__geo_interface__)&lt;/P&gt;&lt;P&gt;BaseGeometry.from_shapely = from_shapely&lt;/P&gt;&lt;P&gt;conn = config.conn&lt;BR /&gt;df = pd.read_sql("select id, ST_AsText(geom) AS geometry from ch01.sweet_table where group_id = 1", con=conn)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;df['geometry'] = df['geometry'].apply(lambda x: loads(x))&lt;BR /&gt;df['geometry'] = df['geometry'].apply(lambda x: Geometry.from_shapely(x))&lt;BR /&gt;Geometry(df.iloc[0].geometry).is_valid&lt;BR /&gt;sdf = df.set_geometry('geometry')&lt;/P&gt;&lt;P&gt;Geometry(sdf.iloc[0].geometry).is_valid #test geometry is valid&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;sdf.spatial.plot(map_widget=m) #plotting error&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;new_lyr_item = sdf.spatial.to_featurelayer('Tester Pester')&lt;BR /&gt;published_item = new_lyr_item.publish()&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2018 16:18:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858975#M4131</guid>
      <dc:creator>NathanielEvatt</dc:creator>
      <dc:date>2018-10-29T16:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Python API Set Geometry Column of Spatially Enabled Data Frame</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858976#M4132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about doing something like this instead…&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import pandas as pd&lt;BR /&gt;from arcgis.features import GeoAccessor, GeoSeriesAccessor&lt;/P&gt;&lt;P&gt;conn = config.conn&lt;BR /&gt;sql = “””&lt;BR /&gt;SELECT &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;id, &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ST_X(geom) AS X, &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ST_Y(geom) AS Y &lt;BR /&gt;FROM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ch01.sweet_table &lt;BR /&gt;WHERE&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;group_id = 1”””&lt;BR /&gt;df = pd.read_sqlsql, conn)&lt;BR /&gt;sdf = pd.DataFrame.spatial.from_xy(df, 'X', 'Y', sr=4326)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At this point you should have a functioning spatial dataframe without using&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Oct 2018 19:03:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858976#M4132</guid>
      <dc:creator>Per_Åke_MattiasWallin</dc:creator>
      <dc:date>2018-10-30T19:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Python API Set Geometry Column of Spatially Enabled Data Frame</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858977#M4133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Per,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, that would work if I were using points, which I know is what I used in the example.&amp;nbsp; However, the meat and potatoes of the data that i am dealing with is polygon.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I basically need something like the from_xy function for polygons, multipolygons and lines as well.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2018 00:10:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858977#M4133</guid>
      <dc:creator>NathanielEvatt</dc:creator>
      <dc:date>2018-10-31T00:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Python API Set Geometry Column of Spatially Enabled Data Frame</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858978#M4134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It’s definitely easier with points- even using polygons imported from a featureclass is painfully slow if the data is large.&amp;nbsp; What if you convert your data to geojson using something like ogr2ogr?&amp;nbsp; Then something like this will work:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="snapshot of notebook" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/426783_geojson.PNG" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2018 15:59:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858978#M4134</guid>
      <dc:creator>Per_Åke_MattiasWallin</dc:creator>
      <dc:date>2018-10-31T15:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Python API Set Geometry Column of Spatially Enabled Data Frame</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858979#M4135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah, I this is the best solution.&amp;nbsp; It is unfortunate that there does not seem to be a solution where geometries can be created in ESRI format using the spatial data frame only, but this is a fast solution, once you have the geojson.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Nat&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2018 17:10:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858979#M4135</guid>
      <dc:creator>NathanielEvatt</dc:creator>
      <dc:date>2018-11-01T17:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Python API Set Geometry Column of Spatially Enabled Data Frame</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858980#M4136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After trying the geojson solution, I am falling back to using shapely and the from_shapely custom method which I took from Joel McCune.&amp;nbsp; The geojson route ended up also being slow and having lots of geometry errors anyway, so I would need to do some geometry updates either way, so sticking with the "hack".&amp;nbsp; I have posted an&lt;A _jive_internal="true" href="https://community.esri.com/ideas/15743-arcgis-python-api-spatialdataframe-loads-for-wkt-geometry"&gt; idea in ESRI Ideas&lt;/A&gt; to encourage a loads method similar to the one I am using from shapely. Thanks to Per for above recommendations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2018 16:50:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/858980#M4136</guid>
      <dc:creator>NathanielEvatt</dc:creator>
      <dc:date>2018-11-02T16:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Python API Set Geometry Column of Spatially Enabled Data Frame</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/1057980#M6063</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;Have you find the solution? I already have a geodataframe created from postgis and I'm tryng to convert from geodataframe to ESRI spatial enabled dataframe, but I'm not able to.&lt;BR /&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 10:11:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcgis-python-api-set-geometry-column-of-spatially/m-p/1057980#M6063</guid>
      <dc:creator>Jose_FranciscoSánchez_Díaz1</dc:creator>
      <dc:date>2021-05-14T10:11:12Z</dc:date>
    </item>
  </channel>
</rss>

