public async Task SelectingFeaturesFromAFeatureClass()
{
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.FacilitySite"))
{
List<Coordinate2D> newCoordinates = new List<Coordinate2D>
{
new Coordinate2D(1021570, 1880583),
new Coordinate2D(1028730, 1880994),
new Coordinate2D(1029718, 1875644),
new Coordinate2D(1021405, 1875397)
};
SpatialQueryFilter spatialFilter = new SpatialQueryFilter
{
WhereClause = "FCODE = 'Park'",
FilterGeometry = new PolygonBuilderEx(newCoordinates).ToGeometry(),
SpatialRelationship = SpatialRelationship.Crosses
};
// For Selecting all matching entries.
using (Selection anotherSelection = enterpriseFeatureClass.Select(spatialFilter, SelectionType.ObjectID, SelectionOption.Normal))
{
}
// This can be used to get one record which matches the criteria. No assumptions can be made about which record satisfying the
// criteria is selected.
using (Selection onlyOneSelection = enterpriseFeatureClass.Select(spatialFilter, SelectionType.ObjectID, SelectionOption.OnlyOne))
{
}
// This can be used to obtain a empty selction which can be used as a container to combine results from different selections.
using (Selection emptySelection = enterpriseFeatureClass.Select(spatialFilter, SelectionType.ObjectID, SelectionOption.Empty))
{
}
// If you want to select all the records in a table.
using (Selection allRecordSelection = enterpriseFeatureClass.Select(null, SelectionType.ObjectID, SelectionOption.Normal))
{
}
}
});
}