Select to view content in your preferred language

Using GetFeatureDataAsync with whereClause - Partial update of cache (9.3.1)

1397
3
04-30-2010 07:41 AM
DavidMarley
Frequent Contributor
I am trying to figure out how to use the GetFeatureDataAsync overload that allows you to specify a whereClause. Due to bandwidth limitations (wireless aircards), it is NOT feasible to use GetFeatureDataAsync with refreshData = true and re-download the entire layer.

I have figured out the syntax of GetFeatureDataAsync with whereClause, HOWEVER the resulting features are still not updating in my cache. I have verified that I am getting (the correct) data back from my GetFeatureDataAsync, but how to update the cache?

The syntax itself is pretty straight-forward: pass null for fidList if you don't wish to use, and then format the where clause appropriately for your data source (ArcSDE with SQL Server etc.) See code snippet below:

string whereClause = "OWNER_NAME = 'Doe, John H.'";
//string whereClause = "ACRES > 1999";
// --- Synch only certain parcels, based on a whereClause
FeatureLayer parcelLayer = (FeatureLayer)getLayer(mobileService1, parcelLayerName);
mobileService1.GetFeatureDataAsync(parcelLayer, mobileService1.GetExtent(), whereClause, null, "GET PARCELS");

I have verified that I am recieving the desired features back, HOWEVER my cache is not updated unless I first delete the existing features in question, or delete the entire featurelayer from my cache. The latter defeats the whole purpose of getting just the changes/updates to begin with. And I cannot figure out how to do the former because I do not know beforehand what features will be returned by the GetFeatureDataAsync until I execute it, and even afterwards I cannot figure out how to parse through the results of the GetFeatureDataAsync and apply the changes.

There is no help or code samples for these methods so it is quite frustrating. I am also quite mystified why ESRI has made it SO DIFFICULT to synchronize server data changes down to the client, without deleting your entire layer and re-downloading the whole thing. There are lots of posts on this topic in the old forum, so it's clearly something a lot of people need to do.

Anyway, suggestions, code samples, alternate approaches are appreciated.
0 Kudos
3 Replies
StephenDickinson
Esri Contributor
Hi,

We have encountered this issue previously also.  I don't have a silver bullet for you but there may be some workarounds.

As far as I know the only way to get the GetFeatureDataAsync method whereClause overload to overwrite existing data with a newer copy is to remove the existing data from the mobile cache first.  The RemoveFeatureData method can be used to do this.

However, as you have mentioned, you don't necessarily know ahead of time which features need to be removed from the cache before you make the call to GetFeatureDataAsync - as you do not know which features will be retrieved by the call.

Therefore, you need some supplementary process to obtain which feature ids to delete / request before making calls to RemoveFeatureData / GetFeatureDataAsync.

I don't think this can be done with the ArcGIS Mobile SDK.  There is a GetFeatureCount method but really you need a GetFeatureIDs method, which doesn't exist.

In order to do this I think you would need to go outside of the Mobile SDK.  Perhaps using the AGS SOAP API is an option?

http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ArcGIS/SOAP/overview.htm

http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriCarto/IMapServer_QueryFeatureIDs.htm

Other alternatives may be to build a custom web service using ArcObjects or create a geoprocessing service.

I hope this helps.

Steve
0 Kudos
DavidMarley
Frequent Contributor
Hi Steve,

Thanks for the thoughts.  Yes it looks like we are going to have to pursue a workaround along the lines of what you are suggesting - i.e., use a supplementary process to get the IDs of features to delete from the cache, delete them, and then call GetFeatureDataAsync.  It just seems crazy to have to do this, but well I can't say I haven't been in this position before...  🙂

The really strange thing is that other overloads of GetFeatureDataAsync include a refreshData boolean parameter so you can, for example, replace the features within a small extent very easily.  But the overload that accepts a whereClause does not have the refreshData parameter. 

I've been trying to find a way to iterate through the "result set" of the GetFeatureDataAsync call, but I can't see any way to access it (I don't see any kind of recordset or other object I can iterate through).  If I could iterate through the records returned, I could get the feature IDs and delete the features without having to make a call to a separate service.

Anyway, thanks again for the thoughts.

Dave
0 Kudos
StephenDickinson
Esri Contributor
Dave,

Re the refreshData param - yes it is confusing why the other GetFeatureDataAsync overloads do have that.  For these overloads setting the refreshData param to true will remove the mobile cache data for the extent and layers specified (depending on overload used).  This then enables features to be downloaded, otherwise with refreshdata=false only new features not in the cache will be download e.g. not edited or deleted features.

However, for the GetFeatureDataAsync whereClause overload the RemoveFeatureData method must be used prior to the call to the GetFeatureDataAsync method in order to reproduce the same kind of behaviour.

As for returning a list of FIDs using the SDK... still not sure about doing that without going outside of the SDK... but as a kludge how about having a copy of the layer in question in the map document underpinning the mobile cache that you can use as a temporary area e.g. one that you can scrub clean but is used just to download data for the purpose of obtaining FIDs to feed into the data retrieval for your real layer?  You could restrict the fields in the temp layer in the map document by turning their visiblity off in layer properties - might save on some space.  I cringed as I typed that!

Steve
0 Kudos