Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

What is the best method for caching features obtained by a featurecuror so they can be requeried without having to round trip to the datasource?

I am querying a subset of features using a queryfilter and later in my code want to subset the original subset of features (ie. I don't want to make a round trip as I already queried the features once). Is there an object or something that allows you to use queryfilter on a subset of client cached features? Or is just storing the features in a List of something and do searching via a loop?

In an arcuser article (fall 2009) http://www.esri.com/news/arcuser/1009/files/5tips.pdf which has arcobjects optimizations there is a section on the following:

Code Listing 4: Don’t Be Too Selective (or Chatty)

which offers:

Build a where clause containing all items you want to fetch.

  • Create a query filter and set the where clause property to the where clause you just created.
  • Create a Geodatabase RecordSet and set the source table property.
  • Create a new InMemoryWorkspace and save the RecordSet as a table within it.

but not much more than that. I can't track down the code samples for the article and the documentation on IRecordSet (assumption that is what this article is referring to) is very light and not much to go on.

share|improve this question
    
I see the IRecordSet2 interface has DetachTable and SaveAsTable methods. This may be what the author of the referenced article was eluding to. –  Justin Carasick Feb 27 '13 at 21:26

2 Answers 2

I would try using ISpatialCacheManager3 for this.

Enabling feature caching improves the performance of all spatial searches whose query geometry lies within the cached area and and also improves the performance of all queries that retrieve features by object ID (for example, GetRow, GetFeature, GetRows, and GetFeatures).

share|improve this answer

**NOTE This may NOT be the BEST method but IS a method that can be used.

        // Create an in-memory workspace factory.
        IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();

        // Create a new in-memory workspace. This returns a name object.
        IWorkspaceName workspaceName;

        try
        {
            workspaceName = workspaceFactory.Create(null, Guid.NewGuid().ToString(), null, 0);
        }
        catch (Exception ex)
        {
            throw new Exception("Error Creating Cache Workspace.", ex);
        }

        IName name = (IName)workspaceName;

        // Open the workspace through the name object.
        _tempWorkspace = (IWorkspace)name.Open();

        IQueryFilter pQuery = new QueryFilterClass();
        pQuery.WhereClause = sWhereClause;

        IRecordSetInit recSetInt = new RecordSetClass();
        recSetInt.SetSourceTable(pFeatureClass as ITable, pQuery);
        IRecordSet2 recSet = (IRecordSet2)recSetInt;

        try
        {
            _tempFeatureClass = recSet.SaveAsTable(_tempWorkspace, Guid.NewGuid().ToString()) as IFeatureClass;
        }
        catch (Exception ex)
        {
            throw new Exception("Error Saving Cache Table.", ex);
        }

What this does: Opens a featureclass and queries a subset of records into an IRecordSet2 object. The subset records set is then persisted to an inmemoryworkspace as a featureclass. The subset featureclass inmemeory can then be queried and searched using a queryfilter without needing to go back to the original data source.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.