ArcObjects with ArcGis 10.1
I have constructed a polyline in WGS84 that has straight segments and curved segments. The line is heavily geodesically densified. Now I have to step through every 100 meters and perform additionally calculations at these points.
IConstructPoint.ConstructAlong looks promising but the distance is spat ref units which for WGS84 is degrees so that rules that out.
The best I have been able to do is as follows: Step through every vertex in the line (which is way more than needed) and:
1. use IPolyline.QueryPointAndDistance to get the distance along the line in spat ref units. 2. Get a subcurve at that distance using IPolycurve2.GetSubcurve 3. Finally use IGeometryServer3.GetLengthsGeodesic of the subcurve to get the length in meters.
Seems like a lot of overhead. There must be a way to get a point every x meters along the line. Most of the functions I have looked at are based on length in spat ref units which is not what I am looking for.
Applicable code is as follows:
Dim pntAlongLine As IPoint = New Point Dim distAlongLineToPnt As Double = 0, distFromPntToLine As Double = 0, IsToRightOfLine As Boolean pPolyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pntOnLine, False, pntAlongLine, distAlongLineToPnt, distFromPntToLine, IsToRightOfLine) 'get a subcurve Dim pPolyCurve As IPolycurve2 = CType(pPolyline, IPolycurve2) Dim outCurve As ICurve = Nothing pPolyCurve.GetSubcurve(0, distAlongLineToPnt, False, outCurve) 'create a polyline array with one element Dim pPolylineArray As IPolylineArray = New PolylineArray pPolylineArray.Add(pPolyline) 'create a linear meter unit Dim pSpatRefFact As New SpatialReferenceEnvironment Dim pLinearUnitMeters As ILinearUnit = CType(pSpatRefFact.CreateUnit(esriSRUnitType.esriSRUnit_Meter), ILinearUnit) 'setup a Geometry server Dim pGeometryServer As IGeometryServer3 = CType(New GeometryServer, IGeometryServer3) Dim pDoubleArray As IDoubleArray pDoubleArray = pGeometryServer.GetLengthsGeodesic(pSpatRef, pPolylineArray, pLinearUnitMeters) 'the reference array will have geodesic distances for each polyline. in this case we passed in only one line. distInMeters = pDoubleArray.Element(0)
This code is dependent on each vertex in the line but what I would really like is a point every 100 meters along the line.