Delete Layers and Tables From Feature Service (Feature Layer Collection)

3312
6
Jump to solution
03-06-2017 12:17 PM
ZacharyNeumann1
New Contributor III

So I created a new feature service (Feature Layer Collection) into a folder. It is an empty feature service with layers and table relationships. Each layer has a geometry type. I only want points. How can I delete the line and polygon layers and tables using the ArcGIS API for python? I will continue to read documentation and if I figure it out I will post back here.

0 Kudos
1 Solution

Accepted Solutions
ZacharyNeumann1
New Contributor III

I think I can use the delete_from_definition(json_dict) method listed here arcgis.features.managers module — arcgis 1.0.1 documentation

I just need to figure out how to use it properly...

View solution in original post

6 Replies
JoshuaBixby
MVP Esteemed Contributor

Retrieve the item either by searching or using its unique identifier, and then use the arcgis.gis.Item.delete() method.

ZacharyNeumann1
New Contributor III

I will try this next! Thanks Joshua!

0 Kudos
ZacharyNeumann1
New Contributor III

This makes sense for deleting the feature service completely, but as for deleting its layers or tables it doesn't make sense to me. I can access the object (see comment below this one) but if I use the delete method on the object I get

AttributeError: 'FeatureLayer' object has no attribute 'delete'

If I ask for the object's id I get 1, which is local to the feature service itself.

0 Kudos
ZacharyNeumann1
New Contributor III

I guess what I mean by feature service is that it's a feature layer collection.

0 Kudos
ZacharyNeumann1
New Contributor III

Reporting back:

from arcgis.features import FeatureLayerCollection
fs_url = 'URL HERE'
comments = FeatureLayerCollection(fs_url, gis=gis)

layers = comments.layers
tables = comments.tables
for layer in layers:
print(layer)
for table in tables:
print(table)

Output will return each layer and table object.

Tried

del layers[1]

but object does not support item deletion.

0 Kudos
ZacharyNeumann1
New Contributor III

I think I can use the delete_from_definition(json_dict) method listed here arcgis.features.managers module — arcgis 1.0.1 documentation

I just need to figure out how to use it properly...