Ejemplo 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);
            }
        }
Ejemplo 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);
        }
Ejemplo n.º 3
0
        private void AddLayer()
        {
            MapWinGIS.Shapefile shpfileOpen;
            string[] fileNombres;

            MapWinGIS.Grid grid;
            MapWinGIS.GridColorScheme gridScheme;
            MapWinGIS.Image image;
            MapWinGIS.Utils utils;

            OpenFileDialog openDlg = new OpenFileDialog();
            openDlg.Multiselect = true;

            int handle;
            string ext;

            //initialize dialog
            openDlg.Filter = "Supported Formats|*.shp;*.bgd;*asc;*.jpg|Shapefile (*.shp)|*.shp|Binary Grids (*.bgd)|*.bgd|ASCII Grids (*.asc)|*.asc |World File (*.jpg)|*.jpg";
            openDlg.CheckFileExists = true;

            if (openDlg.ShowDialog(this) == DialogResult.OK)
            {
                fileNombres = openDlg.FileNames;
                int totalNombres = fileNombres.Length;
                for (int j = 0; j < totalNombres; j++)
                {

                    //get the extension of the file
                    ext = System.IO.Path.GetExtension(openDlg.FileNames[j]);

                    if (ext == ".bgd" || ext == ".asc" || ext == ".jpg")
                    {
                        if (ext == ".jpg")
                        {
                            image = new MapWinGIS.Image();

                            // open image world file
                            image.Open(openDlg.FileNames[j], MapWinGIS.ImageType.JPEG_FILE, true, null);
                            handle = legend1.Layers.Add(image, true);
                            legend1.Map.set_LayerName(handle, System.IO.Path.GetFileNameWithoutExtension(image.Filename));
                            //handle = axMap1.AddLayer(image, true);
                            handleMap.Add(handle);

                        }
                        else
                        {

                            utils = new MapWinGIS.UtilsClass();
                            gridScheme = new MapWinGIS.GridColorScheme();
                            grid = new MapWinGIS.GridClass();

                            //open the grid
                            grid.Open(openDlg.FileName, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, null);

                            //create a coloring scheme for the image
                            gridScheme.UsePredefined(System.Convert.ToDouble(grid.Minimum), System.Convert.ToDouble(grid.Maximum), MapWinGIS.PredefinedColorScheme.SummerMountains);

                            //convert the grid to a image
                            image = utils.GridToImage(grid, gridScheme, null);

                            //add the image to the legend and map
                            handle = axMap1.AddLayer(image, true);
                            handleMap.Add(handle);

                            grid.Close();

                            //utils = new MapWinGIS.UtilsClass();
                            //gridScheme = new MapWinGIS.GridColorScheme();
                            //grid = new MapWinGIS.GridClass();

                            ////open the grid
                            //grid.Open(openDlg.FileName, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, null);

                            ////create a coloring scheme for the image
                            //gridScheme.UsePredefined(System.Convert.ToDouble(grid.Minimum), System.Convert.ToDouble(grid.Maximum), MapWinGIS.PredefinedColorScheme.SummerMountains);

                            ////convert the grid to a image
                            //image = utils.GridToImage(grid, gridScheme, null);

                            ////add the image to the legend and map
                            //handle = axMap1.AddLayer(image, true);
                            ////handle = legend1.Layers.Add(image, true);

                            //if (legend1.Layers.IsValidHandle(handle))
                            //{
                            //    //set the layer name
                            //    legend1.Map.set_LayerName(handle, System.IO.Path.GetFileNameWithoutExtension(grid.Filename));

                            //    //set's the legend layer type, this displays a default icon in the legend (line shapefile, point shapefile,polygon shapefile,grid,image)
                            //    legend1.Layers.ItemByHandle(handle).Type = MapWindow.Interfaces.eLayerType.Grid;

                            //    //set coloring scheme
                            //    //when applying a coloring scheme to a shapfile use axMap1.ApplyLegendColors(ShapefileColorScheme)
                            //    //when applying a coloring scheme for a grid or image use axMap1.SetImageLayerColorScheme(handle,GridColorScheme);
                            //    axMap1.SetImageLayerColorScheme(legend1.SelectedLayer, gridScheme);
                            //    legend1.Layers.ItemByHandle(legend1.SelectedLayer).Refresh();
                            //}

                            //close the grid
                            //grid.Close();
                        }

                    }
                    else if (ext == ".shp")
                    {
                        shpfileOpen = new MapWinGIS.ShapefileClass();

                        //open the shapefile
                        shpfileOpen.Open(openDlg.FileNames[j], null);

                        //add the shapefile to the map and legend
                        handle = legend1.Layers.Add(shpfileOpen, true);
                        legend1.Map.set_LayerName(handle, System.IO.Path.GetFileNameWithoutExtension(shpfileOpen.Filename));
                        //handle = axMap1.AddLayer(shpfileOpen, true);
                        handleMap.Add(handle);
                        string oldProj = shpfileOpen.Projection;

                        // bool status = MapWinGeoProc.SpatialReference.ProjectShapefile(sourceProj, destProj, inputSF, resultSF)
                        this.flagMapaAbierto = true;

                    }
                }

            }
        }