AnsweredAssumed Answered

Unable to display FeatureSet in Map Widget

Question asked by dwaipayana23 on Sep 24, 2018
Latest reply on Sep 24, 2018 by dwaipayana23

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:

 

from arcgis.features import Feature, FeatureSet, FeatureCollection

attributes = [{'FID':1, 'some_field':'some_val', ...}, {'FID':2, 'some_field':'some_val', ...}, ...]

features_from_geom = [{"paths": [[...]]}, {"paths": [[...]]}, ...]

# len(attributes) = len(features_from_geom) = 5

features = list()
counter = len(attributes)
for idx in range(counter):
    features.append(Feature(geometry=features_from_geom[idx], attributes=attributes[idx]))

# here, query_resp_from_x is just a query response from layer X, which in itself is a FeatureSet

feature_set = FeatureSet(
    fields=query_resp_from_x.fields,
    geometry_type=query_resp_from_x.geometry_type,
    spatial_reference=query_resp_from_x.spatial_reference,
    object_id_field_name=query_resp_from_x.object_id_field_name,
    global_id_field_name=query_resp_from_x.global_id_field_name
)

 

Then, I created a map widget in the same notebook and added both the FeatureSet objects to it:

 

from arcgis.gis import GIS

gis_obj = GIS('http://my_portal', 'my_user')
map_obj = gis_obj.map()
map_obj.add_layer(feature_set)
map_obj.add_layer(query_resp_from_x)
map_obj

 

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.)

Outcomes