Deleting features using 'where' clause?

668
5
07-12-2022 06:11 AM
gkresic
New Contributor

By looking at REST API docs for /deleteFeature here:

https://developers.arcgis.com/rest/services-reference/enterprise/delete-features.htm 

it seems that deletes can be performed in multiple ways:

  1. by giving objectid(s) of feature(s) to delete
  2. by specifying geometry to overlap/intersect features to delete with
  3. by specifying SQL-like 'where' clause which will select features to delete

However, by looking at Javadocs, it seems that ArcGIS Runtime for Java supports only first method using deleteFeature(s)Async on FeatureTable.

Are 2 and 3 unsupported or am I missing something?

0 Kudos
5 Replies
MarkBaird
Esri Regular Contributor

I can see you've posted a couple of similar editing and delete questions so I'll use this thread to hopefully help with your issue.

The Java API isn't aiming to be a 1:1 mapping of the REST api, although as you've seen we use it in the background.  The Java API has been designed to make editing workflows on desktop based applications easy.

All the things you list above are possible, but rather than me trying to make a comparison with the REST and and Java it may be more useful if you were to explain what you are trying to achieve.

Remember that the Java API is intended for writing desktop (JavaFX) applications and isn't intended for writing server side components like microservices.

There are lots of sample apps in github which may help you including this one which shows you how to select and delete features.

If the samples don't help then if you explain your application a little more I can point you in the right direction.

0 Kudos
gkresic
New Contributor

Well, I'm simply trying to delete features from hosted layer table - that should be a basic operation unrelated to type of application, don't you agree?

So far, I didn't find any way to do it using ArcGIS Java lib. Provided example queries for features and then deletes them using ServiceFeatureTable.deleteFeaturesAsync(Iterable<Feature>) and ServiceGeodatabase.applyEditsAsync(), but like I explained in another post, that approach doesn't work for me, since ServiceGeodatabase.applyEditsAsync() throws an error (probably due to wrong serialization of parameters during API invocation, but I'm not sure).

0 Kudos
MarkBaird
Esri Regular Contributor

The reason I'm asking what kind of application you are writing is to make sure you are not investing time in a project which can't be licensed.  If you are writing a desktop JavaFX application this is fine, but if you are writing a server side component such as a micro-service then is isn't covered in the license agreement for the ArcGIS Runtime Product and the advice I give needs to be different.

The API can delete features from a hosted feature service.  For example, I tried it as follows using the objectid of a feature in a service.  Starting by getting the feature using a where clause:

            // query parameters to get a specific feature
            QueryParameters queryParameters = new QueryParameters();
            queryParameters.setWhereClause("objectid=1594564");

            // get a quest result containing the feature to be deleted.
            var resultFuture = featureTable.queryFeaturesAsync(queryParameters);
            FeatureQueryResult selected = resultFuture.get();

Then I deleted it using the same techniques used in the sample.

If you explain exactly what you are doing and maybe share some code I can give you some more pointers.

0 Kudos
gkresic
New Contributor

This was exactly my approach, but calling either ServiceFeatureTable.applyEditsAsync() or ServiceGeodatabase.applyEditsAsync() after (successful) ServiceFeatureTable.deleteFeaturesAsync(Iterable<Feature>) resulted in 'Object ID '885192' is not valid.'.

Which version or ArcGIS Runtime and on which OS did you test?

Regarding app type, I current don't have any - I'm just experimenting what is possible with this Java lib. I'll try to put up something reproducible.

BTW, we digressed into problem I described in previous post, so maybe it would be cleaner if we continue over there?

0 Kudos
MarkBaird
Esri Regular Contributor

The service I'm using to delete features is this one https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer

If you can get me a reproducer I can take a closer look at your code.

For info, I was working on a Mac using 100.14.1.  The fact that you are using Linux shouldn't make any difference.  

0 Kudos