Select to view content in your preferred language

Is it possible to query a featurelayer without first adding it to the Map?

169
4
Jump to solution
Sunday
Gurunara
New Contributor III

Is it possible to query a featurelayer in ArcPro SDK without first adding it to the Map? Have the featurelayer uri. Is it sufficient to query the featurelayer for data using where clause, without first adding to the Map?

Code sample?

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

You can open featurelayer as table or featureclass from geodatabase object:

const string LAYER_ID = "0";
using (Geodatabase geodatabase = new Geodatabase(new ServiceConnectionProperties(new Uri("https://sdkexamples.esri.com/server/rest/services/GrandTeton/FeatureServer")))
 using (var table = geodatabase.OpenDataset<Table>(LAYER_ID))
 {
 }

More details in that thread

 

View solution in original post

0 Kudos
4 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

You can open featurelayer as table or featureclass from geodatabase object:

const string LAYER_ID = "0";
using (Geodatabase geodatabase = new Geodatabase(new ServiceConnectionProperties(new Uri("https://sdkexamples.esri.com/server/rest/services/GrandTeton/FeatureServer")))
 using (var table = geodatabase.OpenDataset<Table>(LAYER_ID))
 {
 }

More details in that thread

 

0 Kudos
Gurunara
New Contributor III

This works... but it seems a little bit slower than first addding it to the map and then querying that layer subsequently. Is this true? Is it faster to add to map first and querying it using:

var featureLayer = //get from layer added to map already

using (var table = featureLayer.GetTable())
var queryFilter = new QueryFilter
{WhereClause = whereClause,};
using (var rowCursor = table.Search(queryFilter))
...

But is there risk of getting cached data, and will not represent underlying changes if retrieving data from layers added to map?

0 Kudos
GKmieliauskas
Esri Regular Contributor

Sorry, I am Esri distributor, and I don't know how it is coded inside.

You can set LayerCacheType for FeatureLayer.

0 Kudos
RichardDaniels
Regular Contributor

You can also do something like this that would give you easy access to Query to the table. For example, there is a Select method that Searches and retrieves specific rows in this Table that satisfy the criteria set in the queryFilter. If no query filter is set, all rows will be retrieved. This method must be called on the MCT. Use QueuedTask.Run. (Inherited from ArcGIS.Core.Data.Table)

 

   // You can open a FeatureClass as a Table which will give you a Table Reference.      using (Table featureClassAsTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.AddressPoint"))
      {
        // But it is really a FeatureClass object.        FeatureClass featureClassOpenedAsTable = featureClassAsTable as FeatureClass;
      }

 Also, recall that you are using CODE this means you could open the table using standard ODBC connectors (especially if the feature class is stored in SQL).

0 Kudos