Data Query Concept |
Using the DataQuery class users are able to identify spatial features that lie within a given area (defined by a BoundingBox) or that are near a specific point (defined by a LatLon). Data queries can return information about the following spatial data types:
Tip |
---|
It is possible to define your own spatial data type using the CustomTable and CustomColumn classes. |
Create a simple application that explores the different types of available queries.
Each data type has its own methods, which can be used to perform spatial queries. For example, to find polygons you could use one of the following methods: FindNearestPolygons(LatLon, String), QueryPolygons(BoundingBox, String), QueryPolygonsAtPoint(LatLon, String).
In some cases it is possible to request that only features of a given type be returned. For example: The user could use the mouse to specify an area on a map, and then use the DataQuery class to request all the freeways inside that area by passing the appropriate StreetType to the query method.
The following code snippet demonstrates how a data query can be used to obtain meta information about a given location. A similar procedure is used by some performance car manufacturers to deactivate speed limiters when the vehicle's current location is at a "race_track" or "circuit" polygon.
// This is the location (in Los Angeles, USA) that we'll use for the data query LatLon loc = new LatLon(33.919432,-118.31181); // Get all polygons at the given location... Polygon[] polys = DataQuery.QueryPolygonsAtPoint(loc, "all"); Console.WriteLine("There are a total of " + polys.Length + " polygons at the location " + loc.ToString()); int counter = 1; foreach (Polygon p in polys) { Console.WriteLine("\t" + (counter++) + ") " + p.Name); } // Output: // There are a total of 3 polygons at the location 33.919432,-118.311809 // 1) Chester L Washington Golf Course // 2) Los Angeles // 3) California
See the Predefined Query Tables topic for information on the predefined columns which can be queried for various feature types.