beautypg.com

Pitney Bowes MapXtreme User Manual

Page 191

background image

Chapter 8: Working with Data

Features and Feature Collections

MapXtreme v7.1

198

Developer Guide

Dim map As Map = mapControl1.Map
Dim session As ISession = MapInfo.Engine.Session.Current
Dim si As SearchInfo = _

MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, _
pt, 3) ' 3 pixel tolerance radius

si.QueryDefinition.Columns = Nothing

' fetch all columns instead of just default
' Customize to stop at topmost layer where something is found

CType(si.SearchResultProcessor, ClosestSearchResultProcessor)._

Options = ClosestSearchOptions.StopAtFirstMatch

' Puts results of search directly into default selection
' Searches all tables in map in order from top to bottom.

MapInfo.Engine.Session.Current.Catalog.Search(map._

Layers.GetTableEnumerator(), si, _
session.Selections.DefaultSelection, _
ResultSetCombineMode.Replace)

End Sub

SearchIntersectsFeature

VB example:

Public Shared Sub _

MapInfo_Data_SearchInfoFactorySearchIntersectsGeomeTry(ByVal _
map As Map)

Dim ti As Table = _

MapInfo.Engine.Session.Current.Catalog.GetTable("usa")

Dim lParks As MapInfo.Mapping.FeatureLayer = _

CType(map.Layers("USA"), MapInfo.Mapping.FeatureLayer)

Dim g As MapInfo.Geometry.FeatureGeometry = New _

MapInfo.Geometry.Point(map.GetDisplayCoordSys(),-98,34)

Dim si As SearchInfo = _

MapInfo.Data.SearchInfoFactory.SearchIntersects_
Geometry(g,MapInfo.Data.IntersectType.Geometry)

Dim fc As IResultSetFeatureCollection = _

Session.Current.Catalog.Search("usa",si)

map.SetView (fc.Envelope)

End Sub

SearchWithinScreenRadius

This sample illustrates how to search for features using a screen drawn circle.

C# example:

// find nearest city to center of map
private void menuItemSearchNearest_Click(object sender, System.EventArgs
e)
{

try
{

Cursor.Current = Cursors.WaitCursor;
// to compare to SearchWithinScreenRadius, we are
// calculating the search distance the same way it does