Beispiel #1
0
        public static Point MakePoint(double x, double y)
        {
            var point = new Point();

            point.Set(x, y);
            return(point);
        }
Beispiel #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="origin"></param>
 /// <param name="dX"></param>
 /// <param name="dY"></param>
 public OffSet(MapWinGIS.Point origin, double dX, double dY)
 {
     this.origin   = origin;
     this.dX       = dX;
     this.dY       = dY;
     this.unitArea = (double)this.dX * this.dY;
 }
Beispiel #3
0
        private void SetLegendPositionFromCorner()
        {
            MapWinGIS.Point pt = new MapWinGIS.Point();
            switch (_legendCornerPosition)
            {
            case "topLeft":
                pt.x = Graticule.GraticuleExtents.xMin;
                pt.y = Graticule.GraticuleExtents.yMax;
                break;

            case "topRight":
                pt.x = Graticule.GraticuleExtents.xMax;
                pt.y = Graticule.GraticuleExtents.yMax;
                break;

            case "bottomLeft":
                pt.x = Graticule.GraticuleExtents.xMin;
                pt.y = Graticule.GraticuleExtents.yMin;
                break;

            case "bottomRight":
                pt.x = Graticule.GraticuleExtents.xMax;
                pt.y = Graticule.GraticuleExtents.yMin;
                break;
            }
            double pixelX = 0;
            double pixelY = 0;

            _mapControl.ProjToPixel(pt.x, pt.y, ref pixelX, ref pixelY);
            _legendAnchorCorner = new MapWinGIS.Point()
            {
                x = pixelX,
                y = pixelY
            };
        }
Beispiel #4
0
        private void toolStripButton1_Click_1(object sender, EventArgs e)
        {
            if (!listLabel.Visible)
            {
                MessageBox.Show("No Data!");
                return;
            }
            Shapefile sfTxt = mapControl.get_Shapefile(indexTxt);
            String    str   = "";

            for (int i = 0; i < sfTxt.NumShapes; i++)
            {
                ListViewItem item  = listLabel.Items[i];
                string       id    = item.SubItems[0].Text;
                string       label = item.SubItems[2].Text;
                str += id + "\n";
                str += label + "\n";
                Shape shpTmp = sfTxt.Shape[i];
                for (int j = 0; j < shpTmp.numPoints; j++)
                {
                    MapWinGIS.Point pnt = shpTmp.Point[j];
                    str += (j + 1).ToString() + " " + pnt.x.ToString() + " " + pnt.y.ToString() + "\n";
                }
                str += "\n";
            }

            saveDialog.ShowDialog();
            System.IO.File.WriteAllText(saveDialog.FileName, str);
            MessageBox.Show("Completed!");
        }
Beispiel #5
0
        private void AddPoint(AxMap Map, double lng, double lat, string pointName)
        {
            var sf = new Shapefile();

            if (PointShapefileLayerHandle != -1)
            {
                sf = Map.get_Shapefile(PointShapefileLayerHandle);
            }

            if (PointShapefileLayerHandle == -1)
            {
                if (!sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
                {
                    MessageBox.Show("Failed to create shapefile: " + sf.ErrorMsg[sf.LastErrorCode]);
                    return;
                }
                PointShapefileLayerHandle = Map.AddLayer(sf, true);
            }

            var utils = new Utils();
            ShapeDrawingOptions options = sf.DefaultDrawingOptions;

            options.PointType        = tkPointSymbolType.ptSymbolStandard;
            options.PointShape       = tkPointShapeType.ptShapeCross;
            options.FillColor        = utils.ColorByName(tkMapColor.Black);
            sf.DefaultDrawingOptions = options;
            sf.CollisionMode         = tkCollisionMode.AllowCollisions;


            Shape shp = new Shape();


            //shp = sf.get_Shape(shapeIndex);
            shp.Create(ShpfileType.SHP_POINT);



            MapWinGIS.Point pnt = new MapWinGIS.Point();
            pnt.x   = lng;
            pnt.y   = lat;
            pnt.Key = pointName;

            int Index;

            Index = shp.NumPoints;

            shp.InsertPoint(pnt, ref Index);

            Index = sf.NumShapes;

            if (!sf.EditInsertShape(shp, Index))
            {
                MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]);
                return;
            }

            points.Add(pnt);
            Map.Redraw();
        }
        double LineEquation(MapWinGIS.Point pt1, MapWinGIS.Point pt2, double x)
        {
            double y = 0;

            //http://mathworld.wolfram.com/Two-PointForm.html
            y = pt1.y + (pt2.y - pt1.y) / (pt2.x - pt1.x) * (x - pt1.x);
            return(y);
        }
Beispiel #7
0
        private void ShowLabelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                int    Attr_field;
                string LabelText;
                double x, y;

                int indx            = treeView1.SelectedNode.Index;
                int LayerHandlerlbl = axMap1.get_LayerHandle(indx);

                //Shapefile[] sf1 = new Shapefile[500];
                //sf1[LayerHandlerlbl] = new Shapefile();

                Shapefile sf = axMap1.get_Shapefile(LayerHandlerlbl);
                //sf1[LayerHandlerlbl] = axMap1.get_Shapefile(LayerHandlerlbl);

                sf.Labels.Visible = true;
                //sf1[LayerHandlerlbl].Labels.Visible = true;
                sf.Labels.Clear();

                Attr_field = 1; //Field (or column index in attribute table of the shapefile)
                for (int i = 0; i < sf.NumShapes; i++)
                //for (int i = 0; i < sf1[LayerHandlerlbl].NumShapes; i++)
                {
                    LabelText = sf.CellValue[Attr_field, i].ToString();

                    //LabelText = sf1[LayerHandlerlbl].CellValue[Attr_field, i].ToString();

                    if (sf.ShapefileType == ShpfileType.SHP_POLYGON)
                    {
                        MapWinGIS.Point pnt = sf.Shape[i].Centroid;
                        sf.Labels.AddLabel(LabelText, pnt.x, pnt.y);
                    }
                    else
                    {
                        x = (sf.Shape[i].Extents.xMin + sf.Shape[i].Extents.xMax) / 2;
                        y = (sf.Shape[i].Extents.yMin + sf.Shape[i].Extents.yMax) / 2;

                        sf.Labels.AddLabel(LabelText, x, y);
                    }

                    //MapWinGIS.Point pnt = sf1[LayerHandlerlbl].Shape[i].Centroid;

                    //sf1[LayerHandlerlbl].Labels.AddLabel(LabelText, pnt.x, pnt.y);
                    //MessageBox.Show(LabelText);
                }

                sf.Labels.Synchronized = true;
                //sf1[LayerHandlerlbl].Labels.Synchronized = true;
                axMap1.Redraw();
                //MessageBox.Show("Labeled!!!!");
            }
            catch
            {
            }
        }
        public Vertical_Profiling_Form(MapWinGIS.Image demImg, MapWinGIS.Point pt1, MapWinGIS.Point pt2)
        {
            this.InitializeComponent();
            //MapWinGIS.Point pt1 = new MapWinGIS.Point();
            //pt1.Set(0, 4);
            //MapWinGIS.Point pt2 = new MapWinGIS.Point();
            //pt2.Set(2, 0);

            int row1, col1;

            demImg.ProjectionToImage(pt1.x, pt1.y, out col1, out row1);
            int row2, col2;

            demImg.ProjectionToImage(pt2.x, pt2.y, out col2, out row2);
            var myModel = new PlotModel {
                Title = "Mặt cắt dọc"
            };

            //double step = 0.1;
            //int a_count = (int)Math.Abs((pt1.x - pt2.x) / step);
            //var plot3_Series = new LineSeries { StrokeThickness = 1, MarkerSize = 1 };
            //for (int i = 0; i < a_count; i++)
            //{
            //    int row;
            //    int column;
            //    double x_val = pt1.x + i*step;
            //    double y_val = LineEquation(pt1, pt2, x_val);
            //    demImg.ProjectionToImage(x_val, y_val, out column, out row);
            //    double yDEM = 0;
            //    demImg.Band[1].get_Value(column,row,out yDEM);
            //    plot3_Series.Points.Add(new DataPoint(x_val, yDEM));

            //}
            MapWinGIS.Point ptTmp1 = new MapWinGIS.Point();
            ptTmp1.Set(col1 + 0.5, row1 + 0.5);
            MapWinGIS.Point ptTmp2 = new MapWinGIS.Point();
            ptTmp2.Set(col2 + 0.5, row2 + 0.5);

            int a_count      = Math.Abs(col1 - col2);
            var plot3_Series = new LineSeries {
                StrokeThickness = 1, MarkerSize = 1
            };

            for (int i = 0; i < a_count; i++)
            {
                double x_val = col1 + i;
                double y_val = LineEquation(ptTmp1, ptTmp2, x_val);
                double yDEM  = 0;
                demImg.Band[1].get_Value((int)x_val, (int)y_val, out yDEM);
                demImg.ImageToProjection((int)x_val, (int)y_val, out x_val, out y_val);
                plot3_Series.Points.Add(new DataPoint(x_val, yDEM));
            }
            myModel.Series.Add(plot3_Series);

            this.plotView1.Model = myModel;
        }
Beispiel #9
0
        private void CreateShape(string path, DataTable dataTable)
        {
            Shapefile myShapefile;

            try
            {
                myShapefile = new Shapefile();
                string fileName     = Path.GetFileNameWithoutExtension(txtBox_excel.Text);
                string shapeilePath = Path.GetDirectoryName(path) + "\\" + fileName + ".shp";

                Directory.CreateDirectory(Path.GetDirectoryName(shapeilePath));

                myShapefile.CreateNew(shapeilePath, ShpfileType.SHP_POINT);
                //Create new field
                MapWinGIS.Field myField = new Field();
                //Set the field properties
                myField.Name  = "ID";
                myField.Type  = FieldType.INTEGER_FIELD;
                myField.Width = 10;
                //Add the filed for the shapefile table
                int intFieldIndex = 1;
                myShapefile.EditInsertField(myField, ref intFieldIndex, null);
                int myCounter    = 0;
                int myShapeIndex = 0;

                //First Create header
                CreateHeader(dataTable.Columns, myShapefile);
                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    MapWinGIS.Shape myShape = new Shape();
                    myShape.Create(ShpfileType.SHP_POINT);
                    MapWinGIS.Point myPoint = new MapWinGIS.Point();
                    myPoint.x = Convert.ToDouble(dataTable.Rows[i][x_Index]);
                    myPoint.y = Convert.ToDouble(dataTable.Rows[i][y_Index]);
                    object fld_Value    = dataTable.Rows[i][0];
                    int    myPointIndex = 0;
                    myShape.InsertPoint(myPoint, ref myPointIndex);
                    myShapefile.EditInsertShape(myShape, ref myShapeIndex);
                    myShapefile.EditCellValue(0, myShapeIndex, fld_Value);
                    CreatePointData(dataTable, myShapefile, myShapeIndex, i);
                    myShapeIndex++;
                    myCounter++;
                }
                GeoProjection proj = new GeoProjection();
                // EPSG code
                proj.ImportFromEPSG(4326);  // WGS84

                myShapefile.GeoProjection = proj;
                myShapefile.StopEditingShapes(true, true, null);
                myShapefile.Close();
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #10
0
        //Creates a shape file that contains all flights lat and long points and then generates a feald in the table that contains all flights images
        private void CreatePointShapefile()
        {
            axMap1.Projection   = tkMapProjection.PROJECTION_WGS84;
            axMap1.TileProvider = tkTileProvider.OpenStreetMap;
            var positions = pR.GetPositionsFromDB();
            var sfPoints  = new Shapefile();

            sfPoints.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
            // creating points and inserting them in the shape
            foreach (Position position in positions)
            {
                int count = 0;
                var pnt   = new Point();
                pnt.x = Convert.ToDouble(position.longitude);
                pnt.y = Convert.ToDouble(position.latitude);
                Shape shp = new Shape();
                shp.Create(ShpfileType.SHP_POINT);
                int index = 0;
                shp.InsertPoint(pnt, ref index);
                sfPoints.EditInsertShape(shp, ref count);
                count++;
            }
            var _idShape = axMap1.AddLayer(sfPoints, true);
            int indexo   = sfPoints.Table.FieldIndexByName["MWShapeId"];
            var names    = new HashSet <string>();

            for (int i = 0; i < sfPoints.Table.NumRows; i++)
            {
                names.Add(sfPoints.Table.CellValue[indexo, i].ToString());
            }
            string[] files = Directory.GetFiles(@"D:\Faks\Druga godina\Treci Semestar\Programiranje_u_NET_okolini\Konstrukcijska_Vjezba\FlightTracker\FlightTracker\Resources\imagesOfPlanes");
            foreach (string file in files)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                if (Path.GetExtension(file).ToLower() == ".png" && names.Contains(name))
                {
                    MapWinGIS.Image img = new MapWinGIS.Image();
                    if (img.Open(file, ImageType.USE_FILE_EXTENSION, true, null))
                    {
                        ShapefileCategory ct = new ShapefileCategory();
                        ct = sfPoints.Categories.Add(name);
                        ct.DrawingOptions.PointType     = tkPointSymbolType.ptSymbolPicture;
                        ct.DrawingOptions.PictureScaleX = 0.8;
                        ct.DrawingOptions.PictureScaleY = 0.8;
                        ct.DrawingOptions.DrawingMode   = tkVectorDrawingMode.vdmGDIPlus;
                        sfPoints.CollisionMode          = tkCollisionMode.AllowCollisions;
                        ct.Expression             = "[MWShapeId]=" + name;
                        ct.DrawingOptions.Picture = img;

                        sfPoints.DefaultDrawingOptions = ct.DrawingOptions;
                    }
                }
            }
            sfPoints.Categories.ApplyExpressions();
            axMap1.KnownExtents = tkKnownExtents.keCroatia;
        }
Beispiel #11
0
            /// <summary>
            /// Generate a point from a link's start position
            /// </summary>
            /// <param name="l">link</param>
            /// <returns>point</returns>
            private MapWinGIS.Point linkToPoint(Link l)
            {
                MapWinGIS.Point p = new MapWinGIS.Point();
                int             x, y;

                l.start(out x, out y);
                p.x = origin.x + dX * x;
                p.y = origin.y - dY * y;
                return(p);
            }
Beispiel #12
0
 /// <summary>
 /// Constructor from grid header
 /// </summary>
 /// <param name="h">header</param>
 public OffSet(MapWinGIS.GridHeader h)
 {
     // origin (taken as column zero and row zero) is at the top left of the grid
     this.origin   = new MapWinGIS.Point();
     this.origin.x = h.XllCenter - (h.dX / 2);
     this.origin.y = h.YllCenter - (h.dY / 2) + h.dY * h.NumberRows;
     this.dX       = h.dX;
     this.dY       = h.dY;
     this.unitArea = (double)this.dX * this.dY;
 }
Beispiel #13
0
        private void UpdatePoint(AxMap Map, List <MapWinGIS.Point> PointsToUpdate)
        {
            var sf = new Shapefile();

            if (PointShapefileLayerHandle != -1)
            {
                sf = Map.get_Shapefile(PointShapefileLayerHandle);
            }

            if (PointShapefileLayerHandle == -1)
            {
                if (!sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
                {
                    MessageBox.Show("Failed to create shapefile: " + sf.ErrorMsg[sf.LastErrorCode]);
                    return;
                }
                PointShapefileLayerHandle = Map.AddLayer(sf, true);
            }
            ShapeDrawingOptions options = sf.DefaultDrawingOptions;

            options.PointType        = tkPointSymbolType.ptSymbolStandard;
            options.PointShape       = tkPointShapeType.ptShapeCross;
            sf.DefaultDrawingOptions = options;
            sf.CollisionMode         = tkCollisionMode.AllowCollisions;
            sf.EditClear();

            foreach (MapWinGIS.Point PointToUpdate in PointsToUpdate)
            {
                Shape shp = new Shape();
                shp.Create(ShpfileType.SHP_POINT);
                MapWinGIS.Point pnt = PointToUpdate;

                int Index;
                Index = shp.NumPoints;

                shp.InsertPoint(pnt, ref Index);

                Index = sf.NumShapes;

                if (!sf.EditInsertShape(shp, Index))
                {
                    MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]);
                    return;
                }

                Map.Redraw();
            }
            if (PointsToUpdate.Count == 0)
            {
                Map.Redraw();
            }
        }
Beispiel #14
0
        /// <summary>
        /// convert point shapefile to grid
        /// </summary>
        private bool Point2Grid(MapWinGIS.Shapefile PointSf, int FldID, MapWinGIS.Grid Newgrd,
                                MapWinGIS.GridHeader header, MapWinGIS.GridDataType grType, MapWinGIS.ICallback cback)
        {
            //count the number of shapes
            int s;

            MapWinGIS.Shape shp;
            MapWinGIS.Point pt = new MapWinGIS.Point();
            object          val;
            GridPixel       px;
            int             nShps    = PointSf.NumShapes;
            int             perc     = 1;
            int             shpsPerc = NumPercentShapes(perc, nShps); //percent of progress

            for (s = 0; s < nShps; ++s)
            {
                //get the point
                shp = PointSf.get_Shape(s);

                //exclude shapes which are completely outside of the grid extents
                if (!IsGridContainsShape(shp, header))
                {
                    continue;
                }

                if (shp.numPoints > 0)
                {
                    pt = shp.get_Point(0);
                    if (pt != null)
                    {
                        //return the shape's value and write the pixel
                        val = GetCellValue(PointSf, FldID, s, header.NodataValue);
                        Newgrd.ProjToCell(pt.x, pt.y, out px.col, out px.row);
                        writePx(Newgrd, grType, px, val, cback);
                    }
                }

                //report the progress
                if (s >= shpsPerc)
                {
                    perc     = (int)((s * 100) / nShps);
                    shpsPerc = NumPercentShapes(perc + 1, nShps);
                    reportProgress(shpsPerc, nShps, "shapefile to grid", cback);
                }
            }
            return(true);
        }
        private static double GetAngle(IUtils utils, Point firstPoint, Point secondPoint)
        {
            var angle = utils.GetAngle(firstPoint, secondPoint);

            // convert to proper Cartesian angle of rotation
            angle = (450 - angle) % 360;
            // convert to Radians
            angle = angle * Math.PI / 180.0;

            // Get perpendicular angle:
            angle += 90 * Math.PI / 180.0;
            if (angle > 2 * Math.PI)
            {
                angle -= 2 * Math.PI;
            }

            return(angle);
        }
Beispiel #16
0
 private void axMap1_MouseDownEvent(object sender, AxMapWinGIS._DMapEvents_MouseDownEvent e)
 {
     if (PointF == 1 || PointF == 3)
     {
         double          xP     = 0;
         double          yP     = 0;
         Shapefile       sf     = new Shapefile();
         bool            result = sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
         MapWinGIS.Point pt     = new MapWinGIS.Point();
         axMap1.PixelToProj(e.x, e.y, ref xP, ref yP);
         pt.x           = xP;
         pt.y           = yP;
         comboBox1.Text = FindMinStop(xP, yP);
         Shape shp = new Shape();
         shp.Create(ShpfileType.SHP_POINT);
         shp.InsertPoint(pt, 0);
         sf.EditInsertShape(shp, 0);
         sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsStar);
         axMap1.AddLayer(sf, true);
         axMap1.SendMouseDown = false;
     }
     if (PointF == 2 || PointF == 4)
     {
         double          xP     = 0;
         double          yP     = 0;
         Shapefile       sf     = new Shapefile();
         bool            result = sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
         MapWinGIS.Point pt     = new MapWinGIS.Point();
         axMap1.PixelToProj(e.x, e.y, ref xP, ref yP);
         pt.x           = xP;
         pt.y           = yP;
         comboBox2.Text = FindMinStop(xP, yP);
         Shape shp = new Shape();
         shp.Create(ShpfileType.SHP_POINT);
         shp.InsertPoint(pt, 0);
         sf.EditInsertShape(shp, 0);
         sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsStar);
         axMap1.AddLayer(sf, true);
         axMap1.SendMouseDown = false;
     }
 }
Beispiel #17
0
        private MapWinGIS.Point GetFrameTopLeft(double[] y, double[] x)
        {
            MapWinGIS.Point pt = new MapWinGIS.Point();
            double          top = 0; double left = 0;

            for (int n = 0; n < y.Length; n++)
            {
                if (n == 0)
                {
                    top = y[n];
                }
                else
                {
                    if (y[n] < top)
                    {
                        top = y[n];
                    }
                }
            }

            for (int n = 0; n < x.Length; n++)
            {
                if (n == 0)
                {
                    left = x[n];
                }
                else
                {
                    if (x[n] < left)
                    {
                        left = x[n];
                    }
                }
            }
            pt.y = top;
            pt.x = LegendAnchorCorner.x;
            return(pt);
        }
Beispiel #18
0
 private void mapControl_MeasuringChanged(object sender, _DMapEvents_MeasuringChangedEvent e)
 {
     if (e.action == tkMeasuringAction.MesuringStopped)
     {
         Shape shp = new Shape();
         shp.Create(ShpfileType.SHP_POLYGON);
         //shp_tmp.EditAddShape()
         double x, y;
         for (int i = 0; i < mapControl.Measuring.PointCount; i++)
         {
             if (mapControl.Measuring.get_PointXY(i, out x, out y))
             {
                 MapWinGIS.Point ptn = new MapWinGIS.Point();
                 ptn.Set(x, y);
                 shp.InsertPoint(ptn, ref i);
             }
         }
         Shapefile sfTmp = mapControl.get_Shapefile(currentLayerIndex);
         sfTmp.EditAddShape(shp);
         MessageBox.Show(sfTmp.NumShapes.ToString());
         mapControl.Redraw();
     }
 }
Beispiel #19
0
 private void MainMap_MouseDownEvent(object sender, AxMapWinGIS._DMapEvents_MouseDownEvent e)
 {
     if (e.button == 1)          // left button
     {
         Shapefile sf  = MainMap.get_Shapefile(m_layerHandle);
         Shape     shp = new Shape();
         shp.Create(ShpfileType.SHP_POINT);
         MapWinGIS.Point pnt = new MapWinGIS.Point();
         double          x   = 0.0;
         double          y   = 0.0;
         MainMap.PixelToProj(e.x, e.y, ref x, ref y);
         pnt.x = x;
         pnt.y = y;
         int index = shp.numPoints;
         shp.InsertPoint(pnt, ref index);
         index = sf.NumShapes;
         if (!sf.EditInsertShape(shp, ref index))
         {
             MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]);
             return;
         }
         MainMap.Redraw();
     }
 }
Beispiel #20
0
        private void mapControl_MouseDownEvent(object sender, _DMapEvents_MouseDownEvent e)
        {
            if (e.button == 2 && listLabel.Visible)
            {
                ListViewItem   x     = listLabel.Items[listLabel.SelectedIndices[0]];
                string         type  = x.SubItems[1].Text;
                FormEnterLabel enter = new FormEnterLabel(preSelectedShape.ToString(), type);
                enter.ShowDialog();
                string   str_    = enter.label;
                String[] rowData = new String[3];
                rowData[0] = preSelectedShape.ToString();
                rowData[1] = type;
                rowData[2] = str_;

                ListViewItem item = new ListViewItem(rowData);
                listLabel.Items.RemoveAt(preSelectedShape);
                listLabel.Items.Insert(preSelectedShape, item);
            }


            if (!toolGetValues.Checked)
            {
                return;
            }
            Shape shp = new Shape();

            if (e.button == 1)          // left button
            {
                Shapefile sf = mapControl.get_Shapefile(mapControl.NumLayers - 1);

                shp.Create(ShpfileType.SHP_POINT);
                MapWinGIS.Point pnt = new MapWinGIS.Point();
                double          x   = 0.0;
                double          y   = 0.0;
                mapControl.PixelToProj(e.x, e.y, ref x, ref y);
                Console.WriteLine(x.ToString() + "," + y.ToString());
                pnt.x = x;
                pnt.y = y;
                int index = shp.numPoints;
                shp.InsertPoint(pnt, ref index);
                index = sf.NumShapes;
                if (!sf.EditInsertShape(shp, ref index))
                {
                    MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]);
                    return;
                }
                mapControl.Redraw();
            }
            else
            {
                return;
            }


            int row;
            int column;

            double X = 0;
            double Y = 0;

            mapControl.PixelToProj(e.x, e.y, ref X, ref Y);
            MapWinGIS.Image img = mapControl.get_Image(0);
            img.ProjectionToImage(X, Y, out column, out row);
            double[] vals = new double[img.NoBands];
            for (int i = 1; i <= img.NoBands; i++)
            {
                GdalRasterBand rst = img.get_Band(i);
                double         pVal;
                rst.get_Value(row, column, out pVal);
                vals[i - 1] = pVal;
            }

            FormRasterValue uiRasterValues = new FormRasterValue(vals);

            uiRasterValues.ShowDialog();
            shp.Clear();
        }
Beispiel #21
0
        private void loadPolygonFromTextToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            List <MapWinGIS.Point> coords = new List <MapWinGIS.Point>();
            string file_txt = openDialog.FileName;

            string[] lines = System.IO.File.ReadAllLines(file_txt);
            for (int i = 0; i < lines.Length; i++)
            {
                MapWinGIS.Point pTmp = new MapWinGIS.Point();
                string          line = lines[i];
                if (line != "")
                {
                    string[] arr_line = line.Split(' ');
                    double   latt     = Convert.ToDouble(arr_line[1]);
                    double   longt    = Convert.ToDouble(arr_line[2]);
                    pTmp.x = latt;
                    pTmp.y = longt;
                }
                else
                {
                    pTmp.x = 0.0;
                    pTmp.y = 0.0;
                }

                coords.Add(pTmp);
            }

            // Create Shaefile load Polygon
            var  sfPoly = new Shapefile();
            bool result = sfPoly.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON);

            if (!result)
            {
                MessageBox.Show(sfPoly.ErrorMsg[sfPoly.LastErrorCode]);
            }
            else
            {
                Shape shpPoly = new Shape();
                shpPoly.Create(ShpfileType.SHP_POLYGON);
                int numberPoly = 0;
                int numPoint   = 0;
                for (int i = 0; i < coords.Count; i++)
                {
                    if (coords[i].x == 0.0)
                    {
                        if (i != 0)
                        {
                            sfPoly.EditInsertShape(shpPoly, ref numberPoly);
                            numberPoly += 1;
                        }
                        numPoint = 0;

                        shpPoly = new Shape();
                        shpPoly.Create(ShpfileType.SHP_POLYGON);
                    }
                    else
                    {
                        shpPoly.InsertPoint(coords[i], ref numPoint);
                        numPoint += 1;
                    }
                }
                sfPoly.EditInsertShape(shpPoly, ref numberPoly);
            }


            indexTxt = mapControl.AddLayer(sfPoly, true);
            // Add to Tree
            treeLayers.CheckBoxes  = true;
            treeLayers.AfterCheck += treeLayer_AfterCheck;
            TreeNode layerNode = new TreeNode("Polygon from Text");

            layerNode.Checked = true;
            treeLayers.Nodes[0].Nodes.Add(layerNode);
            layerNode.Parent.Checked = true;
        }
Beispiel #22
0
        public bool SetUpFrame()
        {
            double[] x = new double[5];
            double[] y = new double[5];
            switch (MapLegendPosition)
            {
            case MapLegendPosition.PositionFromCorner:
                switch (LegendCornerPosition)
                {
                case "topLeft":
                    x[0] = LegendAnchorCorner.x;
                    y[0] = LegendAnchorCorner.y;

                    x[1] = LegendAnchorCorner.x + Width;
                    y[1] = LegendAnchorCorner.y;

                    x[2] = LegendAnchorCorner.x + Width;
                    y[2] = LegendAnchorCorner.y + 100;

                    x[3] = LegendAnchorCorner.x;
                    y[3] = LegendAnchorCorner.y + 100;

                    x[4] = LegendAnchorCorner.x;
                    y[4] = LegendAnchorCorner.y;
                    break;

                case "topRight":

                    break;

                case "bottomLeft":

                    break;

                case "bottomRight":

                    break;
                }
                break;

            case MapLegendPosition.PositionFromDefinedExtent:
                break;
            }
            object xObj = x;
            object yObj = y;

            _mapControl.DrawWidePolygonEx(_hLegend, ref xObj, ref yObj, 5, new Utils().ColorByName(tkMapColor.White), true, 2);
            _mapControl.DrawWidePolygonEx(_hLegend, ref xObj, ref yObj, 5, BorderColor, false, 2);
            MapWinGIS.Point topLeft = GetFrameTopLeft(y, x);

            var lbls = _mapControl.get_DrawingLabels(_hLegend);
            var cat  = lbls.AddCategory("Legend");

            cat.FontBold     = true;
            cat.FrameVisible = false;
            cat.FontSize     = 12;
            cat.Alignment    = tkLabelAlignment.laCenterRight;
            if (lbls != null)
            {
                lbls.AddLabel(Caption, topLeft.x + Padding, topLeft.y + Padding, 0, 0);
            }

            return(x.Length > 0 && y.Length > 0);
        }
Beispiel #23
0
        /// <summary>
        /// convert point shapefile to grid
        /// </summary>   
        private bool Point2Grid(MapWinGIS.Shapefile PointSf, int FldID, MapWinGIS.Grid Newgrd,
            MapWinGIS.GridHeader header, MapWinGIS.GridDataType grType, MapWinGIS.ICallback cback)
        {
            //count the number of shapes
            int s;
            MapWinGIS.Shape shp;
            MapWinGIS.Point pt = new MapWinGIS.Point();
            object val;
            GridPixel px;
            int nShps = PointSf.NumShapes;
            int perc = 1;
            int shpsPerc = NumPercentShapes(perc, nShps); //percent of progress

            for (s = 0; s < nShps; ++s)
            {
            //get the point
            shp = PointSf.get_Shape(s);

            //exclude shapes which are completely outside of the grid extents
            if (!IsGridContainsShape(shp, header))
            {
                continue;
            }

            if (shp.numPoints > 0)
            {
                pt = shp.get_Point(0);
                if (pt != null)
                {
                    //return the shape's value and write the pixel
                    val = GetCellValue(PointSf, FldID, s, header.NodataValue);
                    Newgrd.ProjToCell(pt.x, pt.y, out px.col, out px.row);
                    writePx(Newgrd, grType, px, val, cback);
                }
            }

            //report the progress
            if (s >= shpsPerc)
            {
                perc = (int)((s * 100) / nShps);
                shpsPerc = NumPercentShapes(perc + 1, nShps);
                reportProgress(shpsPerc, nShps, "shapefile to grid", cback);
            }
            }
            return true;
        }
Beispiel #24
0
 /// <summary>
 /// Constructor, making an empty dictionary, and setting offset
 /// from origin and cell dimensions
 /// </summary>
 public ManhattanShapes(MapWinGIS.Point p, double dX, double dY)
 {
     ShapesTable = new Dictionary <int, Data>();
     offset      = new OffSet(p, dX, dY);
 }