Pitney Bowes MapXtreme User Manual

Page 307

Advertising
background image

Chapter 16: Spatial Objects and Coordinate Systems

Coordinate Systems

MapXtreme v7.1

314

Developer Guide

Changing the Coordinate System of a Geometry Object

The next example illustrates how to convert a Geometry object from one coordinate system to
another.

VB example:

Public Shared Sub MapInfoGeomeTryCoordSys(ByRef coordSys As _

CoordSys, ByRef points() As DPoint, ByRef alternateCoordSys _
as CoordSys

' All Geometry constructors require a CoordSys parameter
' Note that the points array is assumed to be in coordSys

Dim lineString As LineString = New _

LineString(coordSys,points)

' The Geometry has a reference to the CoordSys used during
' construction. Unlike the coordinate data represented by the
' points array, the CoordSys' is not copied

If ReferenceEquals(coordSys, lineString.CoordSys) Then

Console.WriteLine("Geometry objects hold a reference to _

the CoordSys used during construction")

End If

' if you want to convert the object to another coordinate
' system, you need to make a new copy using one of the copy methods

If Not coordSys.Equals(alternateCoordSys) Then

Dim newGeometry as MapInfo.Geometry.Geometry = _

lineString.Copy(alternateCoordSys)

End If

End Sub

Determining the Coordinate System of a Map in MapControl

The following code examples shows how to determine the coordinate system for a Map object.

VB example:

Public Shared Sub _

MapInfo_Mapping_FeatureViewerGetDisplayCoordSys(ByVal map As Map)

’Load the Default Projection File so that we can get the name.

MapInfo.Engine.Session.Current.CoordSysFactory.LoadDefault_

ProjectionFile()

’Get the Coordinate System object for current map in the MapControl
Dim mapCoordSys As MapInfo.Geometry.CoordSys = _

map.GetDisplayCoordSys()

’Assign the name of the Coordinate System to a string variable.
’note: the CoordSysName function will return a blank string if the
’Coordinate System is not found in the current CoordinateSystemSet
’(loaded by the LoadDefaultProjectionFile above).

Advertising