MapInfo Products KnowledgeBase

Product: MapXtreme 2004/2005
Version: 6.0, 6.1, 6.2, 6.5
Platform: All Windows Platforms
Category: Geometry

Summary:
How to access the coordinates for every node in a line/curve object in MapXtreme 2004/2005.

Question:
It will often be necessary to obtain coordinate information for the nodes in a line, or curve feature. How can this be accomplished?

Answer:
The following code is one solution:
Hide details for C# Code:C# Code:
//create a table object - the 'Lines' table is just one-row table with a single line object for this example
MapInfo.Data.Table ti = MapInfo.Engine.Session.Current.Catalog.GetTable("Lines");
//create a SearchInfo object
MapInfo.Data.SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchAll();
//Query everything from the table
MapInfo.Data.IResultSetFeatureCollection results = MapInfo.Engine.Session.Current.Catalog.Search(ti,si);
//take the first feature (in this case, because the table used only had one row with one curve object
MapInfo.Data.Feature feature = results[0];
//assign the geometry from this feature into a MultiCurve object
MapInfo.Geometry.MultiCurve multiCurve= (MapInfo.Geometry.MultiCurve) feature.Geometry;
//take the first line from the MultiCurve collection
MapInfo.Geometry.Curve curve = multiCurve[0];
//place all the points from the curve into dptArr
MapInfo.Geometry.DPoint [] dptArr = curve.SamplePoints();
//step through the array and print the coordinates to the debug window
for (int i = 0; i < dptArr.Length ; i++)
{
System.Diagnostics.Debug.WriteLine (dptArr[i].ToString());
}
Hide details for VB.NET Code:VB.NET Code:

'create a table object - the 'Lines' table is just one-row table with a single line object for this example
Dim ti As MapInfo.Data.Table = MapInfo.Engine.Session.Current.Catalog.GetTable("Lines")
'create a SearchInfo object
Dim si As MapInfo.Data.SearchInfo = MapInfo.Data.SearchInfoFactory.SearchAll()
'Query everything from the table
Dim results As MapInfo.Data.IResultSetFeatureCollection = MapInfo.Engine.Session.Current.Catalog.Search(ti, si)
'take the first feature (in this case, because the table used only had one row with one curve object
Dim feature As MapInfo.Data.Feature = CType(results, MapInfo.Data.IDynamicFeatureCollection).Item(0)
'assign the geometry from this feature into a MultiCurve object
Dim multiCurve As MapInfo.Geometry.MultiCurve = CType(feature.Geometry, MapInfo.Geometry.MultiCurve)
'take the first curve from the MultiCurve collection
Dim curve As MapInfo.Geometry.Curve = multiCurve.Item(0)
'place all the points from the curve into dptArr
Dim dptArr As MapInfo.Geometry.DPoint() = curve.SamplePoints()
'step through the array and print the coordinates to the debug window
Dim i As Integer
For i = 0 To dptArr.Length
System.Diagnostics.Debug.WriteLine(dptArr(i).ToString())
Next


Last Modified: 04/14/2006 02:34:30 PM
Document URL: http://testdrive.mapinfo.com/techsupp/miprod.nsf/kbase_by_product/FF44DE97CDC7C3E5852571090061E902

How to access the coordinates for every node in a line/curve object in MapXtreme 2004/2005.^FF44DE97CDC7C3E5852571090061E902^Y