当前位置: 首页>>代码示例>>C#>>正文


C# ILineString.Distance方法代码示例

本文整理汇总了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;
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:68,代码来源:GeometryHelper.cs


注:本文中的ILineString.Distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。