private static MultiPoint GetMultiPoint(SqlGeometry sqlMultiPoint) { var coordinates = new Collection <Coordinate>(); for (var i = 1; i <= sqlMultiPoint.STNumPoints().Value; ++i) { coordinates.Add(GetCoordinate(sqlMultiPoint.STPointN(i))); } var multiPoint = new MultiPoint(coordinates); return(multiPoint); }
private IGeometry GetBufferedEnvelope(double marginFactor) { double marginX = (BoundingBox.Right - BoundingBox.Left) * marginFactor; double marginY = (BoundingBox.Top - BoundingBox.Bottom) * marginFactor; var left = BoundingBox.Left - marginX; var bottom = BoundingBox.Bottom - marginY; var top = BoundingBox.Top + marginY; var right = BoundingBox.Right + marginX; MultiPoint lr = new MultiPoint(new[] { new Coordinate(left, bottom), new Coordinate(left, top), new Coordinate(right, top), new Coordinate(right, bottom), new Coordinate(left, bottom), }); return(lr.EnvelopeAsGeometry); }
public void MultiPs() { Coordinate[] c = new Coordinate[36]; Random rnd = new Random(); GeoAPI.Geometries.ICoordinate[] ccheck = new GeoAPI.Geometries.ICoordinate[36]; GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); for (int i = 0; i < 36; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); double x = c[i].X; double y = c[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate ctemp = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); ccheck[i] = ctemp; } GeoAPI.Geometries.IMultiPoint mpsCheck = gf.CreateMultiPoint(ccheck); MultiPoint mps = new MultiPoint(c); for (int ii = 0; ii < mps.Coordinates.Count; ii++) { Assert.AreEqual(mps.Coordinates[ii].X, mpsCheck.Coordinates[ii].X); Assert.AreEqual(mps.Coordinates[ii].Y, mpsCheck.Coordinates[ii].Y); } }
public void IntersectInternalTest() { Coordinate[] c = new Coordinate[50]; Random rnd = new Random(); Coordinate[] cc = new Coordinate[50]; for (int i = 0; i < 50; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); double x = c[i].X; double y = c[i].Y; cc[i] = new Coordinate(x, y); } MultiPoint mps = new MultiPoint(cc); MultiPoint mpsCheck = new MultiPoint(c); bool intersects = mpsCheck.Intersects(mps); if (intersects != true) { Assert.Fail("The two multipoint features did not intersect."); } }
public void MpsBufferArea() { Coordinate[] c = new Coordinate[36]; Random rnd = new Random(); GeoAPI.Geometries.ICoordinate[] ccheck = new GeoAPI.Geometries.ICoordinate[36]; GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(); for (int i = 0; i < 36; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); double x = c[i].X; double y = c[i].Y; GisSharpBlog.NetTopologySuite.Geometries.Coordinate ctemp = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y); ccheck[i] = ctemp; } GeoAPI.Geometries.IMultiPoint mpsCheck = gf.CreateMultiPoint(ccheck); MultiPoint mps = new MultiPoint(c); double area = mps.Buffer(500).Area; double areacheck = mpsCheck.Buffer(500).Area; if (Math.Abs(area - areacheck) > 0.000000001) { Assert.AreEqual(mps.Buffer(500).Area, mpsCheck.Buffer(500).Area); } }
private void MpsCS(object sender, EventArgs e) { Feature f = new Feature(); FeatureSet fs = new FeatureSet(f.FeatureType); Coordinate[] c = new Coordinate[36]; Random rnd = new Random(); for (int i = 0; i < 36; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); } MultiPoint Mps = new MultiPoint(c); f = new Feature(Mps); fs.Features.Add(f); fs.SaveAs("C:\\Temp\\mps.shp", true); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // First, we need to retrieve all data from the input parameters. List <string> fields = new List <string>(); GH_Structure <IGH_Goo> attributes = new GH_Structure <IGH_Goo>(); GH_Structure <GH_Point> inputPointTree = new GH_Structure <GH_Point>(); bool writeFile = false; string filePath = ""; string prj = null; if (!DA.GetData(5, ref writeFile)) { return; } if (!DA.GetData(4, ref filePath)) { return; } // access the input parameter by index. if (!DA.GetDataTree(0, out inputPointTree)) { return; } if (!DA.GetDataList(1, fields)) { return; } if (!DA.GetDataTree(2, out attributes)) { return; } if (!DA.GetData(3, ref prj)) { return; } //create new feature set to add data to //FeatureSet fs = new FeatureSet(FeatureType.Polygon); //FeatureSet fs = new FeatureSet(FeatureType.Point); FeatureSet fs = new FeatureSet(FeatureType.MultiPoint); if (prj != null) { //load projection file string cur_proj = System.IO.File.ReadAllText(@prj); ///create Projection system ProjectionInfo targetProjection = new ProjectionInfo(); targetProjection.ParseEsriString(cur_proj); fs.Projection = targetProjection; } if (writeFile) { // Add fields to the feature sets attribute table foreach (string field in fields) { //<<<dubble chack if this is properly declaring type>>>\\ fs.DataTable.Columns.Add(new DataColumn(field, typeof(string))); } // for every branch (ie feature) foreach (GH_Path path in inputPointTree.Paths) { //set branch IList branch = inputPointTree.get_Branch(path); // create a feature geometry List <Coordinate> vertices = new List <Coordinate>(); //add all pt coordinates to the vertices list foreach (GH_Point pt in branch) { Point3d rhinoPoint = new Point3d(); GH_Convert.ToPoint3d(pt, ref rhinoPoint, 0); vertices.Add(new Coordinate(rhinoPoint.X, rhinoPoint.Y)); } //Convert Coordinates to dot spatial point or multipoint geometry //DotSpatial.Topology.Point geom = new DotSpatial.Topology.Point(vertices); DotSpatial.Topology.MultiPoint geom = new DotSpatial.Topology.MultiPoint(vertices); //convert geom to a feature IFeature feature = fs.AddFeature(geom); //begin editing to add feature attributes feature.DataRow.BeginEdit(); //get this features attributes by its path IList <string> featrueAttributes = attributes.get_Branch(path) as IList <string>; int thisIndex = 0; //add each attribute for the pt's path foreach (var thisAttribute in attributes.get_Branch(path)) { //converting all fields to (((Proper Type...?))) feature.DataRow[fields[thisIndex]] = thisAttribute.ToString(); //currently everything is a string.... //<<<!!!!!!!!!! dubble chack if this is properly converting to the type declared above !!!!!!!!!!>>>\\ thisIndex++; } //finish attribute additions feature.DataRow.EndEdit(); }//end of itterating through branches of pt tree fs.SaveAs(filePath, true); } }
public void MultiPoint_SaveAsWorking() { var vertices = new[] { new Coordinate(10.1, 20.2, 3.3, 4.4), new Coordinate(11.1, 22.2, 3.3, 4.4) }; var mp = new MultiPoint(vertices); var f = new Feature(mp); var fs = new FeatureSet(f.FeatureType) { Projection = KnownCoordinateSystems.Geographic.World.WGS1984 }; fs.Features.Add(f); var fileName = FileTools.GetTempFileName(".shp"); try { Assert.DoesNotThrow(() => fs.SaveAs(fileName, true)); } catch (Exception) { FileTools.DeleteShapeFile(fileName); } }