Hi everyone,

I am trying to use IPolycurve.QueryPointAndDistance to get the distance from the curve start to the location of a dam on a river.

The problem I encountered is that this seems to query existing vertices on the river, so if the particular segment has only a start and end point (and no vertex near the dam location), the distance to the dam will always be 0.

In order to get around this I am using IProximityOperator.ReturnNearestPoint to find the point on the river closest to the dam, and then using IPolycurve.SplitAtPoint to create a vertex at that point. Once that vertex is in place, QueryPointAndDistance should be able to measure the distance to that vertex.

Now, the SplitAtPoint method has a boolean output called SplitHappened and this is set to "True" when the split is successful.

I am running through this loop for 5 different dams. For the first one, SplitHappened is set to "False" and the distance to the dam is 0. But for the other 4 dams, SplitHappened is set to "True". I don't know what could be changing between the first iteration and the others to cause this difference.

Any comments will be appreciated

I am trying to use IPolycurve.QueryPointAndDistance to get the distance from the curve start to the location of a dam on a river.

The problem I encountered is that this seems to query existing vertices on the river, so if the particular segment has only a start and end point (and no vertex near the dam location), the distance to the dam will always be 0.

In order to get around this I am using IProximityOperator.ReturnNearestPoint to find the point on the river closest to the dam, and then using IPolycurve.SplitAtPoint to create a vertex at that point. Once that vertex is in place, QueryPointAndDistance should be able to measure the distance to that vertex.

Now, the SplitAtPoint method has a boolean output called SplitHappened and this is set to "True" when the split is successful.

I am running through this loop for 5 different dams. For the first one, SplitHappened is set to "False" and the distance to the dam is 0. But for the other 4 dams, SplitHappened is set to "True". I don't know what could be changing between the first iteration and the others to cause this difference.

Any comments will be appreciated

'Create a point on the river nearest the dam

Dim pProxOp As IProximityOperator

Set pProxOp = pRiver ' <--- pRiver is an IFeature

Dim pDamPoint As IPoint

Set pDamPoint = pProxOp.ReturnNearestPoint(pDam, esriNoExtension) '<-- pDam is an IFeature

'Create a vertex in the river at that point

Dim PartIndex As Long

Dim SegIndex As Long

Dim SplitHap As Boolean

pRiver.SplitAtPoint pDamPoint, True, False, SplitHap, PartIndex, SegIndex

Debug.Print SplitHap ' <-- This comes up "False" the first time, and "True" all other times

'Find the distance to the point

Dim DistToDam As Double

Dim NearDist As Double

Dim Length As Double

Dim pDamPoint2 As IPoint

Set pDamPoint2 = New Point

Dim Right As Boolean

pRiver.QueryPointAndDistance esriNoExtension, pDam, False, pDamPoint2, DistToDam, NearDist, Right

Duncan