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


C# IFeature.Covers方法代码示例

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


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

示例1: Fast_ClipPolygonWithLine

        /// <summary>
        /// For faster clipping of polygons with lines. Limits the finding of intersections to
        /// outside->inside or inside->outside 2pt segments. Assumes only one intersections exists
        /// per segment, that a segment of two inside points or two outside points will not intersect
        /// the polygon.
        /// </summary>
        /// <param name="polygon">The polygon that will be sectioned by the line.</param>
        /// <param name="line">The line that will clip the polygon into multiple parts.</param>
        /// <param name="resultFeatureSet">The in-memory shapefile where the polygon sections will be saved.</param>
        /// <returns>False if errors are encountered, true otherwise.</returns>
        public static bool Fast_ClipPolygonWithLine(
            ref IFeature polygon, ref IFeature line, ref IFeatureSet resultFeatureSet)
        {
            IFeatureSet resultFile = new FeatureSet(FeatureType.Polygon);
            if (polygon != null && line != null)
            {
                // make sure we are dealing with a valid shapefile type
                if (polygon.FeatureType == FeatureType.Polygon)
                {
                    // create the result shapefile if it does not already exist
                    if (!polygon.Overlaps(line))
                    {
                        resultFeatureSet = resultFile;
                        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.NumGeometries;
                    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;
                        }
                    }

                    // case: all points are inside polygon - check for possible intersections
                    if (numInside == numPoints)
                    {
                        // assume no intersections exist in fast version
                    }
                    else if (numOutside == numPoints)
                    {
                        // case: all points are outside of the polygon - check for possible intersections
                        // assume no intersections exist in fast version
                    }
                    else
                    {
                        // case: part of line is inside and part is outside - find inside segments.
                        if (Fast_ProcessPartInAndOut(ptsInside, line, polygon, resultFile) == false)
                        {
                            resultFeatureSet = resultFile;
                            return false;
                        }
                    }

                    // resultSF result file, do not save to disk.
                    resultFeatureSet = resultFile;
                }
                else
                {
                    resultFeatureSet = resultFile;
                    return false;
                }
            }
            else
            {
                // polygon or line is invalid
                resultFeatureSet = resultFile;
                return false;
            }

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

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