Beispiel #1
0
        /// <summary>
        /// Ogr to DotSpatial at layer level
        /// </summary>
        /// <param name="layer">Ogr Layer</param>
        /// <returns>DotSpatial IFeatureSet</returns>
        public static DotSpatial.Data.IFeatureSet Ogr2DSLayer(OSGeo.OGR.Layer layer)
        {
            DotSpatial.Data.IFeatureSet featureSet = new DotSpatial.Data.FeatureSet();
            featureSet.FeatureType = Ogr2DSGeometryType(layer.GetGeomType());
            featureSet.DataTable   = Ogr2DSDataTable(layer.GetLayerDefn());
            featureSet.Projection  = Ogr2DSProjection(layer.GetSpatialRef());

            for (int i = 0; i < layer.GetFeatureCount(0); i++)
            {
                OSGeo.OGR.Geometry       geometry   = layer.GetFeature(i).GetGeometryRef();
                DotSpatial.Data.IFeature feature    = new DotSpatial.Data.Feature(Ogr2DSGeometry(geometry));
                OSGeo.OGR.Feature        ogrFeature = layer.GetFeature(i);
                feature.DataRow = featureSet.DataTable.NewRow();
                for (int j = 0; j < layer.GetLayerDefn().GetFieldCount(); j++)
                {
                    object value = GetOgrValue(ogrFeature, j);
                    if (value == null)
                    {
                        value = DBNull.Value;
                    }
                    feature.DataRow[j] = value;
                }
                featureSet.Features.Add(feature);
            }

            return(featureSet);
        }
Beispiel #2
0
        public static DotSpatial.Data.FeatureSet ToDotSpatialData(IEnumerable <GPSTrajectory> trajs)
        {
            DotSpatial.Data.FeatureSet fs = new DotSpatial.Data.FeatureSet(DotSpatial.Topology.FeatureType.Line);
            fs.Name = "GPSShapefile";
            fs.DataTable.Columns.Add("UserId", typeof(int));
            foreach (var item in trajs)
            {
                var fe = fs.AddFeature(item.LineString);
                fe.DataRow.BeginEdit();
                fe.DataRow["UserId"] = item.UserID;
                fe.DataRow.EndEdit();
            }

            return(fs);
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            LayerName = comboBoxLayerList.Text;

            max = (double)numericUpDownMax.Value;
            min = (double)numericUpDownMin.Value;
            eve = (double)numericUpDownEvery.Value;

            contourtype = GetSelectedType();

            lev = Contour.CreateLevels(min, max, eve);

            Contours            = Contour.Execute(layers[comboBoxLayerList.SelectedIndex].DataSet as DotSpatial.Data.Raster, contourtype, "Value", lev);
            Contours.Projection = layers[comboBoxLayerList.SelectedIndex].Projection;

            int NumLev = lev.GetLength(0);

            switch (contourtype)
            {
            case (Contour.ContourType.Line):
            {
                color = new Color[NumLev];
                for (int i = 0; i < NumLev; i++)
                {
                    color[i] = tomPaletteEditor1.GetColor(lev[i]);
                }
            }
            break;

            case (Contour.ContourType.Polygon):
            {
                color = new Color[NumLev - 1];
                for (int i = 0; i < NumLev - 1; i++)
                {
                    color[i] = tomPaletteEditor1.GetColor(lev[i] + (eve / 2));
                }
            }
            break;
            }
            this.DialogResult = DialogResult.OK;

            this.Close();
        }
Beispiel #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            LayerName = comboBoxLayerList.Text;

            max = (double)numericUpDownMax.Value;
            min = (double)numericUpDownMin.Value;
            eve = (double)numericUpDownEvery.Value;

            contourtype = GetSelectedType();

            lev = Contour.CreateLevels(min, max, eve);

            Contours = Contour.Execute(layers[comboBoxLayerList.SelectedIndex].DataSet as DotSpatial.Data.Raster, contourtype, "Value", lev);
            Contours.Projection = layers[comboBoxLayerList.SelectedIndex].Projection;

            int NumLev = lev.GetLength(0);

            switch (contourtype)
            {
                case (Contour.ContourType.Line):
                    {
                        color = new Color[NumLev];
                        for (int i = 0; i < NumLev; i++)
                        {
                            color[i] = tomPaletteEditor1.GetColor(lev[i]);
                        }
                    }
                    break;
                case (Contour.ContourType.Polygon):
                    {
                        color = new Color[NumLev - 1];
                        for (int i = 0; i < NumLev - 1; i++)
                        {
                            color[i] = tomPaletteEditor1.GetColor(lev[i] + (eve / 2));
                        }
                    }
                    break;
            }
            this.DialogResult = DialogResult.OK;

            this.Close();
        }
Beispiel #5
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;
        }
Beispiel #6
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);
        }
Beispiel #7
0
 public static void ExportGPSTrajectoriesToShapefile(string shpfilename, IEnumerable <GPSTrajectory> trajs)
 {
     DotSpatial.Data.FeatureSet fs = ToDotSpatialData(trajs);
     fs.SaveAs(shpfilename, true);
 }