Select to view content in your preferred language

Proper Way to Edit Service Feature Table Without Map

6246
4
Jump to solution
02-24-2015 05:08 PM
JeremyMartin
Deactivated User

Hi,

I'm getting started with ArcGIS Online and am not sure how to proceed with a certain scenario.

I've created an Operations app that will display live data that I supply. I've made the service feature tables in my organization and they are displayed on the map correctly.

I would like to have a .net application that connects to this service feature table and edits it accordingly, for example adding/editing features and their geometry (just x,y points, nothing complicated). I'm currently trying to use the ServiceFeatureTable classes, and don't have a problem connecting into the table with my credentials. But it seems that it will not load any features without a map attached.

Is there some way to force it to load all of the features in the table so that I can iterate through them and update them? Is there some other way that I am supposed to be doing this? I'm still trying to sort out all of the capabilities here and I'd appreciate any sort of pointers in the right direction.

0 Kudos
1 Solution

Accepted Solutions
AnttiKajanus1
Deactivated User

When you are working directly with ServiceFeatureTable, you are in a control how the data is queried. After initializing the table use QueryAsync with filter that you want to use and there you go. If you want to get everything, you can create QueryFilter and use "1=1" on Where clause.

private async Task<List<Feature>> GetServiceRequestsAsync()
{
       // Create filter that defines what features are returned
       // Get all ServiceRequests that has attributes "requestid", "status" and "requestdate" set
       var filter = new QueryFilter()
       { 
              WhereClause = "requestid <> '' AND status <> '' AND requestdate IS NOT NULL" 
       };
 
       // For filtering feature spatially, use SpatialQueryFilter instead
       // Get all ServiceRequests that intersects with searchArea geometry and as attribute "requestid" set
       //var filter = new SpatialQueryFilter() { Geometry = searchArea, WhereClause = "requestid <> ''" }; 
 
       // Query all service requests that has requestid, status and requestdate set
       var results = await _serviceRequestTable.QueryAsync(filter);
 
       return results.ToList();
}

Also see FeatureDataForm from Toolkit. It makes this this type of editing very simple.

View solution in original post

4 Replies
JeremyMartin
Deactivated User

I just discovered that there is a REST API. Am I overcomplicating things trying to do this through the .Net SDK then?

0 Kudos
AnttiKajanus1
Deactivated User

When you are working directly with ServiceFeatureTable, you are in a control how the data is queried. After initializing the table use QueryAsync with filter that you want to use and there you go. If you want to get everything, you can create QueryFilter and use "1=1" on Where clause.

private async Task<List<Feature>> GetServiceRequestsAsync()
{
       // Create filter that defines what features are returned
       // Get all ServiceRequests that has attributes "requestid", "status" and "requestdate" set
       var filter = new QueryFilter()
       { 
              WhereClause = "requestid <> '' AND status <> '' AND requestdate IS NOT NULL" 
       };
 
       // For filtering feature spatially, use SpatialQueryFilter instead
       // Get all ServiceRequests that intersects with searchArea geometry and as attribute "requestid" set
       //var filter = new SpatialQueryFilter() { Geometry = searchArea, WhereClause = "requestid <> ''" }; 
 
       // Query all service requests that has requestid, status and requestdate set
       var results = await _serviceRequestTable.QueryAsync(filter);
 
       return results.ToList();
}

Also see FeatureDataForm from Toolkit. It makes this this type of editing very simple.

JeremyMartin
Deactivated User

I really appreciate the help, because this is getting me connected where I need to be. Now the only issue I have is that I can't figure out what is going wrong with syncing my edits. I'm grabbing a feature to edit, change an attribute on it, and then use the UpdateAsync feature on my table. My update success is true, yet my table never changes. I'm not sure why it's giving me a success flag of true in this case, because it obviously isn't getting updated.

For example, this is what my code is doing as a test of this:

editFeature.Attributes["Vehicle"] = "TEST";

await _table.UpdateAsync(editFeature);

var editResult = await _table.ApplyEditsAsync(false);

When I look at the single entry in UpdateResults, it returns that it was successful with no error, but my table is never modified.

Thank you so much for helping me.

EDIT:

I did some searching, and decided to add this after my table initialization: _table.OutFields = OutFields.All;

After I did that, it worked. That wasn't in any of the examples, so I'm not sure how I was supposed to figure that out but I think I have it now.

0 Kudos
AnttiKajanus1
Deactivated User

When working with ServiceFeatureTable, you need to commit your changes manually. You can do this after several changes in local cache or after every change.

// To commit changed to the service use ApplyEdits
var results = await table.ApplyEditsAsync();
0 Kudos