Exemplo n.º 1
0
        public virtual void TestLineStringDateline()
        {
            //works because we use NTS (NtsGeometry); BufferedLineString doesn't yet do DL wrap.
            IShape s = ctx.ReadShapeFromWkt("LINESTRING(160 10, -170 15)");

            CustomAssert.EqualWithDelta(30, s.BoundingBox.Width, 0.0);
        }
Exemplo n.º 2
0
        public virtual void PolyToRectCcwRule()
        {
            NtsSpatialContext ctx = (NtsSpatialContext) new NtsSpatialContextFactory()
            {
                datelineRule = DatelineRule.CcwRect
            }.NewSpatialContext();

            //counter-clockwise
            Assert.Equal(ctx.ReadShapeFromWkt("POLYGON((160 0, -170 0, -170 10, 160 10, 160 0))"),
                         ctx.MakeRectangle(160, -170, 0, 10));
            //clockwise
            Assert.Equal(ctx.ReadShapeFromWkt("POLYGON((160 10, -170 10, -170 0, 160 0, 160 10))"),
                         ctx.MakeRectangle(-170, 160, 0, 10));
        }
Exemplo n.º 3
0
        public virtual void TestPolygonRepair()
        {
            //because we're going to test validation
            //System.setProperty(NtsGeometry.SYSPROP_ASSERT_VALIDATE, "false"); // TODO: Figure this out...
            Environment.SetEnvironmentVariable(NtsGeometry.SYSPROP_ASSERT_VALIDATE, bool.FalseString);

            //note: doesn't repair all cases; this case isn't:
            //ctx.readShapeFromWkt("POLYGON((0 0, 10 0, 10 20))");//doesn't connect around
            string wkt = "POLYGON((0 0, 10 0, 10 20, 5 -5, 0 20, 0 0))";//Topology self-intersect

            NtsSpatialContextFactory factory = new NtsSpatialContextFactory();

            factory.validationRule = ValidationRule.RepairBuffer0;
            NtsSpatialContext ctx     = (NtsSpatialContext)factory.NewSpatialContext(); // TODO: Can we remove this cast?
            IShape            buffer0 = ctx.ReadShapeFromWkt(wkt);

            Assert.True(buffer0.GetArea(ctx) > 0);

            factory = new NtsSpatialContextFactory();
            factory.validationRule = ValidationRule.RepairConvexHull;
            ctx = (NtsSpatialContext)factory.NewSpatialContext();
            IShape cvxHull = ctx.ReadShapeFromWkt(wkt);

            Assert.True(cvxHull.GetArea(ctx) > 0);

            Assert.Equal(SpatialRelation.CONTAINS, cvxHull.Relate(buffer0));

            factory = new NtsSpatialContextFactory();
            factory.validationRule = ValidationRule.None;
            ctx = (NtsSpatialContext)factory.NewSpatialContext();
            ctx.ReadShapeFromWkt(wkt);//doesn't throw
        }
Exemplo n.º 4
0
        public virtual void TestRussia()
        {
            string wktStr = ReadFirstLineFromRsrc("russia.wkt.txt");
            //Russia exercises NtsGeometry fairly well because of these characteristics:
            // * a MultiPolygon
            // * crosses the dateline
            // * has coordinates needing normalization (longitude +180.000xxx)

            //TODO THE RUSSIA TEST DATA SET APPEARS CORRUPT
            // But this test "works" anyhow, and exercises a ton.
            //Unexplained holes revealed via KML export:
            // TODO Test contains: 64°12'44.82"N    61°29'5.20"E
            //  64.21245  61.48475
            // FAILS
            //AssertRelation(null,SpatialRelation.CONTAINS, shape, ctx.makePoint(61.48, 64.21));

            NtsSpatialContextFactory factory = new NtsSpatialContextFactory();

            factory.normWrapLongitude = true;

            NtsSpatialContext ctx = (NtsSpatialContext)factory.NewSpatialContext();

            IShape shape = ctx.ReadShapeFromWkt(wktStr);
            //System.out.println("Russia Area: "+shape.getArea(ctx));
        }
Exemplo n.º 5
0
        public virtual void TestFiji()
        {
            //Fiji is a group of islands crossing the dateline.
            string wktStr = ReadFirstLineFromRsrc("fiji.wkt.txt");

            NtsSpatialContextFactory factory = new NtsSpatialContextFactory();

            factory.normWrapLongitude = true;
            NtsSpatialContext ctx = (NtsSpatialContext)factory.NewSpatialContext();

            IShape shape = ctx.ReadShapeFromWkt(wktStr);

            AssertRelation(null, SpatialRelation.CONTAINS, shape,
                           ctx.MakePoint(-179.99, -16.9));
            AssertRelation(null, SpatialRelation.CONTAINS, shape,
                           ctx.MakePoint(+179.99, -16.9));
            Assert.True(shape.BoundingBox.Width < 5);//smart bbox
            Console.WriteLine("Fiji Area: " + shape.GetArea(ctx));
        }