IsCCW() public method

Tests whether a ring is oriented counter-clockwise.
public IsCCW ( ) : bool
return bool
コード例 #1
0
ファイル: PolygonTests.cs プロジェクト: lishxi/_SharpMap
		public void PolygonTest()
		{
			Polygon p = new Polygon();
			Assert.IsTrue(p.IsEmpty());
			Assert.AreEqual(0, p.NumInteriorRing);
			Assert.AreEqual(p.NumInteriorRing, p.InteriorRings.Count);
			Assert.IsFalse(p.Equals(null));
			Assert.IsTrue(p.Equals(new Polygon()));
			Assert.IsNull(p.GetBoundingBox());
			LinearRing ring = new LinearRing();
			ring.Vertices.Add(new Point(10, 10));
			ring.Vertices.Add(new Point(20, 10));
			ring.Vertices.Add(new Point(20, 20));
            Assert.IsFalse(ring.IsCCW());
			ring.Vertices.Add(new Point(10, 20));
            ring.Vertices.Add(ring.Vertices[0].Clone());
            Assert.IsTrue(ring.IsPointWithin(new Point(15, 15)));
            Assert.AreNotSame(ring.Clone(), ring);
			p.ExteriorRing = ring;
            
            

			Assert.AreEqual(100, p.Area);
			LinearRing ring2 = new LinearRing();
			ring2.Vertices.Add(new Point(11, 11));
			ring2.Vertices.Add(new Point(19, 11));
			ring2.Vertices.Add(new Point(19, 19));
			ring2.Vertices.Add(new Point(11, 19));
			ring2.Vertices.Add(ring2.Vertices[0].Clone());			
			p.InteriorRings.Add(ring2);
			Assert.AreEqual(100 + 64, p.Area);
            // Reverse() doesn't exist for Collections
			//ring2.Vertices.Reverse();
			//Assert.AreEqual(100 - 64, p.Area);
			Assert.AreEqual(1, p.NumInteriorRing);
			Assert.AreEqual(new BoundingBox(10, 10, 20, 20), p.GetBoundingBox());

			Polygon p2 = p.Clone();
			Assert.AreEqual(p, p2);
			Assert.AreNotSame(p, p2);
			p2.InteriorRings.RemoveAt(0);
			Assert.AreNotEqual(p, p2);
		}
コード例 #2
0
        private static Geometry FromShapeFilePolygon(EsriShapeBuffer shapeBuffer, out BoundingBox box)
        {
            box = null;
            if (shapeBuffer == null)
                return null;

            var hasZ = EsriShapeBuffer.HasZs(shapeBuffer.shapeType);
            var hasM = EsriShapeBuffer.HasMs(shapeBuffer.shapeType);
            using (var reader = new BinaryReader(new MemoryStream(shapeBuffer.shapeBuffer)))
            {
                var type = reader.ReadInt32();
                if (!(type == 5 || type == 15 || type == 25))
                    throw new InvalidOperationException();

                box = new BoundingBox(reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble());

                var numParts = reader.ReadInt32();
                var numPoints = reader.ReadInt32();
                var allVertices = new List<Point>(numPoints);

                var parts = new int[numParts+1];
                for (var i = 0; i < numParts; i++)
                    parts[i] = reader.ReadInt32();
                parts[numParts] = numPoints;

                var res = new MultiPolygon();
                Polygon poly = null;
                for (var i = 0; i < numParts; i++)
                {
                    var count = parts[i + 1] - parts[i];
                    var vertices = new List<Point>(count);
                    for (var j = 0; j < count; j++)
                    {
                        var vertex = hasZ
                                         ? new Point3D(reader.ReadDouble(), reader.ReadDouble(), double.NaN)
                                         : new Point(reader.ReadDouble(), reader.ReadDouble());
                        vertices.Add(vertex);
                        allVertices.Add(vertex);
                    }

                    var ring = new LinearRing(vertices);
                    if (poly == null || !ring.IsCCW())
                    {
                        poly = new Polygon(ring);
                        res.Polygons.Add(poly);
                    }
                    else
                    {
                        poly.InteriorRings.Add(ring);
                    }
                }

                if (hasZ)
                {
                    var minZ = reader.ReadDouble();
                    var maxZ = reader.ReadDouble();
                    for (var i = 0; i < numPoints; i++)
                        ((Point3D) allVertices[i]).Z = reader.ReadDouble();
                }

                if (res.NumGeometries == 1)
                    return res.Polygons[0];

                return res;

            }
        }
コード例 #3
0
        private static Geometry ToSharpMapMultiPolygon(EsriShapeBuffer shapeBuffer)
        {
            if (shapeBuffer == null)
                return null;

            var multiPartShapeBuffer = shapeBuffer as EsriMultiPartShapeBuffer;
            if (multiPartShapeBuffer == null)
            {
                BoundingBox box;
                return FromShapeFilePolygon(shapeBuffer, out box);
            }

            var hasZ = EsriShapeBuffer.HasZs(shapeBuffer.shapeType);
            var res = new MultiPolygon();
            Polygon poly = null;
            var offset = 0;
            for (var i = 0; i < multiPartShapeBuffer.NumParts; i++)
            {
                var vertices = new List<Point>(multiPartShapeBuffer.Parts[i]);
                for (var j = 0; j < multiPartShapeBuffer.Parts[i]; j++)
                {
                    var index = offset + j;
                    var point = multiPartShapeBuffer.Points[index];
                    vertices.Add(hasZ 
                        ? new Point3D(point.x, point.y, multiPartShapeBuffer.Zs[index])
                        : new Point(point.x, point.y));
                }

                var ring = new LinearRing(vertices);
                if (poly == null || !ring.IsCCW())
                {
                    poly = new Polygon(ring);
                    res.Polygons.Add(poly);
                } 
                else
                {
                    poly.InteriorRings.Add(ring);
                }

                offset += multiPartShapeBuffer.Parts[i];
            }

            if (res.NumGeometries == 1)
                return res.Polygons[0];
            
            return res;
        }