I have a web map with roughly 50 features and counting. I'm looking for a quick and dirty way to create a view of each layer where a given field is null. The good news is that this field exists in each of the 50 features.
Is there an easy way to do this?
Thanks!
Mike
Solved! Go to Solution.
You can try using ArcGIS API for Python to automate view creation. This can be done via ArcGIS Notebooks in ArcGIS Online or ArcGIS Pro. Please see more steps at the links:
Best regards,
Kanin
If this answer solved your question, please mark it as "Accept as Solution" to help others who have the same question.
@Kanin ,
Thanks for pointing me in the right direction. Here's the code snippet that I used:
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
from arcgis.mapping import WebMap
gis = GIS("<portal>", "user","pw")
fl_wm_search = gis.content.get("web_map_item_id")
fl_wm_object = WebMap(fl_wm_search)
fl_layers = {item.itemId for item in fl_wm_object.layers}
update_dict = {"viewDefinitionQuery" : "field1 = ''"}
for f in fl_layers:
source_search = gis.content.search(f)[0]
source_flc = FeatureLayerCollection.fromitem(source_search)
new_view = source_flc.manager.create_view(name="{}_Null".format(source_search.title.replace(" ","_")))
view_search = gis.content.search(new_view.title)[0]
view_flc = FeatureLayerCollection.fromitem(view_search)
service_layer = view_flc.layers
for i in range (len(service_layer)):
service_layer[i].manager.update_definition(update_dict)
view_search.move("Home Folder")
Happy New Years!
Best,
Mike
You can try using ArcGIS API for Python to automate view creation. This can be done via ArcGIS Notebooks in ArcGIS Online or ArcGIS Pro. Please see more steps at the links:
Best regards,
Kanin
If this answer solved your question, please mark it as "Accept as Solution" to help others who have the same question.
@Kanin ,
Thanks for pointing me in the right direction. Here's the code snippet that I used:
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
from arcgis.mapping import WebMap
gis = GIS("<portal>", "user","pw")
fl_wm_search = gis.content.get("web_map_item_id")
fl_wm_object = WebMap(fl_wm_search)
fl_layers = {item.itemId for item in fl_wm_object.layers}
update_dict = {"viewDefinitionQuery" : "field1 = ''"}
for f in fl_layers:
source_search = gis.content.search(f)[0]
source_flc = FeatureLayerCollection.fromitem(source_search)
new_view = source_flc.manager.create_view(name="{}_Null".format(source_search.title.replace(" ","_")))
view_search = gis.content.search(new_view.title)[0]
view_flc = FeatureLayerCollection.fromitem(view_search)
service_layer = view_flc.layers
for i in range (len(service_layer)):
service_layer[i].manager.update_definition(update_dict)
view_search.move("Home Folder")
Happy New Years!
Best,
Mike
Hello Mike,
Glad this works for you. Happy New Years to you too!
Cheers,
Kanin
Hello All,
When creating the view how do, I make the script update the query for more than one layer. My Feature class has about 55 layers.
using this the line below will update the first sub layer and not the other one's that is in my feature class
service_layer = view_flc.layers[0]
Thanks
ramon