Selecting Features


 

 


 

To select features based on spatial criteria:

 

  1. Create a shape to use as the search feature. The shape can be a geometric shape created in code or it can be a Layer feature.

  2. Determine the type of spatial search criteria you want to use. See the SearchMethod constants.

  3. Invoke the SearchShape method on the Layer whose features you want to select, specifying the shape and the search method.

  4. If you want to qualify the spatial criteria with an expression, you can do so in the SearchShape method.


Map1.AddLayer(MapPath("states.shp"))
Map1.AddLayer(MapPath("cities.shp"))

' search for a state
Dim state As Recordset
state = Map1("states").SearchExpression("STATE_NAME=""Montana""")

If state.EOF Then
  Response.Write("State not found.")
  Response.End()
End If

' search for cities within the state
Dim cities As Recordset
cities = Map1("cities").SearchShape(state.Shape, SearchMethod.Inside)

If cities.EOF Then
  Response.Write("Cities not found.")
  Response.End()
End If

' display the found records in a DataGrid
DataGrid1.DataSource = cities
DataGrid1.DataBind()

 


 

To select features within a distance:

 

  1. Determine a center point and a distance you want to use to select features.

  2. Invoke the SearchByDistance or SearchNearest method on the Layer whose features you want to select.


Map1.AddLayer(MapPath("cities.shp"))

' search for a city
Dim city As Recordset
city = Map1("cities").SearchExpression("CITY_NAME = ""Baldwin"")

If city.EOF Then
  Response.Write("City not found.")
  Response.End()
End If

Dim cityCenter As Point
cityCenter = city.Shape.GetPoint(0)

Dim distance As Double
distance = Map1.ConvertDistance(5, MeasureUnit.Mile, Map1.MapUnit) ' distance = 5 miles

' search for cities within 5 miles
Dim nearestCities As Recordset
nearestCities = Map1("cities").SearchByDistance(cityCenter, distance)

If nearestCities.EOF Then
  Response.Write("Nearest cities not found.")
  Response.End()
End If

' display the found records in a DataGrid
DataGrid1.DataSource = nearestCities
DataGrid1.DataBind()


 

To select features within a buffer:

 

  1. Determine a line shape and a distance you want to use to select features.

  2. Invoke the SearchBuffer method on the Layer whose features you want to select.

Map1.AddLayer(MapPath("roads.shp"))
Map1.AddLayer(MapPath("cities.shp"))

' search for a highway
Dim highway As Recordset
highway = Map1("roads").SearchExpression("ROUTE = ""Interstate 94"")

If highway.EOF Then
  Response.Write("Highway not found.")
  Response.End()
End If

Dim searchDistance As Double
searchDistance = Map1.ConvertDistance(5, MeasureUnit.Mile, Map1.MapUnit) ' distance = 5 miles

' search for cities within 5 miles
Dim nearestCities As Recordset
nearestCities = Map1("cities").SearchBuffer(highway.Shape, searchDistance)

If nearestCities.EOF Then
  Response.Write("Nearest cities not found.")
  Response.End()
End If

' display the found records in a DataGrid
DataGrid1.DataSource = nearestCities
DataGrid1.DataBind()


 

To select features based on an expression:

 

  1. Determine the logical criteria you want to use to select features. Use this to formulate a VBScript expression.

  2. Invoke the SearchExpression method on the Layer whose features you want to select, specifying the logical criteria.


Map1.AddLayer(MapPath("states.shp"))

' search for a state
Dim state As Recordset
state = Map1("states").SearchExpression("STATE_NAME=""Montana""")

If state.EOF Then
  Response.Write("State not found.")
  Response.End()
End If

' display the state
Map1.Extent = state.RecordExtent


 

To export selected features to a new shapefile:

 

Call the Export method of the Recordset to export selected features to a new shapefile.


Dim mapLayer As Layer

mapLayer = Map1.AddLayer(MapPath("states.shp"))
 
Dim records As Recordset

records = mapLayer.SearchExpression("SUB_REGION = ""Pacific""")

If Not records.EOF Then

   records.Export("C:\MAPS\Pacific.shp") 

End If

 

 

© 2018 VDS Technologies
Converted from CHM to HTML with chm2web Standard 2.85 (unicode)