<?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: Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1160507#M7273</link>
    <description>&lt;P&gt;I tried implementing your code to convert the pandas dataframe to a spatially enabled dataframe. It looks like it almost works, in that, it automatically zoomed into the correct location where the points should be. However, the points are not actually appearing on the map. I've included the implemented code in the top cell, the output, as well as an example of the SEDF that I am trying to plot with the SHAPE column featured in the bottom cell. Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iintrater_0-1648861601803.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/38023i3D96A8BD4430BA2A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iintrater_0-1648861601803.png" alt="iintrater_0-1648861601803.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 02 Apr 2022 01:09:21 GMT</pubDate>
    <dc:creator>iintrater</dc:creator>
    <dc:date>2022-04-02T01:09:21Z</dc:date>
    <item>
      <title>Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038187#M5754</link>
      <description>&lt;P&gt;I have a pandas dataframe with latitude and longitude columns. I would like to convert it ultimately to a feature class. In the conversion to a spatial data frame, I do the following.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sdf = arcgis.features.GeoAccessor.from_xy(dff, x_column='longitude', y_column='latitude', sr=4326)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used this tutorial as a guide&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/guide/part2-working-with-geometries/#Create-an-SeDF-object-with-geometries" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/python/guide/part2-working-with-geometries/#Create-an-SeDF-object-with-geometries&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and keep getting this exception message&lt;/P&gt;&lt;P&gt;raise Exception("Spatial column not defined, please use `set_geometry`")&lt;/P&gt;&lt;P&gt;Exception: Spatial column not defined, please use `set_geometry`&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 17:59:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038187#M5754</guid>
      <dc:creator>MichaelWallace3</dc:creator>
      <dc:date>2021-03-18T17:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038205#M5755</link>
      <description>&lt;P&gt;I don't see a reason why this wouldn't work, given your code.&lt;/P&gt;&lt;P&gt;Can you check &lt;STRONG&gt;dff.dtypes&lt;/STRONG&gt;? I would guess that the problem may lie with the input dataframe.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 18:23:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038205#M5755</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-03-18T18:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038261#M5756</link>
      <description>&lt;P&gt;You can try to use &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.GeoAccessor.set_geometry" target="_self"&gt;GeoAccessor.set_geometry&lt;/A&gt; function to set the column(s) that contain the geometry.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf = sdf.set_geometry(['longitude', 'latitude'])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;You can set the parameter "inplace = True". This will change the DF without returning a copy of it.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 19:56:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038261#M5756</guid>
      <dc:creator>MarkKinnaman</dc:creator>
      <dc:date>2021-03-18T19:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038314#M5757</link>
      <description>&lt;P&gt;here are the dtypes for longitude and latitude&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;longitude float64&lt;BR /&gt;latitude float64&lt;/P&gt;&lt;P&gt;The rest of the columns are listed as object.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 21:28:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038314#M5757</guid>
      <dc:creator>MichaelWallace3</dc:creator>
      <dc:date>2021-03-18T21:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038328#M5758</link>
      <description>&lt;P&gt;Thanks Mark for the Quick response I receive the following messages when I try the above code&lt;/P&gt;&lt;P&gt;ValueError: Can't do inplace setting when converting from DataFrame to SpatialDataFrame&lt;/P&gt;&lt;P&gt;if I point at another dataframe&lt;/P&gt;&lt;P&gt;TypeError: Input geometry column must contain valid geometry objects.&lt;/P&gt;&lt;P&gt;I guess I can go back to the tutorial and see what I am missing. Any further suggestions are greatly appreciated!&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 21:37:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038328#M5758</guid>
      <dc:creator>MichaelWallace3</dc:creator>
      <dc:date>2021-03-18T21:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038382#M5759</link>
      <description>&lt;P&gt;Here we go.&lt;/P&gt;&lt;H4&gt;The Standard Method&lt;/H4&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.features import GeoAccessor
import pandas as pd
from numpy.random import rand

lats = rand(5) * 45 + 30
lons = rand(5) * 45 + 30

df = pd.DataFrame({'lat':lats, 'lon':lons})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's df:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;|   |       lat |       lon |
|--:|----------:|----------:|
| 0 | 66.212195 | 42.930500 |
| 1 | 58.392814 | 74.032695 |
| 2 | 44.315964 | 32.602737 |
| 3 | 69.484491 | 58.170186 |
| 4 | 33.592844 | 62.363671 |&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the standard &lt;STRONG&gt;from_xy&lt;/STRONG&gt; seems to work as intended.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;GeoAccessor.from_xy(df, 'lon', 'lat').spatial.plot()&lt;/LI-CODE&gt;&lt;P&gt;Results in:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1616104497694.png" style="width: 200px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8849i97EE231BB37CEBCC/image-size/small?v=v2&amp;amp;px=200" role="button" title="jcarlson_0-1616104497694.png" alt="jcarlson_0-1616104497694.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This even works when the lat/lon values are null or clearly invalid ( &amp;gt; 180 ), it still "works", it just doesn't render correctly on the map.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H4&gt;Let's Pretend that &lt;EM&gt;Didn't&lt;/EM&gt; Work: Alternate Method&lt;/H4&gt;&lt;P&gt;I &lt;EM&gt;have &lt;/EM&gt;had it happen where the normal conversion process just wouldn't work. To work around that, we'll wrangle the lat/lon values into a string of the same format that the SEDF uses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df['SHAPE'] = '"spatialReference": {"wkid": 4326}, {"x":' + df['lon'].astype('str') + ', "y":' + df['lat'].astype('str') + '}'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This results in a new column 'SHAPE' with values like this:&lt;/P&gt;&lt;PRE&gt;'{"spatialReference": {"wkid": 4326}, "x": 67.91584605411032, "y": 34.142203783078585 }&lt;/PRE&gt;&lt;P&gt;Which you may recognize as the JSON text of point geometries, seen in SEDFs. Let's now try to assign this as the geometry column.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf = GeoAccessor.from_df(df, geometry_column='SHAPE')
sdf.spatial.plot()&lt;/LI-CODE&gt;&lt;P&gt;Which results in (different iteration of script, so my random values have shifted):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1616109896555.png" style="width: 200px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8857iEF11C0288E7CF623/image-size/small?v=v2&amp;amp;px=200" role="button" title="jcarlson_0-1616109896555.png" alt="jcarlson_0-1616109896555.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Give this alternate method a shot. If &lt;EM&gt;that&lt;/EM&gt; doesn't work, you may be in a pickle. Or you may need to take a harder look at the input data.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 23:26:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038382#M5759</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-03-18T23:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038405#M5761</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/282068"&gt;@MichaelWallace3&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's working for me too.&lt;/P&gt;&lt;P&gt;You may need to test another dataset and may also consider upgrading ArcGIS API for Python.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 00:57:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038405#M5761</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2021-03-19T00:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038409#M5762</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/282068"&gt;@MichaelWallace3&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;umm... It should work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be helpful for the diagnosis if we can see a snapshot of the DataFrame an exact code that is doing the conversion.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Btw, which version of ArcGIS API for Python are you using?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 01:48:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1038409#M5762</guid>
      <dc:creator>simoxu</dc:creator>
      <dc:date>2021-03-19T01:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1042220#M5853</link>
      <description>&lt;P&gt;Wow thank you this worked perfectly!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 22:37:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1042220#M5853</guid>
      <dc:creator>MichaelWallace3</dc:creator>
      <dc:date>2021-03-30T22:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Spatial Enabled Dataframe from pandas dataframe with Latitude and Longitude coordinates?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1160507#M7273</link>
      <description>&lt;P&gt;I tried implementing your code to convert the pandas dataframe to a spatially enabled dataframe. It looks like it almost works, in that, it automatically zoomed into the correct location where the points should be. However, the points are not actually appearing on the map. I've included the implemented code in the top cell, the output, as well as an example of the SEDF that I am trying to plot with the SHAPE column featured in the bottom cell. Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iintrater_0-1648861601803.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/38023i3D96A8BD4430BA2A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iintrater_0-1648861601803.png" alt="iintrater_0-1648861601803.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2022 01:09:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/creating-spatial-enabled-dataframe-from-pandas/m-p/1160507#M7273</guid>
      <dc:creator>iintrater</dc:creator>
      <dc:date>2022-04-02T01:09:21Z</dc:date>
    </item>
  </channel>
</rss>

