Select to view content in your preferred language

Hide or remove a GPFeatureRecordSetLayer layer using python

386
3
12-20-2023 09:31 AM
TomerAdmon
Emerging Contributor

I'm building a geoprocessing tool with a "Feature Set" input (GPFeatureRecordSetLayer) that will be used during the tool's execution. The result of the execution is a new layer with color indications that should be presented on top of the "Feature Set" for the user.

Any idea how to remove/hide the initial  "Feature Set" layer from the Python side? or maybe update that input layer to be in the bottom of the map.

I've tried to use the "arcpy.Delete_management(desc.name)" that was able to delete the layer, but also caused ArcGIS Pro to throw endless errors.

Another question that might help is:
Where is that input layer stored? is it possible to access that using "arcpy.mapping.MapDocument" maybe...

 

0 Kudos
3 Replies
AlfredBaldenweck
MVP Regular Contributor

If you're trying to remove the layer, you want to be using the removelayer method of the map class

aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.activeMap

mp.removeLayer("Featureset1")

 

A layer is not actually your data; it is just a representation of it. arcpy.management.Delete() is killing whatever data that layer is referencing.

0 Kudos
TomerAdmon
Emerging Contributor

Thanks @AlfredBaldenweck !!
Would that work if the Python script is executed from a geoprocessing widget in webappbuilder? or should I look for an alternative?

0 Kudos
AlfredBaldenweck
MVP Regular Contributor

Actually not sure at all about this one. I'd say give it a try and then if it doesn't work, try the webmap RemoveLayer() method. If it's in a webapp, I'm assuming you're using web maps, as well, so that might be the way to go anyway?

0 Kudos