Example #1
0
 public Polygon(DotSpatial.Topology.Polygon polygon)
 {
     rings = new List <Ring>();
     rings.Add(new Ring(polygon.Shell));
     foreach (var hole in polygon.Holes)
     {
         rings.Add(new Ring(hole));
     }
 }
Example #2
0
        public static DotSpatial.Topology.Geometry toDotSpatial(Geometry l)
        {
            if (l.GeometryType == "LineString")
            {
                return(ToDotSpatialLineString((ILineString)l));
            }

            if (l.GeometryType == "Polygon")
            {
                Polygon p = l as Polygon;

                DotSpatial.Topology.Polygon dsp = ToDotSpatialPolygon((GeoAPI.Geometries.IPolygon)l);
                return((DotSpatial.Topology.Geometry)dsp);
            }

            return(null);
        }
Example #3
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.Length; z++)
                {
                    IList <IGeometry> cont = GetContours(ref iRst, x, y, lev[z]);

                    foreach (var g in cont)
                    {
                        var 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 (var 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 (var c in geomNoder.Node(Contours))
                {
                    NodedContours.Add(c);
                }

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

                foreach (IPolygon 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);
        }