private void DockManager_PanelClosed(object sender, DotSpatial.Controls.Docking.DockablePanelEventArgs e)
 {
     if (e.ActivePanelKey == this.Key)
     {
         this.Focus = false;
     }
 }
Пример #2
0
        public IRaster Surface(DotSpatial.Data.Extent inExtents, double cellSize, DotSpatial.Projections.ProjectionInfo projection, double noDataValue, string outGridPath)
        {

            IRaster raster;
            // this.np=this.Search.MaxNumPoints;
            CreateGridFromExtents(inExtents, cellSize, projection, noDataValue, outGridPath, out raster);

            int nr = raster.NumRows;
            int nc = raster.NumColumns;

            for (int row = 0; row < nr; row++)
            {
                for (int col = 0; col < nc; col++)
                {
                    Coordinate cor = GetXYCell(raster, col, row);
                    double val = this.Interpolate(cor.X, cor.Y, cor.Z, true)[0];
                    raster.Value[row, col] = val;
                }
            }
            raster.Save();
            raster.Close();
            return raster;
        }
Пример #3
0
        private XPathNodeIterator CreateFields(XPathNavigator nav, DotSpatial.Topology.FeatureType type)
        {

            string exp = @"/wfs:FeatureCollection/child::*[name() = 'gml:featureMember' or name() = 'gml:featureMembers']/child::*";
            XPathNodeIterator iterator = nav.Select(exp, _nsmgr);
            fea = new FeatureSet(type);
            if (iterator.Count > 0)
            {
                foreach (string fieldName in fields.Keys)
                {
                    if (fieldName != Geometry)
                    {
                        fea.DataTable.Columns.Add(new DataColumn(fieldName, GetType(fieldName)));
                    }
                }
            }
            return iterator;
        }
Пример #4
0
        public static DotSpatial.Data.FeatureSet Execute(DotSpatial.Data.Raster rst, ContourType contourType, string FieldName = "Value", double[] levels = null)
        {
            double[] lev = levels;
            noData = rst.NoDataValue;
            type = contourType;
            DotSpatial.Data.Raster iRst = RasterCheck(rst, lev); ;

            string field;

            if (FieldName == null)
            {
                field = "Value";
            }
            else
            {
                field = FieldName;
            }

            double[] x = new double[rst.NumColumns];
            double[] y = new double[rst.NumRows];

            for (int i = 0; i < rst.NumColumns; i++)
            {
                x[i] = rst.Extent.MinX + rst.CellWidth * i + rst.CellWidth / 2;
            }

            for (int i = 0; i < rst.NumRows; i++)
            {
                y[i] = rst.Extent.MaxY - rst.CellHeight * i - rst.CellHeight / 2;
            }

            DotSpatial.Data.FeatureSet fs = null;

            switch (type)
            {
                case ContourType.Line:
                    {
                        fs = new DotSpatial.Data.FeatureSet(DotSpatial.Topology.FeatureType.Line);
                        fs.DataTable.Columns.Add(field, typeof(double));

                        for (int z = 0; z < levels.Count(); z++)
                        {
                            IList<IGeometry> cont = GetContours(ref iRst, x, y, lev[z]);

                            foreach (Geometry g in cont)
                            {
                                DotSpatial.Data.Feature f = (DotSpatial.Data.Feature)fs.AddFeature(ToDotSpatialLineString((ILineString)g));
                                f.DataRow[field] = lev[z];
                            }
                        }
                    }
                    break;

                case ContourType.Polygon:
                    {
                        fs = new DotSpatial.Data.FeatureSet(DotSpatial.Topology.FeatureType.Polygon);

                        fs.DataTable.Columns.Add("Lev", typeof(int));
                        fs.DataTable.Columns.Add("Label", typeof(string));

                        Collection<IGeometry> Contours = new Collection<IGeometry>();

                        for (int z = 0; z < levels.Count(); z++)
                        {
                            IList<IGeometry> cont = GetContours(ref iRst, x, y, lev[z]);

                            foreach (Geometry g in cont)
                            {
                                Contours.Add(new LineString(g.Coordinates));
                            }
                        }

                        Coordinate[] Boundary = new Coordinate[5];

                        Boundary[0] = new Coordinate(x[0], y[0]);
                        Boundary[1] = new Coordinate(x[0], y[rst.NumRows - 1]);
                        Boundary[2] = new Coordinate(x[rst.NumColumns - 1], y[rst.NumRows - 1]);
                        Boundary[3] = new Coordinate(x[rst.NumColumns - 1], y[0]);
                        Boundary[4] = new Coordinate(x[0], y[0]);
                        
                        Contours.Add(new LineString(Boundary));

                        Collection<IGeometry> NodedContours = new Collection<IGeometry>();
                        GeometryNoder geomNoder = new GeometryNoder(new PrecisionModel(1000d));

                        foreach (LineString c in geomNoder.Node(Contours))
                        {
                            NodedContours.Add(c);
                        }

                        Polygonizer polygonizer = new Polygonizer();
                        polygonizer.Add(NodedContours);

                        foreach (Polygon p in polygonizer.GetPolygons())
                        {

                            Point pnt = (Point)p.InteriorPoint;

                            int c = (int)((pnt.X - iRst.Extent.MinX) / iRst.CellWidth);
                            int r = (int)((iRst.Extent.MaxY - pnt.Y) / iRst.CellHeight);

                            double z = ((DotSpatial.Data.Raster)iRst).Value[r, c];

                            int Cls = GetLevel(z, lev);
                            string label = "Undefined";

                            if (Cls == -1) label = "< " + lev[0].ToString();
                            if (Cls == lev.Count()) label = "> " + lev[lev.Count() - 1].ToString();
                            if (Cls >= 0 & Cls < lev.Count()) label = lev[Cls].ToString() + " - " + lev[Cls + 1].ToString();

                            DotSpatial.Topology.Polygon dsp = ToDotSpatialPolygon(p);

                            DotSpatial.Data.Feature f = (DotSpatial.Data.Feature)fs.AddFeature(dsp);
                            f.DataRow["Lev"] = Cls;
                            f.DataRow["Label"] = label;
                        }
                    }
                    break;
            }

            return fs;
        }
Пример #5
0
        public static IList<IGeometry> GetContours(ref DotSpatial.Data.Raster rst, double[] x, double[] y, double zlev)
        {
            List<LineString> lsList = new List<LineString>();

            bool ipari, jpari;
            double[] xx = new double[3];
            double[] yy = new double[3];
            double[] zz = new double[3];

            for (int j = 0; j < rst.NumColumns - 1; j++)
            {
                if (((int)((double)j / 2.0)) * 2 == j)
                    jpari = true;
                else
                    jpari = false;

                for (int i = 0; i < rst.NumRows - 1; i++)
                {
                    if (((int)((double)i / 2.0)) * 2 == i)
                        ipari = true;
                    else
                        ipari = false;

                    if (!jpari && !ipari || jpari && ipari)
                    {
                        xx[0] = x[j];
                        yy[0] = y[i];
                        zz[0] = rst.Value[i, j];

                        xx[1] = x[j];
                        yy[1] = y[i + 1];
                        zz[1] = rst.Value[i + 1, j];

                        xx[2] = x[j + 1];
                        yy[2] = y[i];
                        zz[2] = rst.Value[i, j + 1];

                        {
                            Coordinate[] c = Intersect(xx, yy, zz, zlev);
                            if (c != null)
                            {
                                lsList.Add(new LineString(c));
                            }
                        }

                        xx[0] = x[j + 1];
                        yy[0] = y[i];
                        zz[0] = rst.Value[i, j + 1];

                        xx[1] = x[j];
                        yy[1] = y[i + 1];
                        zz[1] = rst.Value[i + 1, j];

                        xx[2] = x[j + 1];
                        yy[2] = y[i + 1];
                        zz[2] = rst.Value[i + 1, j + 1];

                        {
                            Coordinate[] c = Intersect(xx, yy, zz, zlev);
                            if (c != null)
                            {
                                lsList.Add(new LineString(c));
                            }
                        }
                    }

                    if (jpari && !ipari || !jpari && ipari)
                    {
                        xx[0] = x[j];
                        yy[0] = y[i];
                        zz[0] = rst.Value[i, j];

                        xx[1] = x[j];
                        yy[1] = y[i + 1];
                        zz[1] = rst.Value[i + 1, j];

                        xx[2] = x[j + 1];
                        yy[2] = y[i + 1];
                        zz[2] = rst.Value[i + 1, j + 1];

                        {
                            Coordinate[] c = Intersect(xx, yy, zz, zlev);
                            if (c != null)
                            {
                                lsList.Add(new LineString(c));
                            }
                        }

                        xx[0] = x[j];
                        yy[0] = y[i];
                        zz[0] = rst.Value[i, j];

                        xx[1] = x[j + 1];
                        yy[1] = y[i + 1];
                        zz[1] = rst.Value[i + 1, j + 1];

                        xx[2] = x[j + 1];
                        yy[2] = y[i];
                        zz[2] = rst.Value[i, j + 1];

                        {
                            Coordinate[] c = Intersect(xx, yy, zz, zlev);
                            if (c != null)
                            {
                                lsList.Add(new LineString(c));
                            }
                        }
                    }
                }
            }

            LineMerger lm = new LineMerger();

            lm.Add(lsList);

            IList<IGeometry> merged = (IList<IGeometry>)lm.GetMergedLineStrings();

            return merged;
        }
Пример #6
0
        public static DotSpatial.Data.Raster RasterCheck(DotSpatial.Data.Raster raster, double[] levels)
        {
            double eps = (raster.Maximum - raster.Minimum) / 1000;
            int n = levels.Count();

            DotSpatial.Data.Raster rst = raster;

            for (int i = 0; i <= rst.NumRows - 1; i++)
            {
                for (int j = 0; j <= rst.NumColumns - 1; j++)
                {
                    if (rst.Value[i, j] != rst.NoDataValue)
                    {
                        for (int l = 0; l < n; l++)
                        {
                            if (rst.Value[i, j] == levels[l])
                            {
                                rst.Value[i, j] += eps;
                            }
                        }
                    }
                }
            }

            return rst;
        }
Пример #7
0
        //public static int GetLevel(Polygon p, double[] lev)
        //{
        //    double zmin = double.MaxValue;
        //    double zmax = double.MinValue;

        //    foreach (Coordinate c in p.ExteriorRing.Coordinates)
        //    {
        //        if (c.Z < zmin) zmin = c.Z;
        //        if (c.Z > zmax) zmax = c.Z;
        //    }

        //    foreach (LineString ls in p.InteriorRings)
        //    {
        //        foreach (Coordinate c in ls.Coordinates)
        //        {
        //            if (c.Z < zmin) zmin = c.Z;
        //            if (c.Z > zmax) zmax = c.Z;
        //        }
        //    }

        //    if (zmin == zmax)
        //    {
        //        if (zmin == lev[0]) return -1;
        //        if (zmin == lev[lev.Count() - 1]) return lev.Count();
        //    }

        //    for (int i = 0; i < lev.Count(); i++)
        //    {
        //        if (lev[i] == zmin && lev[i + 1] == zmax)
        //        {
        //            return i;
        //        }
        //    }

        //     return -100;
        //}

        public static void CreateMinMaxEvery(DotSpatial.Data.Raster r, ContourType type, out double MinContour, out double MaxContour, out double every)
        {
            double min = r.Minimum;
            double max = r.Maximum;

            if (min == max)
            {
                min = Math.Floor(min);
                max = Math.Ceiling(max);
                if (min == max)
                {
                    max += 1;
                }
            }

            double dz = max - min;

            double Order = Math.Pow(10, Math.Floor(Math.Log10(dz)));

            if (Order == dz) Order /= 10;

            if (dz / Order < 2) Order /= 10;

            MinContour = Math.Floor(min / Order) * Order;
            MaxContour = Math.Ceiling(max / Order) * Order;

            if (MaxContour < max) MaxContour += Order;

            every = Order;

            if (type == ContourType.Line)
            {
                MinContour += every;
                MaxContour -= every;

                if (MaxContour <= MinContour)
                {
                    MaxContour = MinContour + every;
                }
            }
        }
Пример #8
0
        private void Reproject(DotSpatial.Projections.ProjectionInfo proj)
        {
            LogManager.DefaultLogManager.LogMessage(string.Format("Reprojecting from '{0}' to '{1};'", map.Projection.Name, proj.Name), DialogResult.OK);
            
            var extents = map.ViewExtents;
            var oldProjection = map.Projection;
            map.Projection = proj;
            var newExtents = Reproject(extents, oldProjection, map.Projection);

            foreach (var layer in map.Layers)
            {
                layer.Reproject(map.Projection);
            }

            map.ViewExtents = newExtents;
            map.Invalidate();
        }
Пример #9
0
 public void Reproject(DotSpatial.Projections.ProjectionInfo targetProjection)
 {
     //throw new NotImplementedException();
 }
Пример #10
0
 //event triggered when another panel is selected from tabs
 void DockManager_ActivePanelChanged(object sender, DotSpatial.Controls.Docking.DockablePanelEventArgs e)
 {
     if (e.ActivePanelKey == strPanelKey)
     {
         App.DockManager.SelectPanel(strPanelKey);
         App.HeaderControl.SelectRoot(strPanelKey);
     }
 }
Пример #11
0
        private void UpdateCurrentPosition(DotSpatial.Positioning.Position position)
        {
            if (position == null || position.IsEmpty || position.IsInvalid)
            {
                return;
            }

            this.CurrentPosition = position;
        }
Пример #12
0
        private void nmeaInterpreter1_SentenceReceived(object sender, DotSpatial.Positioning.Gps.Nmea.NmeaSentenceEventArgs e)
        {
            BeginInvoke(new MethodInvoker(delegate()
            {
                if (sentenceListBox.Items.Count >= 100)
                sentenceListBox.Items.RemoveAt(0);

                sentenceListBox.Items.Add(e.Sentence.ToString());
                sentenceListBox.SelectedIndex = sentenceListBox.Items.Count - 1;

                statusLabel.Text = "Receiving GPS data.";
            }));
        }
Пример #13
0
        void Layers_LayerAdded(object sender, DotSpatial.Symbology.LayerEventArgs e)
        {
            foreach (var layer in App.Map.Layers)
            {
                layer.IsSelected = false;
            }

            e.Layer.IsSelected = true;
            e.Layer.Checked = true;

            App.Legend.RefreshNodes();

            if (!(e.Layer is IMapImageLayer) && !(e.Layer is IMapRasterLayer))
            {
                var ext = e.Layer.Extent;
                ext.ExpandBy(ext.Width / 10, ext.Height / 10);
                App.Map.ViewExtents = ext;
                App.Map.Refresh();
            }
        }
Пример #14
-1
 public LayerGridItem(string image, string text, DotSpatial.Controls.IMapPolygonLayer layer)
 {
     InitializeComponent();
     this.ImagePath = image;
     _text = text;
     this.Layer = layer;
     this.Checkbox = this.checkBox1;
 }