Checking for points in polygons – Pitney Bowes MapXtreme User Manual

Page 304

Advertising
background image

Chapter 16: Spatial Objects and Coordinate Systems

Checking for Points in Polygons

MapXtreme v7.1

311

Developer Guide

column.DataType = MIDbType.Style
tableInfo.Columns.Add(column)

Dim pointTable As Table = _

Session.Current.Catalog.CreateTable(tableInfo)

’ Set the location and display style of the point
Dim Geometry As FeatureGeometry = _

New MapInfo.Geometry.Point(coordSys, x, y)

Dim vStyle As SimpleVectorPointStyle = _

New SimpleVectorPointStyle(37, Color.Red, 14)

Dim cStyle As CompositeStyle = _

New MapInfo.Styles.CompositeStyle(vStyle)

’Update the table with the location and style of the new feature
Dim cmd As MICommand = connection.CreateCommand()
cmd.Parameters.Add("Geometry", MIDbType.FeatureGeometry)
cmd.Parameters.Add("style", MIDbType.Style)
cmd.CommandText = "Insert Into temp (MI_Geometry,MI_Style) values _

(Geometry,style)"

cmd.Prepare()
cmd.Parameters(0).Value = Geometry
cmd.Parameters(1).Value = cStyle
Dim nchanged As Integer = cmd.ExecuteNonQuery()
cmd.Dispose()

’add the table to the map
map.Layers.Add(New MapInfo.Mapping.FeatureLayer(pointTable))
End Sub

Checking for Points in Polygons

The following code example shows how to determine whether a point is inside the boundary of a
FeatureGeometry (Multipolygon), on the boundary line or falls outside of it.

Public Shared Sub MapInfoGeometryContainsPoint()
Dim coordSysFactory As CoordSysFactory = Session.Current.CoordSysFactory
Dim coordSys As CoordSys = _

coordSysFactory.CreateLongLat(MapInfo.Geometry.DatumID.NAD83)


Dim points(6) As DPoint

points(0) = New DPoint(-0.705036, -0.122302)
points(1) = New DPoint(-0.446043, 0.486811)
points(2) = New DPoint(0.235012, 0.36211)
points(3) = New DPoint(0.422062, -0.304556)
points(4) = New DPoint(-0.244604, -0.71223)
points(5) = New DPoint(-0.705036, -0.122302)

Dim multiCurve As MultiCurve = New _

MultiCurve(coordSys,CurveSegmentType.Linear,points)

Advertising