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); }
private static void TestCoordinate(Coordinate c1, DotSpatial.Topology.Coordinate c2) { Assert.AreEqual(c1.X, c2.X); Assert.AreEqual(c1.Y, c2.Y); if (!double.IsNaN(c1.Z)) { Assert.AreEqual(c1.Z, c2.Z); } }
/// <summary> /// 由点list新建shp文件 /// </summary> /// <param name="point_list"></param> /// <param name="file_path"></param> public static void outputMyPoint(List <MyPoint> point_list, string file_path) { Feature f = new Feature(); FeatureSet fs = new FeatureSet(f.FeatureType); //fs.DataTable.Columns.Add("azimuth", typeof(double)); //fs.DataTable.Columns.Add("speed", typeof(double)); DotSpatial.Topology.Coordinate[] coordinate = new DotSpatial.Topology.Coordinate[point_list.Count]; for (int i = 0; i < point_list.Count; i++) { coordinate[i] = new DotSpatial.Topology.Coordinate(point_list[i].x, point_list[i].y); fs.Features.Add(coordinate[i]); //fs.DataTable.Rows[i]["azimuth"] = point_list[i].azimuth; //fs.DataTable.Rows[i]["speed"] = point_list[i].speed; } fs.SaveAs(file_path, true); //fs.Projection.SaveAs(file_path.Substring(0, file_path.Length - 4) + ".prj"); }
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); }
/// <summary> /// Clears the array, reducing the measure to 1 empty coordinate. /// </summary> public virtual void Clear() { _coordinates = new Coordinate[1]; _coordinates[0] = new Coordinate(); IncrementVersion(); }
/// <summary> /// Creates a new array sequence dimensioned with exactly 1 coordinate, which is set to the coordinate /// </summary> /// <param name="coordinate">The ICoordinate to use when constructing this sequence</param> public CoordinateArraySequence(Coordinate coordinate) { Coordinate[] coords = new Coordinate[1]; coords[0] = coordinate; Configure(coords); }
/// <summary> /// /// </summary> /// <param name="coord"></param> /// <param name="exemplar"></param> /// <returns></returns> public static IPoint CreatePointFromInternalCoord(Coordinate coord, IGeometry exemplar) { new PrecisionModel(exemplar.PrecisionModel).MakePrecise(coord); return(exemplar.Factory.CreatePoint(coord)); }
/// <summary> /// Creates a Point using the given Coordinate; a null Coordinate will create /// an empty Geometry. /// </summary> /// <param name="coordinate"></param> public virtual IPoint CreatePoint(Coordinate coordinate) { return(new Point(coordinate, this)); }
private static QuadTree<byte> BuildQuadTree(StRtree Tree, Dictionary<string, byte> Countries, Coordinate TopLeft, Coordinate BottomRight, int MaxDepth, int Depth = 0) { // Bounding box for this node. var envelope = new Envelope(TopLeft, BottomRight); // Find all countries whose bounding boxes intersect with this node. var coarseResults = Tree.Query(envelope); // Of those countries, find those whose geometry actually intersects with this node. var fineResults = (from Tuple<string, IGeometry> r in coarseResults select r).Where(r => r.Item2.Intersects(envelope.ToPolygon())); // In case of either: // 1) No countries intersect, in which case we mark this node as empty. Or; // 2) Exactly one country intersects, in which case we mark this node as that country. var results = fineResults as IList<Tuple<string, IGeometry>> ?? fineResults.ToList(); if (results.Count() <= 1) { var country = results.FirstOrDefault(); var countryName = country != null ? country.Item1 : ""; Console.WriteLine("Adding {0}, Depth {1}, {2}x{3}", countryName, Depth, BottomRight.X - TopLeft.X, BottomRight.Y - TopLeft.Y); ++_nleafs; return new QuadTreeLeaf<byte> { Data = Countries[countryName], TopLeft = TopLeft.ToGeomoirCoordinate(), BottomRight = BottomRight.ToGeomoirCoordinate() }; } // If we have reached the maximum depth and multiple countries interect // with this node, mark it as the country with the largest overlap. if (Depth >= MaxDepth) { byte label = 0; // Take country with largest area intersecting. var r = (from Tuple<string, IGeometry> t in results orderby t.Item2.Intersection(envelope.ToPolygon()).Area descending select t).First(); if (r.Item2.Intersection(envelope.ToPolygon()).Area > 0) label = Countries[r.Item1]; ++_nleafs; return new QuadTreeLeaf<byte> { Data = label, TopLeft = TopLeft.ToGeomoirCoordinate(), BottomRight = BottomRight.ToGeomoirCoordinate() }; } // Split the node into 4 quadrants and recurse on each. var middleTop = new Coordinate((BottomRight.X + TopLeft.X) / 2, TopLeft.Y); var middleBottom = new Coordinate((BottomRight.X + TopLeft.X) / 2, BottomRight.Y); var middleLeft = new Coordinate(TopLeft.X, (BottomRight.Y + TopLeft.Y) / 2); var middleRight = new Coordinate(BottomRight.X, (BottomRight.Y + TopLeft.Y) / 2); var middle = new Coordinate(middleTop.X, middleLeft.Y); return new QuadTreeNode<byte> { TopLeft = TopLeft.ToGeomoirCoordinate(), BottomRight = BottomRight.ToGeomoirCoordinate(), Children = new [] { BuildQuadTree(Tree, Countries, TopLeft, middle, MaxDepth, Depth + 1), BuildQuadTree(Tree, Countries, middleTop, middleRight, MaxDepth, Depth + 1), BuildQuadTree(Tree, Countries, middleLeft, middleBottom, MaxDepth, Depth + 1), BuildQuadTree(Tree, Countries, middle, BottomRight, MaxDepth, Depth + 1) } }; }
private void map1_MouseDown(object sender, MouseEventArgs e) { switch (shapeType) { case "Point": if (e.Button == MouseButtons.Left) { if ((pointmouseClick)) { //This method is used to convert the screen cordinate to map coordinate //e.location is the mouse click point on the map control DotSpatial.Topology.Coordinate coord = map1.PixelToProj(e.Location); //Create a new point //Input parameter is clicked point coordinate DotSpatial.Topology.Point point = new DotSpatial.Topology.Point(coord); //Add the point into the Point Feature //assigning the point feature to IFeature because via it only we can set the attributes. IFeature currentFeature = pointF.AddFeature(point); //increase the point id pointID = pointID + 1; //set the ID attribute currentFeature.DataRow["ID"] = pointID; //refresh the map map1.ResetBuffer(); } } else { //mouse right click map1.Cursor = Cursors.Default; pointmouseClick = false; } break; case "line": if (e.Button == MouseButtons.Left) { //left click - fill array of coordinates //coordinate of clicked point DotSpatial.Topology.Coordinate coord = map1.PixelToProj(e.Location); if (linemouseClick) { //first time left click - create empty line feature if (firstClick) { //Create a new List called lineArray. //This list will store the Coordinates //We are going to store the mouse click coordinates into this array. List <DotSpatial.Topology.Coordinate> lineArray = new List <DotSpatial.Topology.Coordinate>(); //Create an instance for LineString class. //We need to pass collection of list coordinates LineString lineGeometry = new LineString(lineArray); //Add the linegeometry to line feature IFeature lineFeature = lineF.AddFeature(lineGeometry); //add first coordinate to the line feature lineFeature.Coordinates.Add(coord); //set the line feature attribute lineID = lineID + 1; lineFeature.DataRow["LineID"] = lineID; firstClick = false; } else { //second or more clicks - add points to the existing feature IFeature existingFeature = lineF.Features[lineF.Features.Count - 1]; existingFeature.Coordinates.Add(coord); //refresh the map if line has 2 or more points if (existingFeature.Coordinates.Count >= 2) { lineF.InitializeVertices(); map1.ResetBuffer(); } } } } else { //right click - reset first mouse click firstClick = true; map1.ResetBuffer(); } break; case "polygon": if (e.Button == MouseButtons.Left) { //left click - fill array of coordinates DotSpatial.Topology.Coordinate coord = map1.PixelToProj(e.Location); if (polygonmouseClick) { //first time left click - create empty line feature if (firstClick) { //Create a new List called polygonArray. //this list will store the Coordinates //We are going to store the mouse click coordinates into this array. List <DotSpatial.Topology.Coordinate> polygonArray = new List <DotSpatial.Topology.Coordinate>(); //Create an instance for LinearRing class. //We pass the polygon List to the constructor of this class LinearRing polygonGeometry = new LinearRing(polygonArray); //Add the polygonGeometry instance to PolygonFeature IFeature polygonFeature = polygonF.AddFeature(polygonGeometry); //add first coordinate to the polygon feature polygonFeature.Coordinates.Add(coord); //set the polygon feature attribute polygonID = polygonID + 1; polygonFeature.DataRow["PolygonID"] = polygonID; firstClick = false; } else { //second or more clicks - add points to the existing feature IFeature existingFeature = (IFeature)polygonF.Features[polygonF.Features.Count - 1]; existingFeature.Coordinates.Add(coord); //refresh the map if line has 2 or more points if (existingFeature.Coordinates.Count >= 3) { //refresh the map polygonF.InitializeVertices(); map1.ResetBuffer(); } } } } else { //right click - reset first mouse click firstClick = true; } break; } }