|
The actual distance between two waste bins on the road is required for the waste bin service capability detection function. Because the road uses a line element, considering the precision of the collected data, I suppose there may be garbage bins on both sides of the road on the map. Therefore, finding this distance is indeed a difficult problem. Later, I thought about many methods, all of which were negated one by one.
Later, I saw a post on the Forum. It was written in VB and changed to C #. In fact, it was quite simple. I mainly used the querypointanddistance method that came with ipolympus, it returns the distance from the starting point to the line, and then subtract the two distances to obtain the distance between the two points.
Icurve. querypointanddistance method: finds the point on the curve closest to inpoint, then copies that point to outpoint; optionally calculates related items.
/// <Summary>
/// Get the distance between two waste bins on the road
/// </Summary>
/// <Param name = "pnt1"> waste bin 1 </param>
/// <Param name = "pnt2"> waste bin 2 </param>
/// <Param name = "roadfeature"> path </param>
/// <Returns> </returns>
Public double getdistanceoftwopoint (ipoint pnt1, ipoint pnt2, ifeature roadfeature)
{
Double distanceofpnt1 = distancefromstartpoint (pnt1, roadfeature );
Double distanceofpnt2 = distancefromstartpoint (pnt2, roadfeature );
Return distanceofpnt2-distanceofpnt1;
}
/// <Summary>
/// Distance from the waste bin to the road start point
/// </Summary>
/// <Param name = "Ppoint"> </param>
/// <Param name = "pfeature"> </param>
/// <Returns> </returns>
Public double distancefromstartpoint (ipoint Ppoint, ifeature pfeature)
{
Ipolympus line ppolyline = pfeature. Shape as ipolympus line;
Ipoint outpoint = new pointclass ();
Double distancealongcurve = 0; // distance between the point closest to the curve and the starting point of the curve
Double distancefromcurve = 0; // The linear distance from this point to the curve
Bool Brightside = false;
Ppolyline. querypointanddistance (esrisegmentextension. esrinoextension, Ppoint, false, outpoint, ref distancealongcurve, ref distancefromcurve, ref Brightside );
Return distancealongcurve;
} |