private void CheckReduce(double scaleFactor, string wkt, string wktExpected)
        {
            var pm      = new PrecisionModel(scaleFactor);
            var reducer = new GeometryPrecisionReducer(pm);

            CheckReduce(reducer, wkt, wktExpected);
        }
예제 #2
0
        public bool CheckGeometriesIsInControlGeometry(IEnumerable <IGeometry> achsenreferenzenToCheck, IGeometry controlGeometry)
        {
            if (achsenreferenzenToCheck.Any(a => a == null) || controlGeometry == null)
            {
                Loggers.TechLogger.Warn("AchsenReferenz or Controlgeometry with null value");
                return(false);
            }
            //perform check
            GeometryPrecisionReducer precReduc = new GeometryPrecisionReducer(new PrecisionModel(1000));

            precReduc.ChangePrecisionModel = true;
            NetTopologySuite.Operation.Buffer.BufferParameters bufferPara = new NetTopologySuite.Operation.Buffer.BufferParameters(32, GeoAPI.Operation.Buffer.EndCapStyle.Round);
            controlGeometry = precReduc.Reduce((IGeometry)controlGeometry.Clone());
            IGeometry bufferedcontrolgeometry = controlGeometry.Buffer(1.5, bufferPara);

            foreach (var achsref in achsenreferenzenToCheck)
            {
                IGeometry ar = achsref;
                ar = precReduc.Reduce((IGeometry)ar.Clone());
                IGeometry bufferedar = ar.Buffer(1.498, bufferPara);
                IGeometry diff       = bufferedar.Difference(bufferedcontrolgeometry);
                if (!diff.IsEmpty)
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #3
0
        /*
         * public static Geometry OLDReducePrecisionPointwise(Geometry geom, double scaleFactor)
         * {
         *  PrecisionModel pm = new PrecisionModel(scaleFactor);
         *  Geometry reducedGeom = SimpleGeometryPrecisionReducer.Reduce(geom, pm);
         *  return reducedGeom;
         * }
         */

        public static Geometry ReducePrecisionPointwise(Geometry geom, double scaleFactor)
        {
            var pm          = new PrecisionModel(scaleFactor);
            var reducedGeom = GeometryPrecisionReducer.Reduce(geom, pm);

            return(reducedGeom);
        }
        public void TestPolgonWithCollapsedPointPointwise()
        {
            var g       = reader.Read("POLYGON ((10 10, 100 100, 200 10.1, 300 100, 400 10, 10 10))");
            var g2      = reader.Read("POLYGON ((10 10, 100 100, 200 10,   300 100, 400 10, 10 10))");
            var gReduce = GeometryPrecisionReducer.ReducePointwise(g, pmFixed1);

            AssertEqualsExactAndHasSameFactory(gReduce, g2);
        }
        //=======================================

        private void CheckReducePointwise(string wkt, string wktExpected)
        {
            var g         = Read(wkt);
            var gExpected = Read(wktExpected);
            var gReduce   = GeometryPrecisionReducer.ReducePointwise(g, _pmFixed1);

            AssertEqualsExactAndHasSameFactory(gExpected, gReduce);
        }
        public override void StartRun(int npts)
        {
            _sineStar        = SineStarFactory.Create(new Coordinate(OriginX, OriginY), Size, npts, NumberOfArms, ArmRatio);
            _sinePolyCrinkly = GeometryPrecisionReducer.Reduce(_sineStar, new PrecisionModel(Size));

            Console.WriteLine();
            Console.WriteLine($"Running with # pts {_sinePolyCrinkly.NumPoints}");
            ////if (npts <= 1000) Console.WriteLine(_sineStar);
        }
        private void CheckReduceExactSameFactory(GeometryPrecisionReducer reducer,
                                                 string wkt,
                                                 string wktExpected)
        {
            var g        = Read(wkt);
            var expected = Read(wktExpected);
            var actual   = reducer.Reduce(g);

            Assert.That(actual.EqualsExact(expected), Is.True);
            Assert.That(expected.Factory, Is.EqualTo(expected.Factory));
        }
        public GeometryPrecisionReducerTest()
        {
            pmFloat             = new PrecisionModel();
            pmFixed1            = new PrecisionModel(1);
            reducer             = new GeometryPrecisionReducer(pmFixed1);
            reducerKeepCollapse = new GeometryPrecisionReducer(pmFixed1);

            gfFloat = new GeometryFactory(pmFloat, 0);
            reader  = new WKTReader(gfFloat);

            reducerKeepCollapse.RemoveCollapsedComponents = false;
        }
        private void CheckReduce(
            GeometryPrecisionReducer reducer,
            string wkt,
            string wktExpected)
        {
            var g        = Read(wkt);
            var expected = Read(wktExpected);
            var actual   = reducer.Reduce(g);

            CheckEqual(expected, actual);
            Assert.That(expected.Factory, Is.EqualTo(expected.Factory));
        }
        public GeometryPrecisionReducerTest()
        {
            //_pmFloat = new PrecisionModel();
            _pmFixed1            = new PrecisionModel(1);
            _reducer             = new GeometryPrecisionReducer(_pmFixed1);
            _reducerKeepCollapse = new GeometryPrecisionReducer(_pmFixed1);

            //_gfFloat = new GeometryFactory(_pmFloat, 0);
            //_reader = new WKTReader(_gfFloat);
            _reader = new WKTReader(NtsGeometryServices.Instance);

            _reducerKeepCollapse.RemoveCollapsedComponents = false;
        }
예제 #11
0
        public static IGeometry NodeWithPointwisePrecision(IGeometry geom, double scaleFactor)
        {
            var pm = new PrecisionModel(scaleFactor);

            var roundedGeom = GeometryPrecisionReducer.Reduce(geom, pm);

            var geomList = new List <IGeometry>();

            geomList.Add(roundedGeom);

            var noder = new GeometryNoder(pm);
            var lines = noder.Node(geomList);

            return(FunctionsUtil.getFactoryOrDefault(geom).BuildGeometry(CollectionUtil.Cast <IGeometry>((ICollection)lines)));
        }
예제 #12
0
        /// <summary>
        /// Reduces precision pointwise, then snap-rounds.
        /// Note that output set may not contain non-unique linework
        /// (and thus cannot be used as input to Polygonizer directly).
        /// UnaryUnion is one way to make the linework unique.
        /// </summary>
        /// <param name="geom">A geometry containing linework to node</param>
        /// <param name="scaleFactor">the precision model scale factor to use</param>
        /// <returns>The noded, snap-rounded linework</returns>
        public static IGeometry SnapRoundWithPointwisePrecisionReduction(IGeometry geom, double scaleFactor)
        {
            var pm = new PrecisionModel(scaleFactor);

            var roundedGeom = GeometryPrecisionReducer.ReducePointwise(geom, pm);

            var geomList = new List <IGeometry>();

            geomList.Add(roundedGeom);

            var noder = new GeometryNoder(pm);
            var lines = noder.Node(geomList);

            return(FunctionsUtil.GetFactoryOrDefault(geom).BuildGeometry(lines.Cast <IGeometry>().ToArray()));
        }
        public static Geometry NodeWithPointwisePrecision(Geometry geom, double scaleFactor)
        {
            var pm = new PrecisionModel(scaleFactor);

            var roundedGeom = GeometryPrecisionReducer.Reduce(geom, pm);

            var geomList = new List <Geometry>();

            geomList.Add(roundedGeom);

            var noder = new GeometryNoder(pm);
            var lines = noder.Node(geomList);

            return(Utility.FunctionsUtil.getFactoryOrDefault(geom).BuildGeometry(lines.Cast <Geometry>().ToList()));
        }
        private static void Test(int nPts)
        {
            const double size     = 100;
            var          origin   = new Coordinate(0, 0);
            var          sinePoly = CreateSineStar(origin, size, nPts).Boundary;

            /**
             * Make the geometry "crinkly" by rounding off the points.
             * This defeats the  MonotoneChain optimization in the full relate
             * algorithm, and provides a more realistic test.
             */
            var sinePolyCrinkly = GeometryPrecisionReducer.Reduce(sinePoly,
                                                                  new PrecisionModel(size / 10));
            var target = sinePolyCrinkly;

            TestRectangles(target, 100);
        }
예제 #15
0
        public static IGeometry SnapRound(
            IGeometry geomA, IGeometry geomB,
            double scaleFactor)
        {
            var pm = new PrecisionModel(scaleFactor);

            var roundedGeomA = GeometryPrecisionReducer.ReducePointwise(geomA, pm);
            var geomRound    = roundedGeomA;

            if (geomB != null)
            {
                var roundedGeomB = GeometryPrecisionReducer.ReducePointwise(geomB, pm);
                geomRound = geomA.Factory.CreateGeometryCollection(new [] { roundedGeomA, roundedGeomB });
            }

            var       noder   = new GeometrySnapRounder(pm);
            IGeometry snapped = noder.Node(geomRound);

            return(snapped);
        }
예제 #16
0
        public void TestIssue177()
        {
            var reader = new WKTReader();
            var g1     = reader.Read("MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))");
            var g2     = reader.Read("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))");

            IGeometry res = null;

            //                                                                                     |
            //                                                             Some cruel scale factor V
            Assert.DoesNotThrow(() => res = SnapRoundOverlayFunctions.SnappedIntersection(g1, g2, 0.1));
            Assert.That(res, Is.Not.Null);
            Assert.That(res.IsValid, Is.True);

            ToImage(0, g1, g2, res);

            // To show that the result is correct:
            var r1 = new GeometryPrecisionReducer(new PrecisionModel(0.1)).Reduce(g1);
            var r2 = new GeometryPrecisionReducer(new PrecisionModel(0.1)).Reduce(g2);

            ToImage(0, r1, r2, res);
        }
예제 #17
0
        public bool CheckOverlapp(IEnumerable <IGeometry> alte_achsenreferenzen, IGeometry neue_achsenreferenz)
        {
            GeometryPrecisionReducer precReduc = new GeometryPrecisionReducer(new PrecisionModel(1000));

            neue_achsenreferenz = precReduc.Reduce(neue_achsenreferenz);
            foreach (var alte_achsenreferenz in alte_achsenreferenzen)
            {
                IGeometry alteGeometry = alte_achsenreferenz;
                alteGeometry = precReduc.Reduce(alteGeometry);

                if (neue_achsenreferenz.Coordinates.Length == 2)
                {
                    double distancefirst = alteGeometry.Distance(neue_achsenreferenz.Factory.CreatePoint(neue_achsenreferenz.Coordinates.First()));
                    double distancelast  = alteGeometry.Distance(neue_achsenreferenz.Factory.CreatePoint(neue_achsenreferenz.Coordinates.Last()));
                    if (distancefirst < 0.001 && distancelast < 0.001)
                    {
                        return(false);
                    }
                }


                if (alteGeometry.Coordinates.Length == 2)
                {
                    double distancefirst = neue_achsenreferenz.Distance(alteGeometry.Factory.CreatePoint(alteGeometry.Coordinates.First()));
                    double distancelast  = neue_achsenreferenz.Distance(alteGeometry.Factory.CreatePoint(alteGeometry.Coordinates.Last()));
                    if (distancefirst < 0.001 && distancelast < 0.001)
                    {
                        return(false);
                    }
                }


                //Is the new Achsenreferenz-Geometry intersecting with existing achsenreferenzen?
                if (neue_achsenreferenz.Intersects(alteGeometry))
                {
                    //check if the intersection is just the snapping point of the two geometries
                    IGeometry intersection = neue_achsenreferenz.Intersection(alteGeometry);
                    bool      intersectionisfirstorlastpoint_neu = intersection.Coordinates[0].Equals3D(neue_achsenreferenz.Coordinates.First());
                    intersectionisfirstorlastpoint_neu |= intersection.Coordinates[0].Equals3D(neue_achsenreferenz.Coordinates.Last());

                    bool intersectionisfirstorlastpoint_alt = intersection.Coordinates[0].Equals3D(alteGeometry.Coordinates.First());
                    intersectionisfirstorlastpoint_alt |= intersection.Coordinates[0].Equals3D(alteGeometry.Coordinates.Last());



                    if (!(intersection.GetType() == typeof(Point) && (intersectionisfirstorlastpoint_neu || intersectionisfirstorlastpoint_alt)))
                    {
                        return(false);
                    }
                }
                else
                {
                    //check if lines with nonsimilar points overlap
                    NetTopologySuite.Operation.Buffer.BufferParameters bufferPara = new NetTopologySuite.Operation.Buffer.BufferParameters(0, GeoAPI.Operation.Buffer.EndCapStyle.Flat);
                    IGeometry alt_bufferedstrabs = alteGeometry.Buffer(0.001d, bufferPara);

                    IGeometry intersect = alt_bufferedstrabs.Intersection(neue_achsenreferenz);

                    if (intersect.Length > 0.001)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        public static IEnumerable <IGeometry> Reduce(ICollection <IGeometry> geometries, double precision)
        {
            var reducer = new GeometryPrecisionReducer(new PrecisionModel(precision));

            return(geometries.Select(o => reducer.Reduce(o)));
        }
예제 #19
0
        public void TestDifferenceOfComplexMultipolygons()
        {
            string pol1String =
                @"MULTIPOLYGON (((636192.59787309519 6154321.6995911133,
636182.897398793 6154321.8655825993,
636173.596086427 6154322.1355276527,
636167.86522464128 6154325.0849273112,
636161.6231205092 6154326.6646057721,
636160.17831999587 6154326.7813923974,
636161.62312051 6154326.66460577,
636167.86343093 6154325.08425578,
636173.59608643 6154322.13552765,
636182.89523056 6154321.86485684,
636185.751571696 6154321.8162046,
636192.59787309519 6154321.6995911133)),
((636152.84859301744 6154319.8801070936,
636153.02270491 6154322.12552969,
636154.630037279 6154324.02402822,
636157.17036459 6154327.02453251,
636157.17036458931 6154327.02453251,
636153.02270490839 6154322.1255296879,
636152.84859301744 6154319.8801070936)),
((636211.11390913755 6154314.0155097777,
636211.114677974 6154314.0171801187,
636207.437031418 6154321.4456680715,
636207.43681213306 6154321.4456718238,
636211.11390913755 6154314.0155097777)),
((636203.68238669413 6154308.2698675757,
636208.89654585847 6154309.1981610162,
636209.84867722925 6154311.2667209692,
636208.89554388 6154309.19807967,
636203.68238669413 6154308.2698675757)),
((636172.16130951955 6154302.44953468,
636178.5428774301 6154303.7584576393,
636172.16345147 6154302.45243773,
636158.325838736 6154303.24290477,
636158.1491036 6154303.25300068,
636157.253171342 6154304.03329127,
636152.6634752 6154308.0305764,
636152.581231977 6154315.22303587,
636152.56918352365 6154316.2767155087,
636152.65988775936 6154308.0283991182,
636158.15162006055 6154303.2493718751,
636172.16130951955 6154302.44953468)))";

            string pol2String =
                @"MULTIPOLYGON (((636167.79101204267 6154298.2703853333,
636168.33523776615 6154298.2803832982,
636170.65232001338 6154298.4203548077,
636170.69354923489 6154298.4303527726,
636171.18829989259 6154298.4703446319,
636173.33221940952 6154298.7302917205,
636173.42292369681 6154298.7502876511,
636174.0083786418 6154298.8402693355,
636174.02487033047 6154298.8502673,
636176.01211880578 6154299.2501858976,
636176.56459037366 6154299.3701614775,
636177.13355363009 6154299.5501248464,
636177.521108312 6154299.690096355,
636179.05483535107 6154300.2899742518,
636179.219752237 6154300.3499620417,
636179.75573211617 6154300.5999111654,
636180.27522030682 6154300.8698562188,
636180.76997096464 6154301.1897910973,
636180.976117072 6154301.3197646411,
636182.44387735671 6154302.3595529953,
636182.71599021845 6154302.5695102587,
636183.177757499 6154302.9394349623,
636183.60654140241 6154303.33935356,
636184.01058777294 6154303.7692660522,
636184.38165076624 6154304.2291724393,
636184.72797622671 6154304.7090747571,
636184.85528403521 6154304.9176677912,
636179.86541827 6154304.02921314,
636172.16345147 6154302.45243773,
636158.325838736 6154303.24290477,
636158.1491036 6154303.25300068,
636157.253171342 6154304.03329127,
636152.6634752 6154308.0305764,
636152.581231977 6154315.22303587,
636152.56918347 6154316.2767202,
636153.02270491 6154322.12552969,
636154.630037279 6154324.02402822,
636157.17036459 6154327.02453251,
636157.518183773 6154326.99641747,
636161.62312051 6154326.66460577,
636167.86343093 6154325.08425578,
636173.59608643 6154322.13552765,
636182.89523056 6154321.86485684,
636184.8490700468 6154321.8315769676,
636184.60428856232 6154322.2854971271,
636184.46410920925 6154322.525448286,
636183.4416245165 6154324.1751125008,
636183.2767076306 6154324.4350595893,
636182.93038217013 6154324.9149619071,
636182.55931917683 6154325.3748682942,
636182.1552728063 6154325.8047807869,
636181.72648890293 6154326.204699385,
636181.26472162234 6154326.5746240877,
636180.7864626532 6154326.9145548958,
636180.29171199538 6154327.2344897734,
636179.77222380473 6154327.5044348277,
636179.70625705039 6154327.5444266871,
636178.88167262077 6154327.9343473194,
636176.35019842186 6154329.2740746224,
636176.11931478162 6154329.3940502014,
636175.58333490242 6154329.6439993251,
636175.03086333454 6154329.8439586237,
636174.46190007811 6154330.0239219926,
636173.89293682168 6154330.1538955374,
636173.30748187669 6154330.2438772218,
636172.7220269317 6154330.3038650118,
636172.202538741 6154330.3238609415,
636170.808991055 6154330.3338589063,
636170.74302430055 6154330.3338589063,
636170.41319052875 6154330.3338589063,
636168.17032088025 6154330.2438772218,
636167.634341001 6154330.2538751867,
636163.00017650658 6154331.173687961,
636162.4147215616 6154331.2636696463,
636162.18383792136 6154331.2936635409,
636157.70634446852 6154331.7635678928,
636157.35177316377 6154331.7935617883,
636156.76631821878 6154331.8135577179,
636156.1808632738 6154331.7935617883,
636155.59540832881 6154331.7335739983,
636155.00995338371 6154331.6435923139,
636154.44099012727 6154331.5036208043,
636154.02869791246 6154331.39364319,
636152.30531645461 6154330.8437551185,
636152.148645413 6154330.7837673286,
636151.59617384523 6154330.58380803,
636151.06019396591 6154330.3338589063,
636150.54070577526 6154330.0639138529,
636150.04595511756 6154329.7439789744,
636149.5676961483 6154329.4040481662,
636149.10592886782 6154329.0341234636,
636148.67714496434 6154328.6342048654,
636148.56170314422 6154328.5142292865,
636148.05046079785 6154327.9843371445,
636147.76185624755 6154327.6744002309,
636147.39079325413 6154327.2144938437,
636147.04446779378 6154326.7345915269,
636146.73937155481 6154326.2346932795,
636146.45901284879 6154325.7147991024,
636146.23637505271 6154325.2348967856,
636145.69214932923 6154323.9451593077,
636145.67565764056 6154323.8851715177,
636145.46126568888 6154323.3352834461,
636145.296348803 6154322.7753974088,
636145.27985711442 6154322.7254075846,
636144.71913970227 6154320.5858430862,
636144.60369788215 6154320.0659489091,
636144.50474775059 6154319.5160608375,
636144.38106008607 6154318.6062460281,
636144.38106008607 6154318.5662541678,
636144.348076709 6154318.3163050441,
636144.16666813439 6154316.4966754252,
636144.05947215855 6154315.5468687555,
636144.02648878144 6154315.1569481222,
636144.00999709277 6154314.5670681912,
636144.02648878144 6154313.9771882594,
636144.0842096915 6154313.3873083275,
636144.18315982306 6154312.80742636,
636144.31509333174 6154312.2375423592,
636144.36456839752 6154312.05757899,
636144.405797619 6154311.6776563218,
636144.50474775059 6154311.0877763908,
636144.55422281637 6154310.847825232,
636144.81808983383 6154309.6880612988,
636144.90054827684 6154309.3581284555,
636145.06546516274 6154308.798242419,
636145.27985711442 6154308.2483543465,
636145.51898659894 6154307.70846424,
636145.79934530507 6154307.1885700626,
636146.104441544 6154306.6886718152,
636146.12917907687 6154306.6586779207,
636147.300088967 6154304.9190320205,
636147.62167689449 6154304.4691235982,
636147.99273988779 6154304.009217211,
636148.39678625832 6154303.5793047184,
636148.5699489885 6154303.4193372792,
636149.55120445974 6154302.4895265391,
636149.80682563293 6154302.2495753812,
636150.26859291352 6154301.8796506776,
636150.74685188266 6154301.53971987,
636151.24160254048 6154301.2197849918,
636151.76109073113 6154300.9498399384,
636152.04144943715 6154300.8098684289,
636153.32780114736 6154300.2299864627,
636153.58342232055 6154300.1200088477,
636154.13589388831 6154299.9200495491,
636154.70485714474 6154299.74008618,
636154.91100325214 6154299.690096355,
636155.94173378916 6154299.4401472323,
636156.30455093819 6154299.3601635126,
636156.8900058833 6154299.2701818282,
636157.12088952353 6154299.2401879327,
636159.77605138684 6154298.9602449145,
636160.056410093 6154298.93025102,
636164.47618263564 6154298.6103161415,
636166.69431475119 6154298.3403710881,
636167.20555709756 6154298.290381263,
636167.79101204267 6154298.2703853333)))";
            var      polygon1 = /*(MultiPolygon)*/ new WKTReader().Read(pol1String);
            var      polygon2 = /*(MultiPolygon)*/ new WKTReader().Read(pol2String);
            Geometry result   = null;

            while (true)
            {
                try
                {
                    result = polygon1.Difference(polygon2);
                    break;
                }
                catch (TopologyException ex)
                {
                    polygon1 = InsertTopologyExceptionPoint(ex.Coordinate, polygon1);
                    polygon2 = InsertTopologyExceptionPoint(ex.Coordinate, polygon2);
                }
            }

            Assert.IsNotNull(result);
            double area = 0;

            Assert.DoesNotThrow(() => area = result.Area);
            Assert.AreEqual(0.01025390625, area, 0.01);

            Console.WriteLine("WKT : {0}", result.AsText());
            Console.WriteLine("Area: {0}", area);

            //2nd Attempt
            var gpr = new GeometryPrecisionReducer(new PrecisionModel(10000000000));
            var p1  = gpr.Reduce(polygon1);
            var p2  = gpr.Reduce(polygon2);

            result = null;
            Assert.DoesNotThrow(() => result = p1.Difference(p2));
            area = 0;
            Assert.DoesNotThrow(() => area = result.Area);
            Assert.AreEqual(0.01025390625, area, 0.01);

            Console.WriteLine("WKT : {0}", result.AsText());
            Console.WriteLine("Area: {0}", area);
        }