Esempio n. 1
0
        /// <summary>
        /// Exports the shapes from the inputSF which fall within the given polygon, saving to the resultSF provided.
        /// </summary>
        /// <returns>False if an error occurs, true otherwise.</returns>
        public static bool SelectPointsWithPolygon(ref MapWinGIS.Shapefile inputSF, ref MapWinGIS.Shape polygon, ref MapWinGIS.Shapefile resultSF, bool SkipMWShapeID)
        {
            MapWinGIS.Utils utils     = new MapWinGIS.UtilsClass();
            int             numPoints = inputSF.NumShapes;
            int             shpIndex  = 0;

            if (Globals.CopyFields(ref inputSF, ref resultSF) == false)
            {
                return(false);
            }

            for (int i = 0; i <= numPoints - 1; i++)
            {
                MapWinGIS.Point currPt = new MapWinGIS.PointClass();
                currPt = inputSF.QuickPoint(i, 0);
                if (utils.PointInPolygon(polygon, currPt))
                {
                    shpIndex = resultSF.NumShapes;
                    if (resultSF.EditInsertShape(inputSF.get_Shape(i), ref shpIndex) == false)
                    {
                        gErrorMsg = "Problem inserting shape into result file: " + resultSF.get_ErrorMsg(resultSF.LastErrorCode);
                        Debug.WriteLine(gErrorMsg);
                        Error.SetErrorMsg(gErrorMsg);
                        return(false);
                    }
                    //add the table values
                    int numFields = resultSF.NumFields;
                    for (int j = 0; j <= numFields - 1; j++)
                    {
                        if (resultSF.EditCellValue(j, shpIndex, inputSF.get_CellValue(j, i)) == false)
                        {
                            gErrorMsg = "Problem inserting value into DBF table: " + resultSF.get_ErrorMsg(resultSF.LastErrorCode);
                            Debug.WriteLine(gErrorMsg);
                            Error.SetErrorMsg(gErrorMsg);
                            return(false);
                        }
                    }    //end of looping through table
                }        //end of checking if point is inside polygon
            }            //end of looping through points

            if (resultSF.NumShapes > 0)
            {
                if (resultSF.NumFields == 0 || !SkipMWShapeID)
                {
                    //add the ID field and values
                    if (Globals.DoInsertIDs(ref resultSF) == false)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the shape indexes of the shapes falling within the specified polygon.
        /// </summary>
        /// <returns>False if an error occurs, true otherwise.</returns>
        public static bool SelectPointsWithPolygon(ref MapWinGIS.Shapefile inputSF, ref MapWinGIS.Shape polygon, ref System.Collections.ArrayList results)
        {
            results = new System.Collections.ArrayList();
            MapWinGIS.Utils utils     = new MapWinGIS.UtilsClass();
            int             numPoints = inputSF.NumShapes;

            for (int i = 0; i <= numPoints - 1; i++)
            {
                MapWinGIS.Point currPt = new MapWinGIS.PointClass();
                currPt = inputSF.QuickPoint(i, 0);
                if (utils.PointInPolygon(polygon, currPt))
                {
                    results.Add(i);
                } //end of checking if point is inside polygon
            }     //end of looping through points

            return(results.Count > 0);
        }