Hi all,
I am trying to display a FeatureSet (arcgis.features.FeatureSet) object on the ArcGIS API for Python map widget (arcgis.gis.GIS.map.add_layer) in Jupyter Notebook.
I have two FeatureSet objects:
- obtained while querying a layer (query_resp_from_x)
- constructed from arcgis.features.Feature objects (feature_set)
This is the code I am using to create the feature_set object:
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>features <SPAN class="keyword token">import</SPAN> Feature<SPAN class="punctuation token">,</SPAN> FeatureSet<SPAN class="punctuation token">,</SPAN> FeatureCollection
attributes <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">'FID'</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'some_field'</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">'some_val'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">'FID'</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'some_field'</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">'some_val'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN>
features_from_geom <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">"paths"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"paths"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># len(attributes) = len(features_from_geom) = 5</SPAN>
features <SPAN class="operator token">=</SPAN> list<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
counter <SPAN class="operator token">=</SPAN> len<SPAN class="punctuation token">(</SPAN>attributes<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> idx <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN>counter<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
features<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>Feature<SPAN class="punctuation token">(</SPAN>geometry<SPAN class="operator token">=</SPAN>features_from_geom<SPAN class="punctuation token">[</SPAN>idx<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> attributes<SPAN class="operator token">=</SPAN>attributes<SPAN class="punctuation token">[</SPAN>idx<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># here, query_resp_from_x is just a query response from layer X, which in itself is a FeatureSet</SPAN>
feature_set <SPAN class="operator token">=</SPAN> FeatureSet<SPAN class="punctuation token">(</SPAN>
fields<SPAN class="operator token">=</SPAN>query_resp_from_x<SPAN class="punctuation token">.</SPAN>fields<SPAN class="punctuation token">,</SPAN>
geometry_type<SPAN class="operator token">=</SPAN>query_resp_from_x<SPAN class="punctuation token">.</SPAN>geometry_type<SPAN class="punctuation token">,</SPAN>
spatial_reference<SPAN class="operator token">=</SPAN>query_resp_from_x<SPAN class="punctuation token">.</SPAN>spatial_reference<SPAN class="punctuation token">,</SPAN>
object_id_field_name<SPAN class="operator token">=</SPAN>query_resp_from_x<SPAN class="punctuation token">.</SPAN>object_id_field_name<SPAN class="punctuation token">,</SPAN>
global_id_field_name<SPAN class="operator token">=</SPAN>query_resp_from_x<SPAN class="punctuation token">.</SPAN>global_id_field_name
<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Then, I created a map widget in the same notebook and added both the FeatureSet objects to it:
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
gis_obj <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token"><SPAN>'</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fmy_portal" target="_blank">http://my_portal</A><SPAN>'</SPAN></SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'my_user'</SPAN><SPAN class="punctuation token">)</SPAN>
map_obj <SPAN class="operator token">=</SPAN> gis_obj<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
map_obj<SPAN class="punctuation token">.</SPAN>add_layer<SPAN class="punctuation token">(</SPAN>feature_set<SPAN class="punctuation token">)</SPAN>
map_obj<SPAN class="punctuation token">.</SPAN>add_layer<SPAN class="punctuation token">(</SPAN>query_resp_from_x<SPAN class="punctuation token">)</SPAN>
map_obj<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
The map displayed only the query response FeatureSet (query_resp_from_x). Neither the FeatureSet I constructed (feature_set) was displayed, not an exception was raised.
I tried adding some rendering information to the FeatureSet and construct a FeatureCollection from it and display it on map, to no avail.
Can someone tell me what is wrong with this approach?
(P.S.: I converted both the FeatureSet objects (feature_set and query_resp_from_x) and compared them. They were exactly the same except for changes in values. I am attaching both the dict objects as JSON files for your reference.)