示例#1
0
        /// <summary>
        /// Removes portions of the input line shapefile that fall within the polygons of the erase polygon shapefile.
        /// </summary>
        /// <param name="inputSF">The line shapefile to erase.</param>
        /// <param name="eraseSF">The polygon shapefile that will be used to erase portions of the line shapefile.</param>
        /// <param name="resultSF">The result shapefile.</param>
        /// <returns>False if an error was encountered, true otherwise.</returns>
        public static bool EraseLineSFWithPolySF(ref MapWinGIS.Shapefile inputSF, ref MapWinGIS.Shapefile eraseSF, ref MapWinGIS.Shapefile resultSF)
        {
            MapWinUtility.Logger.Dbg("EraseLineSFWithPolySF(inputSF: " + Macro.ParamName(inputSF) + "\n" +
                                     "                      eraseSF: " + Macro.ParamName(eraseSF) + "\n" +
                                     "                      resultSF: " + Macro.ParamName(resultSF) + ")");

            if (inputSF == null || eraseSF == null || resultSF == null)
            {
                gErrorMsg = "One of the input parameters is null.";
                Error.SetErrorMsg(gErrorMsg);
                Debug.WriteLine(gErrorMsg);
                MapWinUtility.Logger.Dbg(gErrorMsg);
                return(false);
            }
            bool status = true;

            MapWinGIS.Shapefile tempInput = new MapWinGIS.ShapefileClass();
            string tempFile = System.IO.Path.GetTempPath() + "tempLineResult.shp";

            //CDM 8/4/2006 tempInput.CreateNew(tempFile, inputSF.ShapefileType);
            Globals.PrepareResultSF(ref tempFile, ref tempInput, inputSF.ShapefileType);
            tempInput.StartEditingShapes(true, null);
            int shpIndex  = 0;
            int numInputs = inputSF.NumShapes;

            for (int i = 0; i <= numInputs - 1; i++)
            {
                tempInput.EditInsertShape(inputSF.get_Shape(i), ref shpIndex);
                shpIndex++;
            }

            int numErase = eraseSF.NumShapes;

            for (int i = 0; i <= numErase - 1; i++)
            {
                Debug.WriteLine("Num shapes in tempInput = " + tempInput.NumShapes);
                MapWinGIS.Shape eraseShp = new MapWinGIS.ShapeClass();
                eraseShp = eraseSF.get_Shape(i);
                resultSF.EditClear();
                status = EraseLineSFWithPoly(ref tempInput, ref eraseShp, ref resultSF, false);
                if (i != numErase - 1)
                {
                    int numResults = resultSF.NumShapes;
                    if (numResults > 0)
                    {
                        tempInput.EditClear();
                        shpIndex = 0;
                        for (int j = 0; j <= numResults - 1; j++)
                        {
                            tempInput.EditInsertShape(resultSF.get_Shape(j), ref shpIndex);
                            shpIndex++;
                        }
                    }
                }
            }
            MapWinUtility.Logger.Dbg("Finished EraseLineSFWithPolySF");
            return(status);
        }