<?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: How to convert a spatially enabled dataframe(sdf) to a gdf in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560310#M10893</link>
    <description>&lt;P&gt;Going straight from the Feature Service to the gdf using requests would work. I get a data source error when trying it this way though. Do I need to consider authentication?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;DataSourceError                           Traceback (most recent call last)
Cell In[3], line 13
      4 layer_params = {
      5   "where" : "1=1",
      6   "f" : "geojson"
      7 }
      9 layer_req = requests.post(
     10   'https://zklxc2usnyaidrpe.maps.arcgis.com/home/item.html?id=21638fcd54d14a25b6f1affdef812146',
     11   layer_params
     12 )
---&amp;gt; 13 gdf = gpd.read_file(layer_req.text)
     14 gdf

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\geopandas\io\file.py:294, in _read_file(filename, bbox, mask, columns, rows, engine, **kwargs)
    291             from_bytes = True
    293 if engine == "pyogrio":
--&amp;gt; 294     return _read_file_pyogrio(
    295         filename, bbox=bbox, mask=mask, columns=columns, rows=rows, **kwargs
    296     )
    298 elif engine == "fiona":
    299     if pd.api.types.is_file_like(filename):

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\geopandas\io\file.py:547, in _read_file_pyogrio(path_or_bytes, bbox, mask, rows, **kwargs)
    538     warnings.warn(
...
File pyogrio\\_io.pyx:1240, in pyogrio._io.ogr_read()

File pyogrio\\_io.pyx:220, in pyogrio._io.ogr_open()

DataSourceError: 'DOCTYPE html&amp;gt;&amp;lt;html&amp;gt;  &amp;lt;head&amp;gt;    &amp;lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&amp;gt;    &amp;lt;meta name="viewport" content="width=device-width" /&amp;gt;    &amp;lt;link rel="stylesheet" href="https://cdn-a.arcgis.com/cdn/1B87370/js/calcite-web/dist/css/calcite-web-no-fonts.min.css" /&amp;gt;    &amp;lt;link rel="stylesheet" type="text/css" href="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgis-components/dist/ItemBrowser/index.css" /&amp;gt;    &amp;lt;link rel="stylesheet" type="text/css" href="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgis-components/dist/Share/index.css" /&amp;gt;    &amp;lt;link rel="stylesheet" type="text/css" href="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgis-components/dist/GroupBrowser/index.css" /&amp;gt;    &amp;lt;link rel="stylesheet" href="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgisonline/css/app.css" /&amp;gt;    &amp;lt;link rel="stylesheet" type="text/css" href="https://cdn-a.arcgis.com/cdn/1B87370/js/calcite-components/calcite/calcite.css"&amp;gt;    &amp;lt;link rel="stylesheet" type="text/css" href="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgis-app-components/arcgis-app/arcgis-app.css"&amp;gt;    &amp;lt;link rel="stylesheet" href="https://cdn-a.arcgis.com/cdn/1B87370/js/jsapi/dojox/highlight/resources/highlight.css"&amp;gt;    &amp;lt;link rel="stylesheet" href="https://cdn-a.arcgis.com/cdn/1B87370/js/jsapi/dojox/highlight/resources/pygments/friendly.css" /&amp;gt;  &amp;lt;/head&amp;gt;  &amp;lt;body spellcheck="false"&amp;gt;    &amp;lt;div class="loader is-active padding-leader-5 padding-trailer-5 js-page-loader"&amp;gt;      &amp;lt;div class="loader-bars"&amp;gt;&amp;lt;/div&amp;gt;      &amp;lt;div class="loader-text"&amp;gt;&amp;lt;/div&amp;gt;    &amp;lt;/div&amp;gt;    &amp;lt;script type="text/javascript" src="./js/arcgisonline/config.js"&amp;gt;&amp;lt;/script&amp;gt;    &amp;lt;script src="https://cdn-a.arcgis.com/cdn/1B87370/js/jsapi/dojo/dojo.js"&amp;gt;&amp;lt;/script&amp;gt;    &amp;lt;script type="module" src="https://cdn-a.arcgis.com/cdn/1B87370/js/calcite-components/calcite/calcite.esm.js"&amp;gt;&amp;lt;/script&amp;gt;    &amp;lt;script nomodule="" src="https://cdn-a.arcgis.com/cdn/1B87370/js/calcite-components/calcite/calcite.js"&amp;gt;&amp;lt;/script&amp;gt;    &amp;lt;script type="module" src="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgis-app-components/arcgis-app/arcgis-app.esm.js"&amp;gt;&amp;lt;/script&amp;gt;    &amp;lt;script&amp;gt;      require(window.dojoConfig, ["arcgisonline/main"]);    &amp;lt;/script&amp;gt;  &amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;' does not exist in the file system, and is not recognized as a supported dataset name. &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Nov 2024 16:42:46 GMT</pubDate>
    <dc:creator>ZacharyKasson</dc:creator>
    <dc:date>2024-11-19T16:42:46Z</dc:date>
    <item>
      <title>How to convert a spatially enabled dataframe(sdf) to a gdf</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560006#M10889</link>
      <description>&lt;P&gt;python: 3.9&lt;/P&gt;&lt;P&gt;arcgis: 2.3.0.1&lt;/P&gt;&lt;P data-unlink="true"&gt;I am accessing a Feature Layer from the Living Atlas. I convert it to a sdf with the column 'SHAPE' as the geometry. How do I add the sdf to a leafmap map. I have added other layers to the map via add_gdf(). Can I convert the sdf to a gdf? or a geojson which i could then create a gdf from. I found &lt;A href="https://gis.stackexchange.com/questions/418040/converting-arcgis-spatially-enabled-dataframe-to-geojson" target="_blank" rel="noopener"&gt;this&lt;/A&gt; but need to create the geojson as a variable instead of a local file.&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;SPAN&gt;Here is some of the code I am using:&lt;/SPAN&gt;&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.gis import GIS
from arcgis import gis, GeoAccessor, geometry
gis = GIS()

def read_fl(item_id):
    living_atlas_item = gis.content.get(item_id)
    feature_layer = living_atlas_item.layers[0]
    sdf = feature_layer.query(where="1=1", out_sr=4326).sdf
    return sdf

item_id = "21638fcd54d14a25b6f1affdef812146"
sdf = read_fl(item_id)

# Transform sdf to gdf somehow

# Create map
map = leafmap.Map(
    layers_control=True,
    draw_control=False,
    measure_control=False,
    fullscreen_control=False)

map.add_basemap(basemap_selection)
map.add_gdf(
    gdf=sdf,
    zoom_to_layer=False,
    layer_name='Fires',
    info_mode='on_click',
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 23:50:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560006#M10889</guid>
      <dc:creator>ZacharyKasson</dc:creator>
      <dc:date>2024-11-18T23:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a spatially enabled dataframe(sdf) to a gdf</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560226#M10890</link>
      <description>&lt;P&gt;That method assumes you have GeoPandas. While you *can* get your sdf into a GeoDataFrame, there's not a built-in method for it.&lt;/P&gt;&lt;P&gt;It is possible to use &lt;STRONG&gt;requests&lt;/STRONG&gt; to query a Feature Service, and for GeoPandas to parse the response.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import geopandas as gp
import requests

layer_params = {
  "where" : "1=1",
  "f" : "geojson"
}

layer_req = requests.post(
  'URL to the feature service',
  layer_params
)

gdf = gp.read_file(layer_req.text)

# then do the rest of it&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 15:03:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560226#M10890</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-11-19T15:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a spatially enabled dataframe(sdf) to a gdf</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560310#M10893</link>
      <description>&lt;P&gt;Going straight from the Feature Service to the gdf using requests would work. I get a data source error when trying it this way though. Do I need to consider authentication?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;DataSourceError                           Traceback (most recent call last)
Cell In[3], line 13
      4 layer_params = {
      5   "where" : "1=1",
      6   "f" : "geojson"
      7 }
      9 layer_req = requests.post(
     10   'https://zklxc2usnyaidrpe.maps.arcgis.com/home/item.html?id=21638fcd54d14a25b6f1affdef812146',
     11   layer_params
     12 )
---&amp;gt; 13 gdf = gpd.read_file(layer_req.text)
     14 gdf

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\geopandas\io\file.py:294, in _read_file(filename, bbox, mask, columns, rows, engine, **kwargs)
    291             from_bytes = True
    293 if engine == "pyogrio":
--&amp;gt; 294     return _read_file_pyogrio(
    295         filename, bbox=bbox, mask=mask, columns=columns, rows=rows, **kwargs
    296     )
    298 elif engine == "fiona":
    299     if pd.api.types.is_file_like(filename):

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\geopandas\io\file.py:547, in _read_file_pyogrio(path_or_bytes, bbox, mask, rows, **kwargs)
    538     warnings.warn(
...
File pyogrio\\_io.pyx:1240, in pyogrio._io.ogr_read()

File pyogrio\\_io.pyx:220, in pyogrio._io.ogr_open()

DataSourceError: 'DOCTYPE html&amp;gt;&amp;lt;html&amp;gt;  &amp;lt;head&amp;gt;    &amp;lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&amp;gt;    &amp;lt;meta name="viewport" content="width=device-width" /&amp;gt;    &amp;lt;link rel="stylesheet" href="https://cdn-a.arcgis.com/cdn/1B87370/js/calcite-web/dist/css/calcite-web-no-fonts.min.css" /&amp;gt;    &amp;lt;link rel="stylesheet" type="text/css" href="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgis-components/dist/ItemBrowser/index.css" /&amp;gt;    &amp;lt;link rel="stylesheet" type="text/css" href="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgis-components/dist/Share/index.css" /&amp;gt;    &amp;lt;link rel="stylesheet" type="text/css" href="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgis-components/dist/GroupBrowser/index.css" /&amp;gt;    &amp;lt;link rel="stylesheet" href="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgisonline/css/app.css" /&amp;gt;    &amp;lt;link rel="stylesheet" type="text/css" href="https://cdn-a.arcgis.com/cdn/1B87370/js/calcite-components/calcite/calcite.css"&amp;gt;    &amp;lt;link rel="stylesheet" type="text/css" href="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgis-app-components/arcgis-app/arcgis-app.css"&amp;gt;    &amp;lt;link rel="stylesheet" href="https://cdn-a.arcgis.com/cdn/1B87370/js/jsapi/dojox/highlight/resources/highlight.css"&amp;gt;    &amp;lt;link rel="stylesheet" href="https://cdn-a.arcgis.com/cdn/1B87370/js/jsapi/dojox/highlight/resources/pygments/friendly.css" /&amp;gt;  &amp;lt;/head&amp;gt;  &amp;lt;body spellcheck="false"&amp;gt;    &amp;lt;div class="loader is-active padding-leader-5 padding-trailer-5 js-page-loader"&amp;gt;      &amp;lt;div class="loader-bars"&amp;gt;&amp;lt;/div&amp;gt;      &amp;lt;div class="loader-text"&amp;gt;&amp;lt;/div&amp;gt;    &amp;lt;/div&amp;gt;    &amp;lt;script type="text/javascript" src="./js/arcgisonline/config.js"&amp;gt;&amp;lt;/script&amp;gt;    &amp;lt;script src="https://cdn-a.arcgis.com/cdn/1B87370/js/jsapi/dojo/dojo.js"&amp;gt;&amp;lt;/script&amp;gt;    &amp;lt;script type="module" src="https://cdn-a.arcgis.com/cdn/1B87370/js/calcite-components/calcite/calcite.esm.js"&amp;gt;&amp;lt;/script&amp;gt;    &amp;lt;script nomodule="" src="https://cdn-a.arcgis.com/cdn/1B87370/js/calcite-components/calcite/calcite.js"&amp;gt;&amp;lt;/script&amp;gt;    &amp;lt;script type="module" src="https://cdn-a.arcgis.com/cdn/1B87370/js/arcgis-app-components/arcgis-app/arcgis-app.esm.js"&amp;gt;&amp;lt;/script&amp;gt;    &amp;lt;script&amp;gt;      require(window.dojoConfig, ["arcgisonline/main"]);    &amp;lt;/script&amp;gt;  &amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;' does not exist in the file system, and is not recognized as a supported dataset name. &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 16:42:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560310#M10893</guid>
      <dc:creator>ZacharyKasson</dc:creator>
      <dc:date>2024-11-19T16:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a spatially enabled dataframe(sdf) to a gdf</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560332#M10894</link>
      <description>&lt;P&gt;I think the quickest way to get what you need is to just use geojson. I'm not sure if leafmap takes a geojson string, or dict but this should give you geojson string:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def read_fl(item_id):
    living_atlas_item = gis.content.get(item_id)
    feature_layer = living_atlas_item.layers[0]
    fs = feature_layer.query(where="1=1", out_sr=4326)
    return fs.to_geojson
    &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it requires a dict, then modify to this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import json
def read_fl(item_id):
    living_atlas_item = gis.content.get(item_id)
    feature_layer = living_atlas_item.layers[0]
    fs = feature_layer.query(where="1=1", out_sr=4326)
    geojson_string = fs.to_geojson
    return json.loads(geojson_string)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Per leafmap documentation, you should not have to create a gdf for this to work:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;m = leafmap.Map(center=[0, 0], zoom=2)

in_geojson = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/cable_geo.geojson"
m.add_geojson(in_geojson, layer_name="Cable lines")&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 17:09:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560332#M10894</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2024-11-19T17:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a spatially enabled dataframe(sdf) to a gdf</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560387#M10895</link>
      <description>&lt;P&gt;I found it to be simple than I thought.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;gdf = gpd.GeoDataFrame(sdf, geometry='SHAPE')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 18:20:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560387#M10895</guid>
      <dc:creator>ZacharyKasson</dc:creator>
      <dc:date>2024-11-19T18:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a spatially enabled dataframe(sdf) to a gdf</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560388#M10896</link>
      <description>&lt;P&gt;I appreciate the responses. It seems there is a direct route from sdf to gdf. I accepted it as a solution.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 18:21:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-spatially-enabled-dataframe-sdf/m-p/1560388#M10896</guid>
      <dc:creator>ZacharyKasson</dc:creator>
      <dc:date>2024-11-19T18:21:26Z</dc:date>
    </item>
  </channel>
</rss>

