Exemplo n.º 1
0
        /// <summary>
        /// Removes points from the point shapefile that lie within any shapes in the polygon shapefile.
        /// </summary>
        /// <param name="pointSF">The point shapefile.</param>
        /// <param name="polygonSF">The shapefile containing the erase polygons.</param>
        /// <param name="resultSF">The resulting file with points removed.</param>
        /// <returns>False if an error was encountered, true otherwise.</returns>
        public static bool ErasePointSFWithPolySF(ref MapWinGIS.Shapefile pointSF, ref MapWinGIS.Shapefile polygonSF, ref MapWinGIS.Shapefile resultSF)
        {
            MapWinUtility.Logger.Dbg("ErasePointSFWithPolySF(pointSF : " + Macro.ParamName(pointSF) + ",\n" +
                                     "                       polygonSF: " + Macro.ParamName(polygonSF) + ",\n" +
                                     "                       resultSF: " + resultSF.ToString());
            if (pointSF == null || polygonSF == null || resultSF == null)
            {
                gErrorMsg = "One of the input parameters is null.";
                Error.SetErrorMsg(gErrorMsg);
                Debug.WriteLine(gErrorMsg);
                MapWinUtility.Logger.Dbg(gErrorMsg);
                return(false);
            }
            int shpIndex = 0;
            int numPts   = pointSF.NumShapes;

            for (int i = 0; i <= numPts - 1; i++)
            {
                shpIndex = resultSF.NumShapes;
                resultSF.EditInsertShape(pointSF.get_Shape(i), ref shpIndex);
            }

            int numPolygons = polygonSF.NumShapes;

            for (int i = 0; i <= numPolygons - 1; i++)
            {
                MapWinGIS.Shape currPoly = new MapWinGIS.ShapeClass();
                currPoly.Create(polygonSF.ShapefileType);
                currPoly = polygonSF.get_Shape(i);
                int numParts = currPoly.NumParts;
                if (numParts == 0)
                {
                    numParts = 1;
                }
                Globals.Vertex[][] polyVertArray = new Globals.Vertex[numParts][];
                Globals.ConvertPolyToVertexArray(ref currPoly, out polyVertArray);

                numPts = resultSF.NumShapes;
                for (int j = 0; j <= numPts - 1; j++)
                {
                    double x = resultSF.QuickPoint(j, 0).x;
                    double y = resultSF.QuickPoint(j, 0).y;
                    if (Utils.PointInPoly(ref polyVertArray, x, y) == true)
                    {
                        //remove the point.
                        resultSF.EditDeleteShape(j);
                        numPts--;
                        j--;
                    }
                }
            }
            MapWinUtility.Logger.Dbg("Finsihed ErasePointSFWithPolySF");
            return(true);
        }