Geospatial Analysis with AutoCAD Map 3D, Part 218 Nov, 2009 By: Michael Schlosser
Find patterns — and answers — in your data by creating subsets and identifying features and objects.
Geospatial queries are at the heart of geospatial analysis; they are used to retrieve a subset of objects or features by attribute, location, or both. Queries help create subsets of the data, identify objects and features based on specific criteria, and reveal patterns in the data. Queries have two primary components: attribute conditions (e.g., Zone= "Industrial") and/or geographic conditions (e.g., number of water meters within a specific area). Queries are used to answer questions such as:
- "How many municipalities are in the state of Georgia?"
- "What is the total length of 8-inch PVC water main within city boundaries?"
- "Where are all the land parcels that are zoned industrial?"
AutoCAD Map 3D software supports the ability to query both CAD data and feature data. CAD data is typified by geometric data such as points, lines, text, and other CAD entities stored in DWG files. Features, on the other hand, are spatial representations of real-world entities such as hydrants, power lines, and land parcels. Feature data is typically stored in geospatial files and databases including ESRI SHP files, SDF, Oracle, PostGIS, and ESRI ArcSDE managed databases, as well as other formats. This article focuses on the feature data query capabilities in AutoCAD Map 3D.
Feature Data Queries
For this example, we will query an ESRI SHP file containing land parcels to create a map that dispalys all parcels with land values less than $10,000 that are also touching a particular geographic region, as indicated by a user-specified rectangular window.
To query feature data, you must first connect to a geospatial data source containing the features to be queried. By connecting to a feature data source rather than relying on an import process, you can work with the feature data directly in its native format without first having to create a copy of the data.
In Display Manager, click Data > Connect to Data to reveal the Data Connect window.
In the left pane of the Data Connect window, select the data provider corresponding to the geospatial data source to be queried — in this example, it's Add SHP Connection. In the right pane, specify the connection parameters to the PARCELS.SHP file and click the Connect button.
Next, in the Add Data to Map section, under Schema, select the feature classes to include in the map. If the data source contains only a single feature class, as it does in this case, that feature class is selected automatically. To display all of the features without creating a query, click the Add to Map button.
The result is a map showing all parcel features from the geospatial data source.
Now that the map has some feature data in it, you can create a query by activating the Create Query window. In Display Manager, right-click the Parcels feature layer and select the Query to Filter Data option.
At this point, you can define an expression to filter the data by attribute and/or location. Click on the Start a Simple Filter option to reveal an expression template of the form:
[property] > [value]
Now, modify the expression template by selecting [property] and then choosing a property option to reveal a list of valid properties that can be used in the query. To find all parcels with a Land Value of less than $10,000, select the LAND_VALUE property.
Note that the default comparison operator is set to the "greater than" symbol. To change the comparison operator to the "less than" symbol, select ">" in the expression template and then choose the "<" icon. Next, enter the comparison value by selecting [value], then enter the number 10000 via the keyboard.
At this point, you can check to make sure that you've built a valid expression by selecting the Validate button. If the expression is valid, click the OK button to reveal the results.
Note that the map now shows a subset of the total number of parcels; namely, only those parcels where the Land Value is less than $10,000.
Recall that we want to show only those parcels touching a user-specified rectangular region. To add this geographic component to the query, re-activate the Create Query window.
In Display Manager, right-click the Parcels feature layer and select the Query to Filter Data option. Note that the current filter expression is revealed:
LAND_VALUE < 10000
Now, add a joining operator by selecting the AND icon. Next, add the geographic search condition by selecting Locate on Map and then the Touching Any Part of Rectangle option. The current map will be revealed, allowing you to specify the two opposite corners of your desired rectangular window. The filter expression should now look like this:
LAND_VALUE < 10000 AND [LOCATION:INTERSECTS.POLYGON.ID1]
Select the Validate button to ensure that you have a valid expression, and then click OK to reveal the results.
The final resultant map now reveals only those parcels that satisfy both attribute and location-specific conditions.
Different Kinds of Queries
This article has examined the creation of a simple geospatial query of a feature data source using AutoCAD Map 3D. A video of this example is available via my blog, geoExpressions. Be sure to look for my future articles; next time, I will explore the creation of a CAD data query.
About the Author: Michael Schlosser
In her easy-to-follow, friendly style, long-time Cadalyst contributing editor and Autodesk Technical Evangelist Lynn Allen guides you through a new feature or time-saving trick in every episode of her popular AutoCAD video tips. Subscribe to the free Cadalyst Video Picks newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!