示例#1
0
        private Dictionary <string, List <Point> > GetTilesFromShapeFile()
        {
            var tilesToDownload = new Dictionary <string, List <Point> >();
            var indexMapFile    = Shapefile.OpenFile(this.options.ShapeFile);

            indexMapFile.Reproject(ProjectionInfo.FromEpsgCode(4326));

            // Get the map index from the Feature data
            for (int i = 0; i < indexMapFile.DataTable.Rows.Count; i++)
            {
                // Get the feature
                DotSpatial.Data.IFeature feature = indexMapFile.Features.ElementAt(i);

                var polygon = feature.BasicGeometry as Polygon;
                var name    = (string)feature.DataRow[1];

                if (!string.IsNullOrWhiteSpace(this.options.FeaturePropertyValue))
                {
                    if (this.options.FeaturePropertyValue != name)
                    {
                        continue;
                    }
                }
                tilesToDownload[name] = polygon.GetTiles(name, this.options.MinZoom, this.options.MaxZoom);
                // Now it's very quick to iterate through and work with the feature.
            }
            return(tilesToDownload);
        }
示例#2
0
        /// <summary>
        /// Updates the parameters in the SQL statement with the values from the feature, including
        /// the geometry.
        /// </summary>
        /// <param name="feature">feature to save</param>
        /// <param name="parms">SQL parameters to update</param>
        /// <param name="cols">column names</param>
        /// <param name="srid">spatial reference</param>
        private void UpdateCommandParameters(DotSpatial.Data.IFeature feature, List <SQLiteParameter> parms, List <string> cols, int srid)
        {
            for (int i = 0; i < cols.Count; i++)
            {
                if (System.DBNull.Value.Equals(feature.DataRow[cols[i]]))
                {
                    if (parms[i].DbType == DbType.String)
                    {
                        parms[i].Value = "";
                    }
                    else
                    {
                        parms[i].Value = Activator.CreateInstance(DbTypeMapping[parms[i].DbType]);
                    }
                }
                else
                {
                    parms[i].Value = feature.DataRow[cols[i]];
                }
            }

            // Save geometry
            //Helper.SpatiaLiteWkbWriter writer = new Helper.SpatiaLiteWkbWriter();
            //var g = DotSpatial.Topology.Geometry.FromBasicGeometry(feature.BasicGeometry);
            //g.Srid = srid;
            //byte[] blob = writer.Write(g);
            parms[parms.Count - 1].Value = feature.BasicGeometry.ToBinary();
        }
示例#3
0
        public static FeatureSet SHPLineDataHandler(FeatureSet fs, IndexedDictionary <string, string[]> data)
        {
            try
            {
                Debug.Write("\nCoor: " + Convert.ToDouble(data["coordinates"][1]) + "| " + Convert.ToDouble(data["coordinates"][2]) + "| " + Convert.ToDouble(data["coordinates"][3]) + "| " + Convert.ToDouble(data["coordinates"][4]));
                DotSpatial.Topology.Coordinate        ptcoor1  = new DotSpatial.Topology.Coordinate(Convert.ToDouble(data["coordinates"][1]), Convert.ToDouble(data["coordinates"][2]));
                DotSpatial.Topology.Coordinate        ptcoor2  = new DotSpatial.Topology.Coordinate(Convert.ToDouble(data["coordinates"][3]), Convert.ToDouble(data["coordinates"][4]));
                List <DotSpatial.Topology.Coordinate> lineCoor = new List <DotSpatial.Topology.Coordinate>();
                lineCoor.Add(ptcoor1);
                lineCoor.Add(ptcoor2);
                LineString line = new LineString(lineCoor);
                DotSpatial.Data.IFeature feature = fs.AddFeature(line);

                //remove geometry
                data.Remove("Geometry");
                //now fill in rest of the columns
                foreach (var item in data)
                {
                    string dataType = data[item.Key][0];
                    string value    = data[item.Key][1];
                    Debug.Write("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~SHP null AND dOUBLE DEBUG~~~~~~~~~~~~~~~~ VALUE : " + value + " =" + (string.IsNullOrEmpty(value)));
                    //check if value is null - double dont accept string null values. need to fix it before sending.
                    if (value.Equals("null") && dataType.Equals("Double"))
                    {
                        //for double
                        double d;
                        if (double.TryParse(value, out d))
                        {
                            // valid number
                            Debug.Write("\n~~~~VALID");
                        }
                        else
                        {
                            // not a valid number
                            Debug.Write("\n~~~~VALID Assigning 0");
                            value = "0";
                        }
                    }


                    if (!item.Key.Equals("Geometry") || !item.Key.Equals("coordinates"))
                    {
                        Debug.Write("\n~~SHP WRITE Property: " + item.Key);
                        Debug.Write("\n~~SHP WRITE dataType: " + dataType);
                        Debug.Write("\n~~SHP WRITE value: " + value);

                        feature.DataRow.BeginEdit();
                        feature.DataRow[item.Key] = value;
                        feature.DataRow.EndEdit();
                    }
                    Debug.Write("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~SHP null AND dOUBLE DEBUG~~~~~~~~~~~~~~~~\n");
                }
            }
            catch (SystemException ex)
            {
                Debug.Write("\n" + ex.ToString());
            }
            return(fs);
        }
示例#4
0
        public static void createSHP()
        {
            // See comments below this code for an updated version.

            // define the feature type for this file
            FeatureSet fs = new FeatureSet(FeatureType.Polygon);


            // Add Some Columns
            fs.DataTable.Columns.Add(new DataColumn("ID", typeof(int)));
            fs.DataTable.Columns.Add(new DataColumn("Text", typeof(string)));


            // create a geometry (square polygon)
            List <DotSpatial.Topology.Coordinate> vertices = new List <DotSpatial.Topology.Coordinate>();

            vertices.Add(new DotSpatial.Topology.Coordinate(0, 0));
            vertices.Add(new DotSpatial.Topology.Coordinate(0, 100));
            vertices.Add(new DotSpatial.Topology.Coordinate(100, 100));
            vertices.Add(new DotSpatial.Topology.Coordinate(100, 0));
            Polygon geom = new Polygon(vertices);

            // add the geometry to the featureset.
            DotSpatial.Data.IFeature feature = fs.AddFeature(geom);

            // now the resulting features knows what columns it has
            // add values for the columns
            feature.DataRow.BeginEdit();
            feature.DataRow["ID"]   = 1;
            feature.DataRow["Text"] = "Hello World";
            feature.DataRow.EndEdit();


            // save the feature set
            fs.SaveAs(@"H:\temp\12Converter\SHPTEST\test.shp", true);
        }
示例#5
0
        public static FeatureSet SHPPointDataHandler(FeatureSet fs, IndexedDictionary <string, string[]> data)
        {
            try
            {
                DotSpatial.Topology.Coordinate ptcoor = new DotSpatial.Topology.Coordinate(Convert.ToDouble(data["Northing"][1]), Convert.ToDouble(data["Easting"][1]));
                Point pt = new Point(ptcoor);
                DotSpatial.Data.IFeature feature = fs.AddFeature(pt);

                //remove geometry
                data.Remove("Geometry");

                //now fill in rest of the columns
                foreach (var item in data)
                {
                    string dataType = data[item.Key][0];
                    string value    = data[item.Key][1];


                    if (!item.Key.Equals("Northing") || !item.Key.Equals("Easting") || !item.Key.Equals("Geometry"))
                    {
                        Debug.Write("\nProperty: " + item.Key);
                        Debug.Write("\ndataType: " + dataType);
                        Debug.Write("\nvalue: " + value);

                        feature.DataRow.BeginEdit();
                        feature.DataRow[item.Key] = value;
                        feature.DataRow.EndEdit();
                    }
                }
            }
            catch (SystemException ex)
            {
                Debug.Write("\n" + ex.ToString());
            }
            return(fs);
        }
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            List <int[]>   list_poly  = new List <int[]>();
            List <float[]> list_nodes = new List <float[]>();
            StreamReader   sr         = new StreamReader(InputFileName);
            var            line       = sr.ReadLine();

            line = sr.ReadLine();
            line = sr.ReadLine();
            while (!sr.EndOfStream)
            {
                line = sr.ReadLine();
                if (TypeConverterEx.IsNotNull(line))
                {
                    if (line.Contains("BEGPARAMDEF"))
                    {
                        break;
                    }
                    if (line.Contains("E3T"))
                    {
                        var   buf = TypeConverterEx.Split <string>(line.Trim());
                        int[] num = new int[3];
                        num[0] = int.Parse(buf[2]);
                        num[1] = int.Parse(buf[3]);
                        num[2] = int.Parse(buf[4]);
                        list_poly.Add(num);
                    }
                    else if (line.Contains("ND"))
                    {
                        var     buf = TypeConverterEx.Split <string>(line);
                        float[] num = new float[3];
                        num[0] = float.Parse(buf[2]);
                        num[1] = float.Parse(buf[3]);
                        num[2] = float.Parse(buf[4]);
                        list_nodes.Add(num);
                    }
                }
            }
            sr.Close();
            cancelProgressHandler.Progress("Package_Tool", 10, "2dm file loaded.");
            var        num_nodes = list_nodes.Count;
            var        num_polys = list_poly.Count;
            var        node_shp  = InputFileName.Replace(".2dm", "_pt.shp");
            var        poly_shp  = InputFileName.Replace(".2dm", "_poly.shp");
            FeatureSet fs_poly   = new FeatureSet(FeatureType.Polygon);

            fs_poly.Name = "Mesh_Elements";
            fs_poly.DataTable.Columns.Add(new DataColumn("ID", typeof(int)));
            fs_poly.DataTable.Columns.Add(new DataColumn("Temp", typeof(double)));
            for (int i = 0; i < num_polys; i++)
            {
                GeoAPI.Geometries.Coordinate[] vertices = new GeoAPI.Geometries.Coordinate[4];
                var temp = list_poly[i];
                vertices[0]   = new Coordinate();
                vertices[0].X = list_nodes[temp[0] - 1][0];
                vertices[0].Y = list_nodes[temp[0] - 1][1];
                vertices[0].Z = list_nodes[temp[0] - 1][2];
                vertices[1]   = new Coordinate();
                vertices[1].X = list_nodes[temp[1] - 1][0];
                vertices[1].Y = list_nodes[temp[1] - 1][1];
                vertices[1].Z = list_nodes[temp[1] - 1][2];
                vertices[2]   = new Coordinate();
                vertices[2].X = list_nodes[temp[2] - 1][0];
                vertices[2].Y = list_nodes[temp[2] - 1][1];
                vertices[2].Z = list_nodes[temp[2] - 1][2];
                vertices[3]   = new Coordinate(vertices[0]);
                GeoAPI.Geometries.ILinearRing ring = new LinearRing(vertices);
                Polygon geom = new Polygon(ring);
                DotSpatial.Data.IFeature feature = fs_poly.AddFeature(geom);
                feature.DataRow.BeginEdit();
                feature.DataRow["ID"]   = i + 1;
                feature.DataRow["Temp"] = System.Math.Round((vertices[0].Z + vertices[1].Z + vertices[2].Z) / 3, 2);
                feature.DataRow.EndEdit();
            }
            fs_poly.SaveAs(poly_shp, true);
            cancelProgressHandler.Progress("Package_Tool", 80, "Mesh elements shapefile created.");
            FeatureSet fs_pt = new FeatureSet(FeatureType.Point);

            fs_pt.Name = "Mesh_Nodes";
            fs_pt.DataTable.Columns.Add(new DataColumn("ID", typeof(int)));
            fs_pt.DataTable.Columns.Add(new DataColumn("Temp", typeof(double)));
            for (int i = 0; i < num_nodes; i++)
            {
                Point pt = new Point(list_nodes[i][0], list_nodes[i][1], list_nodes[i][2]);
                DotSpatial.Data.IFeature feature = fs_pt.AddFeature(pt);
                feature.DataRow.BeginEdit();
                feature.DataRow["ID"]   = i + 1;
                feature.DataRow["Temp"] = list_nodes[i][2];
                feature.DataRow.EndEdit();
            }
            fs_pt.SaveAs(node_shp, true);
            cancelProgressHandler.Progress("Package_Tool", 90, "Mesh nodes shapefile created.");
            cancelProgressHandler.Progress("Package_Tool", 100, "Finished.");
            return(true);
        }