<?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: Read geometry from JSON API response in notebook in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/read-geometry-from-json-api-response-in-notebook/m-p/1262200#M8414</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Using the sample you provided, I was able to parse the JSON correctly into an SEDF like so:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor

parsed_json = [
    {
        **feature["properties"], 
        "geom": {
                    "rings" : feature["geometry"]["coordinates"],
                    "spatialReference" : {"wkid" : 4326}
                }
    } for feature in json["features"]]

df = pd.DataFrame.from_dict(parsed_json)
sedf = pd.DataFrame.spatial.from_df(df, geometry_column="geom")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Feb 2023 22:58:34 GMT</pubDate>
    <dc:creator>EarlMedina</dc:creator>
    <dc:date>2023-02-27T22:58:34Z</dc:date>
    <item>
      <title>Read geometry from JSON API response in notebook</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/read-geometry-from-json-api-response-in-notebook/m-p/1260873#M8391</link>
      <description>&lt;P&gt;I'm trying to create a layer that updates with data from the &lt;A href="https://www.ipcinfo.org/ipc-country-analysis/ipc-mapping-tool/" target="_self"&gt;IPC&lt;/A&gt; api (sample response below).&lt;/P&gt;&lt;P&gt;With GeoPandas, I can successfully load this into a geodataframe in one line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;gpd.GeoDataFrame.from_features(json['features'])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've not been able to get a similar results using the ESRI notebook environment without geopandas.&lt;/P&gt;&lt;P&gt;I can create a data frame that brings through the attribute data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;df = pd.DataFrame()
for feature in json['features']: 
    temp_df = pd.DataFrame.from_dict(data=feature['properties'], orient='index').T
    geom = pd.DataFrame.from_dict(data=feature['geometry'], orient='index').T
    temp_df['geom_type'] = geom.type
    temp_df['geom'] = geom.coordinates    
    df = df.append(temp_df)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if I try to wrap geom.coordinates in arcgis.geometry.Geometry() it gives an error:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;ValueError&lt;/SPAN&gt;: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().&lt;/PRE&gt;&lt;P&gt;Any help on how to correctly parse the JSON response attributes and geometry into something I can publish as a feature layer would be much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sample API response:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;{'type': 'FeatureCollection',
 'features': [{'type': 'Feature',
   'properties': {'id': '24755676',
    'estimated_population': 363930,
    'period': 'C',
    'from': 'Jan 2022',
    'to': 'Jan 2022',
    'color': '#E67800',
    'anl_id': '24755659',
    'title': 'Middle Juba',
    'overall_phase': 3,
    'country': 'SO',
    'year': 2022,
    'condition': 'A',
    'phase3_worse_population': 0,
    'phase3_worse_percentage': 0,
    'phase1_population': 198570,
    'phase1_percent': 0.54,
    'phase1_color': '#CDFACD',
    'phase2_population': 85470,
    'phase2_percent': 0.23,
    'phase2_color': '#FAE61E',
    'phase3_population': 64190,
    'phase3_percent': 0.17,
    'phase3_color': '#E67800',
    'phase4_population': 15700,
    'phase4_percent': 0.04,
    'phase4_color': '#C80000',
    'phase5_population': 0,
    'phase5_percent': 0,
    'phase5_color': '#640000'},
   'geometry': {'type': 'Polygon',
    'coordinates': [[[42.920335297, 0.31870463],
      [42.730911255, 0.311817259],
      [42.630912781, 0.721780658],
      [42.430908203, 1.321726918],
      [42.200901031, 1.311727881],
      [41.420883179, 1.261732697],
      [41.640888214, 1.941671729],
      [42.400909424, 1.951670408],
      [42.520908356, 1.881676555],
      [42.900917053, 1.521708727],
      [42.980918884, 1.461714149],
      [43.270923615, 1.031752586],
      [43.350925446, 0.921762526],
      [43.520351409, 0.676131546],
      [43.497226716, 0.652937771],
      [43.487045289, 0.645697118],
      [43.434757233, 0.589724184],
      [43.401786803, 0.56085235],
      [43.377445223, 0.535068869],
      [43.29442215, 0.436700226],
      [43.258571626, 0.401362718],
      [43.241474152, 0.381407499],
      [43.208774567, 0.350011586],
      [43.190654755, 0.328533321],
      [42.920335297, 0.31870463]]]} }]}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 14:10:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/read-geometry-from-json-api-response-in-notebook/m-p/1260873#M8391</guid>
      <dc:creator>A_Schwab</dc:creator>
      <dc:date>2023-02-23T14:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Read geometry from JSON API response in notebook</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/read-geometry-from-json-api-response-in-notebook/m-p/1262200#M8414</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Using the sample you provided, I was able to parse the JSON correctly into an SEDF like so:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor

parsed_json = [
    {
        **feature["properties"], 
        "geom": {
                    "rings" : feature["geometry"]["coordinates"],
                    "spatialReference" : {"wkid" : 4326}
                }
    } for feature in json["features"]]

df = pd.DataFrame.from_dict(parsed_json)
sedf = pd.DataFrame.spatial.from_df(df, geometry_column="geom")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2023 22:58:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/read-geometry-from-json-api-response-in-notebook/m-p/1262200#M8414</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2023-02-27T22:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Read geometry from JSON API response in notebook</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/read-geometry-from-json-api-response-in-notebook/m-p/1264578#M8462</link>
      <description>&lt;P&gt;Thanks for taking time to look at this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code you shared works for me to create a DF and then SEDF of the JSON.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I try to visualise the data in the map widget with&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sedf.spatial.plot(map_widget= map1)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;it throws an error (error text attached as widget_error.txt).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried using the SEDF to create a feature layer with&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sedf.spatial.to_featurelayer('test', gis=GIS("home"))&lt;/LI-CODE&gt;&lt;P&gt;this also threw an error, attached as to_fl_error.txt&lt;/P&gt;&lt;P&gt;If you have any insight into what might be causing the errors or how to proceed, it would be much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;FWIW, if I access the geometry of a feature/row in the SEDF through `sedf[:1].geom[0]` the notebook correctly displays the geometry of the district.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2023 17:04:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/read-geometry-from-json-api-response-in-notebook/m-p/1264578#M8462</guid>
      <dc:creator>A_Schwab</dc:creator>
      <dc:date>2023-03-06T17:04:28Z</dc:date>
    </item>
  </channel>
</rss>

