Example #1
0
        public void TestCreateModifyDiff()
        {
            var p  = ReadWkt <LineString>("LINESTRING(1 1, 2 2, 3 3, 4 4)");
            var p2 = ReadWkt <LineString>("LINESTRING(0 0, 1 1, 2.5 2.5, 3 3)");
            var n  = (LineStringDiff)Differ.CreateDiff(p, p2);

            Assert.AreEqual(0, n.Index);
            Assert.AreEqual(Operation.Modify, n.Operation);
            Assert.AreEqual(3, n.Value.Count);

            var d1 = n.Value[0];

            Assert.AreEqual(0, d1.Index);
            Assert.AreEqual(Operation.Insert, d1.Operation);
            Assert.AreEqual(0, d1.Value.X);
            Assert.AreEqual(0, d1.Value.Y);
            Assert.AreEqual(double.NaN, d1.Value.Z);

            var d2 = n.Value[1];

            Assert.AreEqual(1, d2.Index);
            Assert.AreEqual(Operation.Modify, d2.Operation);
            Assert.AreEqual(0.5, d2.Value.X);
            Assert.AreEqual(0.5, d2.Value.Y);
            Assert.AreEqual(double.NaN, d2.Value.Z);

            var d3 = n.Value[2];

            Assert.AreEqual(3, d3.Index);
            Assert.AreEqual(Operation.Delete, d3.Operation);
            Assert.AreEqual(4, d3.Value.X);
            Assert.AreEqual(4, d3.Value.Y);
            Assert.AreEqual(double.NaN, d3.Value.Z);
        }
        public void TestCreateDiffFromDifferentGeoms()
        {
            var geom1 = ReadWkt("POINT(1 1)");
            var geom2 = ReadWkt("LINESTRING(1 1, 2 2, 3 3)");

            var ex = Assert.Throws <GeometryTypeException>(delegate { Differ.CreateDiff(geom1, geom2); });

            Assert.AreEqual("Cannot create patch from Point to LineString!", ex.Message);
        }
Example #3
0
        public void TestCreateInsertDiff()
        {
            var p = ReadWkt <MultiLineString>("MULTILINESTRING((1 1, 2 2, 3 3, 4 4), (10 10, 20 20))");

            var n = (MultiLineStringDiff)Differ.CreateDiff(null, p);

            Assert.AreEqual(0, n.Index);
            Assert.AreEqual(Operation.Insert, n.Operation);
            Assert.AreEqual(2, n.Value.Count);
        }
Example #4
0
        public void TestCreateModifyDiff()
        {
            var p  = ReadWkt <MultiLineString>("MULTILINESTRING((1 1, 2 2, 3 3, 4 4), (10 10, 20 20))");
            var p2 = ReadWkt <MultiLineString>("MULTILINESTRING((0 0, 1.5 1.5, 2 2, 3 3), (4 5, 6 7))");
            var n  = (MultiLineStringDiff)Differ.CreateDiff(p, p2);

            Assert.AreEqual(0, n.Index);
            Assert.AreEqual(Operation.Modify, n.Operation);
            Assert.AreEqual(2, n.Value.Count);
        }
        public void TestCreateDiffFromUnsupportedGeometry()
        {
            var gc1 = ReadWkt("GEOMETRYCOLLECTION (POINT (40 10))");
            var gc2 = ReadWkt("GEOMETRYCOLLECTION (POINT (40 11))");


            var ex = Assert.Throws <GeometryTypeException>(delegate { Differ.CreateDiff(gc1, gc2); });

            Assert.AreEqual("Geometry type not supported: GeometryCollection", ex.Message);
        }
Example #6
0
        public void TestCreateModifyDiff()
        {
            var p  = ReadWkt <MultiPolygon>("MULTIPOLYGON(((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3), (5 5, 6 6, 7 7, 5 5)), ((10 10, 10 20, 20 20, 20 10, 10 10)))");
            var p2 = ReadWkt <MultiPolygon>("MULTIPOLYGON(((0 0, 1 1, 0.5 1.5, 2 2, 0 0), (5 5, 6 6, 7 7, 5 5)), ((30 30, 30 40, 40 40, 40 30, 30 30), (35 35, 35 36, 36 36, 36 35, 35 35)))");
            var n  = (MultiPolygonDiff)Differ.CreateDiff(p, p2);

            Assert.AreEqual(0, n.Index);
            Assert.AreEqual(Operation.Modify, n.Operation);
            Assert.AreEqual(2, n.Value.Count);
        }
Example #7
0
        public void TestCreateInsertDiff()
        {
            var p = ReadWkt <MultiPolygon>("MULTIPOLYGON(((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3), (5 5, 6 6, 7 7, 5 5)), ((10 10, 10 20, 20 20, 20 10, 10 10)))");

            var n = (MultiPolygonDiff)Differ.CreateDiff(null, p);

            Assert.AreEqual(0, n.Index);
            Assert.AreEqual(Operation.Insert, n.Operation);
            Assert.AreEqual(2, n.Value.Count);
        }
Example #8
0
        public void TestCreateInsertDiff()
        {
            var p = ReadWkt <MultiPoint>("MULTIPOINT((2 2), (3 3))");

            var n = (MultiPointDiff)Differ.CreateDiff(null, p);

            Assert.AreEqual(0, n.Index);
            Assert.AreEqual(Operation.Insert, n.Operation);
            Assert.AreEqual(2, n.Value.Count);
        }
Example #9
0
        public void TestLineStringChangeZOnly()
        {
            var g1 = ReadWkt("LINESTRING(0 0 0, 2 2 1, 3 3, 4 4)");
            var g2 = ReadWkt("LINESTRING(0 0 1, 2 2 2, 3 3, 4 4)");

            var diff = (LineStringDiff)Differ.CreateDiff(g1, g2);

            Assert.AreEqual(Operation.Modify, diff.Operation);
            Assert.AreEqual(2, diff.Value.Count);
        }
Example #10
0
        public void TestCreateModifyDiff()
        {
            var p  = ReadWkt <MultiPoint>("MULTIPOINT((2 2), (3 3))");
            var p2 = ReadWkt <MultiPoint>("MULTIPOINT((1 2), (1.5 2.5))");
            var n  = (MultiPointDiff)Differ.CreateDiff(p, p2);

            Assert.AreEqual(0, n.Index);
            Assert.AreEqual(Operation.Modify, n.Operation);
            Assert.AreEqual(2, n.Value.Count);
        }
Example #11
0
        public void TestCreateModifyDiff()
        {
            var p  = ReadWkt <Point>("POINT(10.53 60.10)");
            var p2 = ReadWkt <Point>("POINT(10.52 60.10)");
            var n  = (PointDiff)Differ.CreateDiff(p, p2);

            Assert.AreEqual(0, n.Index);
            Assert.AreEqual(Operation.Modify, n.Operation);
            Assert.AreEqual(-0.01, n.Value.X, 0.0000001);
            Assert.AreEqual(0, n.Value.Y);
            Assert.AreEqual(double.NaN, n.Value.Z);
        }
Example #12
0
        public void TestCreateInsertDiff()
        {
            var p2 = ReadWkt <Point>("POINT(10.53 60.10)");

            var n = (PointDiff)Differ.CreateDiff(null, p2);

            Assert.AreEqual(0, n.Index);
            Assert.AreEqual(Operation.Insert, n.Operation);
            Assert.AreEqual(10.53, n.Value.X);
            Assert.AreEqual(60.10, n.Value.Y);
            Assert.AreEqual(double.NaN, n.Value.Z);
        }
Example #13
0
        public void TestCreateInsertDiff()
        {
            var p = ReadWkt <Polygon>("POLYGON((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3), (5 5, 6 6, 7 7, 5 5))");

            var n = (PolygonDiff)Differ.CreateDiff(null, p);


            Assert.AreEqual(0, n.Index);
            Assert.AreEqual(Operation.Insert, n.Operation);
            Assert.AreEqual(3, n.Value.Count);
            Assert.AreEqual(Operation.Insert, n.Value[0].Operation);
            Assert.AreEqual(Operation.Insert, n.Value[0].Value[0].Operation);
        }
Example #14
0
        public void TestModify()
        {
            var p1   = ReadWkt <MultiPolygon>("MULTIPOLYGON(((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3), (5 5, 6 6, 7 7, 5 5)), ((10 10, 10 20, 20 20, 20 10, 10 10)))");
            var p2   = ReadWkt <MultiPolygon>("MULTIPOLYGON(((0 0, 1 1, 0.5 1.5, 2 2, 0 0), (5 5, 6 6, 7 7, 5 5)), ((30 30, 30 40, 40 40, 40 30, 30 30), (35 35, 35 36, 36 36, 36 35, 35 35)))");
            var diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.AreEqual(WriteWkt(p1), WriteWkt(unpatched));
        }
Example #15
0
        public void TestPassWrongTypeOfGeometry()
        {
            var point1 = ReadWkt("POINT(1 1)");
            var point2 = ReadWkt("POINT(1 1)");

            var diff = Differ.CreateDiff(point1, point2);

            var line = ReadWkt("LINESTRING(1 1, 2 2, 3 3)");


            var ex = Assert.Throws <GeometryTypeException>(delegate { diff.Apply(line); });

            Assert.AreEqual("Expected Point, got LineString!", ex.Message);
        }
Example #16
0
        public void TestInsert()
        {
            MultiLineString p1   = null;
            var             p2   = ReadWkt <MultiLineString>("MULTILINESTRING((0 0, 1.5 1.5, 2 2, 3 3), (4 5, 6 7))");
            var             diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.IsNull(unpatched);
        }
Example #17
0
        public void TestModify()
        {
            var p1   = ReadWkt <Point>("POINT(10.53 60.10)");
            var p2   = ReadWkt <Point>("POINT(10.52 60.10)");
            var diff = (PointDiff)Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.AreEqual(WriteWkt(p1), WriteWkt(unpatched));
        }
Example #18
0
        public void TestModify()
        {
            var p1   = ReadWkt <MultiPoint>("MULTIPOINT((2 2), (3 3))");
            var p2   = ReadWkt <MultiPoint>("MULTIPOINT((1 2), (1.5 2.5))");
            var diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.AreEqual(WriteWkt(p1), WriteWkt(unpatched));
        }
Example #19
0
        public void TestInsert()
        {
            MultiPoint p1   = null;
            var        p2   = ReadWkt <MultiPoint>("MULTIPOINT((1 2), (1.5 2.5))");
            var        diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.IsNull(unpatched);
        }
Example #20
0
        public void TestModify()
        {
            var p1   = ReadWkt <LineString>("LINESTRING(1 1, 2 2, 3 3, 4 4)");
            var p2   = ReadWkt <LineString>("LINESTRING(0 0, 1 1, 2.5 2.5, 3 3)");
            var diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.AreEqual(WriteWkt(p1), WriteWkt(unpatched));
        }
Example #21
0
        public void TestInsert()
        {
            MultiPolygon p1   = null;
            var          p2   = ReadWkt <MultiPolygon>("MULTIPOLYGON(((0 0, 1 1, 0.5 1.5, 2 2, 0 0), (5 5, 6 6, 7 7, 5 5)), ((30 30, 30 40, 40 40, 40 30, 30 30), (35 35, 35 36, 36 36, 36 35, 35 35)))");
            var          diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.IsNull(unpatched);
        }
Example #22
0
        public void TestInsert()
        {
            LineString p1   = null;
            var        p2   = ReadWkt <LineString>("LINESTRING(0 0, 1 1, 2.5 2.5, 3 3)");
            var        diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.IsNull(unpatched);
        }
Example #23
0
        public void TestInsert()
        {
            Point p1   = null;
            var   p2   = ReadWkt <Point>("POINT(10.52 60.10)");
            var   diff = (PointDiff)Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.IsNull(unpatched);
        }
Example #24
0
        public void TestModify()
        {
            var p1   = ReadWkt <MultiLineString>("MULTILINESTRING((1 1, 2 2, 3 3, 4 4), (10 10, 20 20))");
            var p2   = ReadWkt <MultiLineString>("MULTILINESTRING((0 0, 1.5 1.5, 2 2, 3 3), (4 5, 6 7))");
            var diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.AreEqual(WriteWkt(p1), WriteWkt(unpatched));
        }
Example #25
0
        public void TestInsert()
        {
            Polygon p1   = null;
            var     p2   = ReadWkt <Polygon>("POLYGON((0 0, 0.5 0.5, 2 2, 0 0), (5 5, 6 6, 7 7, 5 5), (7 7, 8 8, 10 10, 7 7))");
            var     diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.IsNull(unpatched);
        }
Example #26
0
        public void TestModify()
        {
            var p1   = ReadWkt <Polygon>("POLYGON((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3), (5 5, 6 6, 7 7, 5 5))");
            var p2   = ReadWkt <Polygon>("POLYGON((0 0, 0.5 0.5, 2 2, 0 0), (5 5, 6 6, 7 7, 5 5), (7 7, 8 8, 10 10, 7 7))");
            var diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.AreEqual(WriteWkt(p2), WriteWkt(patched));

            var unpatched = diff.Undo(p2);

            Assert.AreEqual(WriteWkt(p1), WriteWkt(unpatched));
        }
Example #27
0
        public void TestDiffer()
        {
            foreach (var geomPair in pairs)
            {
                var oldGeom = geomPair.OldGeometry;
                var newGeom = geomPair.NewGeometry;
                var diff    = Differ.CreateDiff(oldGeom, newGeom);

                var patched = diff.Apply(oldGeom);
                Assert.AreEqual(WriteWkt(newGeom), WriteWkt(patched), $"Patch {geomPair.Name}");

                var unpatched = diff.Undo(newGeom);
                Assert.AreEqual(WriteWkt(oldGeom), WriteWkt(unpatched), $"UnPatch {geomPair.Name}");
            }
        }
Example #28
0
        public void TestDelete()
        {
            var     p1 = ReadWkt <Polygon>("POLYGON((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3), (5 5, 6 6, 7 7, 5 5))");
            Polygon p2 = null;

            var diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.IsNull(patched);


            var unpatched = diff.Undo(p2);

            Assert.AreEqual(WriteWkt(p1), WriteWkt(unpatched));
        }
Example #29
0
        public void TestDelete()
        {
            var        p1 = ReadWkt <MultiPoint>("MULTIPOINT((2 2), (3 3))");
            MultiPoint p2 = null;

            var diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.IsNull(patched);


            var unpatched = diff.Undo(p2);

            Assert.AreEqual(WriteWkt(p1), WriteWkt(unpatched));
        }
Example #30
0
        public void TestDelete()
        {
            var        p1 = ReadWkt <LineString>("LINESTRING(1 1, 2 2, 3 3, 4 4)");
            LineString p2 = null;

            var diff = Differ.CreateDiff(p1, p2);

            var patched = diff.Apply(p1);

            Assert.IsNull(patched);


            var unpatched = diff.Undo(p2);

            Assert.AreEqual(WriteWkt(p1), WriteWkt(unpatched));
        }