How do I query the features in a shapefile and display the results?

3521
3
08-14-2015 11:22 AM
AllenChan
New Contributor

I am following this tutorial http://www.arcgis.com/home/item.html?id=953a530ada30477d95cc69e788268bc9 but I don't know how to modify it to do what I need. I'd like to be able to access the data table within the shapefile, query it, and only map the returned results. This seems simple enough but I cannot find any documentation on how to do this. Any ideas?

Tags (2)
0 Kudos
3 Replies
by Anonymous User
Not applicable

Using the ArcGIS Runtime for .NET, you would want to use the ShapefileTable class to open your shapefile.  Depending on how you need to query, you could potentially set the DefinitionExpression for the layer the ShapefileTable is associated with or you could use ShapefileTable.QueryAsync to retrieve the features back and then use those features to create a graphics layer for display purposes.

// Open shapefile

ShapefileTable shp = await ShapefileTable.OpenAsync(pathToShapefile);

// Create feature layer

FeatureTable ft = new FeatureTable(shp);

ft.DefenitionExpression = "sweet_field > 10";

// Add layer to map

.

.

.

0 Kudos
AnttiKajanus1
Regular Contributor II

In ArcGIS Runtime for .NET SDK you should use the approach that Bob Crawford​ said. You can also see examples from our samples

RalphElsaesser
New Contributor

I think, a small change has to be made:

FeatureLayer myFeatureLayer = new FeatureLayer(myShapefileTable);
 myFeatureLayer.DefinitionExpression = "sweet_field > 10";

// Add layer to map

0 Kudos