本文整理汇总了C#中ILineString.Distance方法的典型用法代码示例。如果您正苦于以下问题:C# ILineString.Distance方法的具体用法?C# ILineString.Distance怎么用?C# ILineString.Distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILineString
的用法示例。
在下文中一共展示了ILineString.Distance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Distance
/// <summary>
/// Returns the minimum distance of <paramref name="geometry"/> to <paramref name="lineString"/>.
/// </summary>
/// <param name="lineString"></param>
/// <param name="geometry"> </param>
/// <returns></returns>
static public double Distance(ILineString lineString, IGeometry geometry)
{
double minDistance = Double.MaxValue;
if (lineString == null) return minDistance;
ICoordinate c1;
ICoordinate c2;
ICoordinate[] coordinates = lineString.Coordinates;
if (geometry is IPoint)
{
var point = (IPoint)geometry;
for (int i = 1; i < coordinates.Length; i++)
{
c1 = coordinates[i - 1];
c2 = coordinates[i];
double distance = LinePointDistance(c1.X, c1.Y, c2.X, c2.Y, point.X, point.Y);
if (distance < minDistance)
{
minDistance = distance;
}
}
}
else if (geometry is ILineString)
{
return LineStringFirstIntersectionOffset(lineString, (ILineString)geometry);
}
else if(geometry != null)
{
return lineString.Distance(geometry);
/* TODO: check if above code doesn't work good for line string - use trickery trick below
// trickery trick someone changed cross section geometry from point to linestring
// non geometry based cross sections are represented using a 2 point linestring.
// Use the center of this linestring
IPoint crossSectionCenter = GeometryFactory.CreatePoint(CrossSectionHelper.CrossSectionCoordinate(crossSection));
double distance = GeometryHelper.Distance((ILineString)branch.Geometry, crossSectionCenter);
float limit;
if (map != null)
{
limit = (float)MapControlHelper.ImageToWorld(map, 1);
}
else
{
limit = (float)(0.1 * Math.Max(branch.Geometry.EnvelopeInternal.Width, branch.Geometry.EnvelopeInternal.Height));
}
if (distance < limit)
{
crossSection.Branch = branch;
CalculateCrossSectionOffset(crossSection);
CrossSectionHelper.UpdateDefaultGeometry(crossSection, crossSection.Geometry.Length / 2);
}
*/
}
return minDistance;
}