public void TestCalculateBounds() { Ring r = new Ring(); r.Points.Add(new Point(0.5,0)); r.Points.Add(new Point(0,0.5)); r.Points.Add(new Point(0.5,1)); r.Points.Add(new Point(1,0.5)); r.Close(); Assert.AreEqual(new Rectangle(0,0,1,1), r.CalculateBounds()); }
public void TestCalculateArea() { Ring r = new Ring(); r.Points.Add(new Point(0,0)); r.Points.Add(new Point(0,1)); r.Points.Add(new Point(1,1)); r.Points.Add(new Point(1,0)); r.Close(); Assert.AreEqual(1, r.CalculateArea()); }
public void TestClose() { Ring r = new Ring(); r.Points.Add(new Point(0,0)); r.Points.Add(new Point(0,1)); r.Points.Add(new Point(1,1)); r.Points.Add(new Point(1,0)); Assert.IsFalse(r.IsClosed); r.Close(); Assert.IsTrue(r.IsClosed); }
public void TestCreateFromPolygon() { Polygon p = new Polygon(); Ring r1 = new Ring(); r1.Points.Add(new Point(0,0)); r1.Points.Add(new Point(0, 5)); r1.Points.Add(new Point(5,6)); r1.Points.Add(new Point(5,0)); r1.Close(); p.Rings.Add(r1); Assert.AreEqual("POLYGON((0 0,0 5,5 6,5 0,0 0))", WellKnownText.CreateFromPolygon(p)); // add hole Ring r2 = new Ring(); r2.Points.Add(new Point(1.1,1.1)); r2.Points.Add(new Point(1.6,1.1)); r2.Points.Add(new Point(1.4,1.4)); r2.Points.Add(new Point(1.1,1.6)); r2.Close(); p.Rings.Add(r2); Assert.AreEqual("POLYGON((0 0,0 5,5 6,5 0,0 0),(1.1 1.1,1.6 1.1,1.4 1.4,1.1 1.6,1.1 1.1))", WellKnownText.CreateFromPolygon(p)); // add another poly Ring r3 = new Ring(); r3.Points.Add(new Point(10,10)); r3.Points.Add(new Point(10,15)); r3.Points.Add(new Point(15,15)); r3.Points.Add(new Point(15,10)); r3.Close(); p.Rings.Add(r3); Assert.AreEqual("MULTIPOLYGON(((0 0,0 5,5 6,5 0,0 0),(1.1 1.1,1.6 1.1,1.4 1.4,1.1 1.6,1.1 1.1)),((10 10,10 15,15 15,15 10,10 10)))", WellKnownText.CreateFromPolygon(p)); }
public void TestValidate() { Ring r = new Ring(); Assert.IsFalse(r.Validate()); }
public void TestNotIsClockwise() { Ring r = new Ring(); r.Points.Add(new Point(0,0)); r.Points.Add(new Point(1,0)); r.Points.Add(new Point(1,1)); r.Points.Add(new Point(0,1)); r.Close(); Assert.IsFalse(r.IsClockwise); }
public Ring Simplify(double tolerance) { Ring r = new Ring(); r.points = new List<Point>(this.points); if (r.IsClosed) { r.points.RemoveAt(r.Points.Count-1); } r.points = Simplificator.Simplify(r.points, tolerance, true); r.Close(); return r; }
public void TestSimpleFeatureSourceSerialization() { Map m = new Map(); Layer l = new Layer(); SimpleFeatureSource sfs = new SimpleFeatureSource(FeatureType.Polygon); Polygon p = new Polygon(); Ring r = new Ring(); r.Points.Add(new Point(0,0)); r.Points.Add(new Point(0,5)); r.Points.Add(new Point(5,5)); r.Points.Add(new Point(5,0)); r.Close(); p.Rings.Add(r); Ring hole = new Ring(); hole.Points.Add(new Point(1,1)); hole.Points.Add(new Point(2,1)); hole.Points.Add(new Point(2,2)); hole.Points.Add(new Point(2,1)); hole.Close(); p.Rings.Add(hole); sfs.Features.Add(p); l.Data = sfs; m.Layers.Add(l); MapSerializer ms = new MapSerializer(); string s = MapSerializer.Serialize(m); Map m2 = ms.Deserialize(new MemoryStream(UTF8Encoding.UTF8.GetBytes((s)))); Assert.AreEqual(1, m2.Layers.Count); Assert.AreEqual(1, (m2.Layers[0].Data as SimpleFeatureSource).Features.Count); Assert.AreEqual(2, ((m2.Layers[0].Data as SimpleFeatureSource).Features[0] as Polygon).Rings.Count); }
static Polygon GetPolygon(BinaryReader stream, uint dlen, bool hasMeasure) { //Polygons stored in a shapefile must be clean. A clean polygon is one that // 1. Has no self-intersections. This means that a segment belonging to one ring may // not intersect a segment belonging to another ring. The rings of a polygon can // touch each other at vertices but not along segments. Colinear segments are // considered intersecting. // 2. Has the inside of the polygon on the "correct" side of the line that defines it. The // neighborhood to the right of an observer walking along the ring in vertex order is // the inside of the polygon. Vertices for a single, ringed polygon are, therefore, // always in clockwise order. Rings defining holes in these polygons have a // counterclockwise orientation. "Dirty" polygons occur when the rings that define // holes in the polygon also go clockwise, which causes overlapping interiors. // The order of rings in the points array is not significant. stream.ReadDouble(); // double xmin = stream.ReadDouble(); // double ymin = stream.ReadDouble(); // double xmax = stream.ReadDouble(); // double ymax = uint numParts = stream.ReadUInt32(); uint numPoints = stream.ReadUInt32(); uint[] parts = new uint[numParts]; int ii; for (ii=0; ii < numParts; ii++) parts[ii] = stream.ReadUInt32(); Ring[] rings = new Ring[numParts]; for (ii=0; ii < rings.Length; ii++) rings[ii] = new Ring(); //Polygon po = new Polygon(xmin, ymin, xmax, ymax); Polygon po = new Polygon(); ii=0; for (int jj=0; jj < numPoints; jj++) { if (ii < parts.Length-1) { if (parts[ii+1] == jj) { po.Rings.Add(rings[ii]); ii++; } } Point p = new Point(stream.ReadDouble(), stream.ReadDouble()); rings[ii].Points.Add(p); } po.Rings.Add(rings[ii]); if (hasMeasure) { stream.ReadDouble(); // Mmin stream.ReadDouble(); // Mmax for (int jj=0; jj < numPoints; jj++) { stream.ReadDouble(); // Marray } } return po; }