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


C# IFeature.Crosses方法代码示例

本文整理汇总了C#中IFeature.Crosses方法的典型用法代码示例。如果您正苦于以下问题:C# IFeature.Crosses方法的具体用法?C# IFeature.Crosses怎么用?C# IFeature.Crosses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFeature的用法示例。


在下文中一共展示了IFeature.Crosses方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Accurate_ClipPolygonWithLine

        /// <summary>
        /// Accurate Clip Polygon with Line
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="line"></param>
        /// <param name="resultFeatureSet"></param>
        /// <returns></returns>
        public static bool Accurate_ClipPolygonWithLine(
            ref IFeature polygon, ref IFeature line, ref IFeatureSet resultFeatureSet)
        {
            if (polygon != null && line != null)
            {
                bool boundsIntersect = line.Crosses(polygon);
                if (boundsIntersect == false)
                {
                    return false;
                }

                // find if all of the line is inside, outside, or part in and out of polygon
                // line might intersect polygon mutliple times
                int numPoints = line.NumPoints;
                bool[] ptsInside = new bool[numPoints];
                int numInside = 0;
                int numOutside = 0;
                int numParts = polygon.NumPoints;
                if (numParts == 0)
                {
                    numParts = 1;
                }

                Coordinate[][] polyVertArray = new Coordinate[numParts][];
                ConvertPolyToVertexArray(ref polygon, ref polyVertArray);

                // check each point in the line to see if the entire line is either
                // inside of the polygon or outside of it (we know it's inside polygon bounding box).
                for (int i = 0; i <= numPoints - 1; i++)
                {
                    Point currPt = new Point(line.Coordinates[i]);
                    if (polygon.Covers(currPt))
                    {
                        ptsInside[i] = true;
                        numInside += 1;
                    }
                    else
                    {
                        ptsInside[i] = false;
                        numOutside += 1;
                    }
                }

                if (numInside == numPoints)
                {
                    // case: all points are inside polygon - check for possible intersections
                    if (ProcessAllInside(ref line, ref polygon, ref resultFeatureSet) == false)
                    {
                        return false;
                    }
                }
                else if (numOutside == numPoints)
                {
                    // case: all points are outside of the polygon - check for possible intersections
                    if (ProcessAllOutside(ref line, ref polygon, ref resultFeatureSet) == false)
                    {
                        return false;
                    }
                }
                else
                {
                    // case: part of line is inside and part is outside - find inside segments.
                    if (ProcessPartInAndOut(ref ptsInside, ref line, ref polygon, ref resultFeatureSet) == false)
                    {
                        return false;
                    }
                }
            }
            else
            {
                return false;
            }

            return true;
        }
开发者ID:DIVEROVIEDO,项目名称:DotSpatial,代码行数:82,代码来源:ClipPolygonWithLine.cs


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