beautypg.com

Pitney Bowes MapXtreme User Manual

Page 192

background image

Chapter 8: Working with Data

Features and Feature Collections

MapXtreme v7.1

199

Developer Guide

System.Drawing.Rectangle rect=mapControl1.Bounds;
System.Drawing.Point pt = new System.Drawing.Point(rect.Left,

rect.Top);

pt.X += rect.Width/2;
pt.Y += rect.Height/2;

DPoint dpt1 = new DPoint();
// convert center point to map coords (could use map.Center)
_map.DisplayTransform.FromDisplay(pt, out dpt1);
Distance d = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance

(_map, 3);

SearchInfo si =MapInfo.Data.SearchInfoFactory.SearchNearest(dpt1,

_map.GetDisplayCoordSys(), d);

IResultSetFeatureCollection fc = _catalog.Search("uscty_1k", si);

MapInfo.Geometry.Point p = new

MapInfo.Geometry.Point(_map.GetDisplayCoordSys(), dpt1);

FeatureGeometry buffer = p.Buffer(d.Value, d.Unit, 20,

DistanceType.Spherical);

ShowSearchGeometry(buffer);

SelectFeatureCollection(fc);

}
finally
{

Cursor.Current = Cursors.Default;

}

}

Code Example: How to Find a Feature Containing a Point

You may also wish to perform the opposite type of search, in which you are looking for a feature that
encompasses a point. For example, for delivery planning, you may want to know in which region a
customer is located.

VB example:

Dim g As MapInfo.Geometry.FeatureGeometry = New _

MapInfo.Data.SearchInfoFactory.SearchIntersectsGeometry(g, _
MapInfo.Data.IntersectType.Geometry)

Dim irfc As MapInfo.Data.IResultSetFeatureCollection = _

MapInfo.Engine.Session.Current.Catalog.Search("british_
columbia", si)

Me.MapControl1.Map.SetView(irfc.Envelope)