/// <inheritdoc cref="IGeometryReader{TSource}.Read(Stream)"/>>
        public IGeometry Read(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            using (var reader = new BinaryReader(stream))
            {
                var header   = GeoPackageBinaryHeader.Read(reader);
                var services = new NtsGeometryServices(_coordinateSequenceFactory,
                                                       _precisionModel, HandleSRID ? header.SrsId : -1);
                // NOTE: GeoPackage handle SRID in header, so no need to read this also in wkb;
                const bool dontHandleSRID = false;
                var        wkbReader      = new WKBReader(services)
                {
                    HandleSRID      = dontHandleSRID,
                    HandleOrdinates = HandleOrdinates,
                    RepairRings     = RepairRings
                };
                var geom = wkbReader.Read(stream);
                if (HandleSRID)
                {
                    geom.SRID = header.SrsId;
                }
                return(geom);
            }
        }
Esempio n. 2
0
        private static bool TestWktWkb(int number, NtsGeometryServices gs, string wkt, string wkb)
        {
            var r       = new WKTReader(gs);
            var wktGeom = r.Read(wkt);
            var s       = new WKBReader(gs);
            var wkbGeom = s.Read(WKBReader.HexToBytes(wkb));

            try
            {
                Assert.AreEqual(wkb, WKBWriter.ToHex(wktGeom.AsBinary()), "wkb's don't match");
                Assert.IsTrue(DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9, number + ": DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9");
                if (!wktGeom.EqualsExact(wkbGeom))
                {
                    Assert.AreEqual(wkt, wktGeom.AsText(), number + ": wkt.Equals(wktGeom.AsText())");
                    var wktGeom2 = s.Read(wktGeom.AsBinary());
                    Assert.AreEqual(wkt, wktGeom2.AsText(), number + ": wkt.Equals(wktGeom2.AsText())");
                    var diff = wkbGeom.Difference(wktGeom);
                    Assert.IsTrue(false, number + ": wktGeom.EqualsExact(wkbGeom)\n" + diff.AsText());
                }
                return(false);
            }
            catch (AssertionException ex)
            {
                Console.WriteLine(ex.Message);
                return(true);
            }
        }
        public string GetFile()
        {
            if (!Directory.Exists(Constans.Constans.PathToSaveFile))
            {
                throw new Exception(Constans.Constans.AppDataFolderDosentExists);
            }
            string       resultGeoJson = "";
            var          stream        = HttpContext.Current.Request.GetBufferedInputStream();
            StreamReader reader        = new StreamReader(stream);

            reader.ReadToEnd();

            var postedFile = HttpContext.Current.Request.Files[Constans.Constans.FormObjectName];
            var ignore     = HttpContext.Current.Request.InputStream;

            if (postedFile != null)
            {
                ClearDataDirectory(Constans.Constans.PathToSaveFile);
                var pathToZipFile = Path.Combine(Constans.Constans.PathToSaveFile, postedFile.FileName);
                postedFile.SaveAs(pathToZipFile);

                string fullPathToShpFile = ZipFileHelper.ExtractZipFile(pathToZipFile);

                IGeometryServices geometryServices = new NtsGeometryServices();

                ShapeFileHelper shapeFileHelper = new ShapeFileHelper(fullPathToShpFile);
                resultGeoJson = shapeFileHelper.ConvertShapeFileToGeoJson();
                ClearDataDirectory(Constans.Constans.PathToSaveFile);
            }
            return(resultGeoJson);
        }
Esempio n. 4
0
        public ConvexHullTest()
        {
            var gs = new NtsGeometryServices(new PrecisionModel(1000), 0);

            _geometryFactory = gs.CreateGeometryFactory();
            _reader          = new WKTReader(gs);
        }
        private static Geometry ReadGeometryFromWkbHexString(string wkbHexFile, NtsGeometryServices geomServ)
        {
            var    reader = new WKBReader(geomServ);
            string wkbHex = CleanHex(wkbHexFile);

            return(reader.Read(WKBReader.HexToBytes(wkbHex)));
        }
Esempio n. 6
0
        public IsValidTest()
        {
            var gs = new NtsGeometryServices(PrecisionModel.Floating.Value, 0);

            _geometryFactory = gs.CreateGeometryFactory();
            _reader          = new WKTReader(gs);
        }
Esempio n. 7
0
        public void Test()
        {
            var i = new NtsGeometryServices(CsFactory, PrecisionModel.Floating.Value, 0,
                                            GeometryOverlay.Legacy, new PerOrdinateEqualityComparer());
            var f   = i.CreateGeometryFactory();
            var pt1 = f.CreatePoint(new Coordinate(1, 2));
            var pt2 = f.CreatePoint(new CoordinateZ(1, 2, 3));
            var pt3 = f.CreatePoint(new CoordinateM(1, 2, 4));
            var pt4 = f.CreatePoint(new CoordinateZM(1, 2, 3, 4));
            var pt5 = f.CreatePoint(new CoordinateZM(1, 2, double.NaN, 4));
            var pt6 = f.CreatePoint(new Coordinate(1, 2));

            Assert.IsFalse(pt1 == pt2);
            Assert.IsFalse(pt1 == pt3);
            Assert.IsFalse(pt1 == pt4);
            Assert.IsFalse(pt1 == pt5);
            Assert.IsTrue(pt1 == pt6);
            Assert.AreNotEqual(pt1, pt2);
            Assert.AreNotEqual(pt1, pt3);
            Assert.AreNotEqual(pt1, pt4);
            Assert.AreNotEqual(pt2, pt3);
            Assert.AreNotEqual(pt2, pt4);
            Assert.AreNotEqual(pt3, pt4);
            Assert.AreNotEqual(pt4, pt5);
            Assert.AreEqual(pt1, pt6);

            Assert.IsTrue(pt1 == f.CreatePoint(new CoordinateZ(1, 2)));
            Assert.IsTrue(pt1 == f.CreatePoint(new CoordinateM(1, 2)));
            Assert.IsTrue(pt1 == f.CreatePoint(new CoordinateZM(1, 2)));
        }
Esempio n. 8
0
 public SqlServerGeometryTypeMapping([NotNull] NtsGeometryServices geometryServices, [NotNull] string storeType)
     : base(
         new GeometryValueConverter <TGeometry>(
             CreateReader(geometryServices, IsGeography(storeType)),
             CreateWriter(IsGeography(storeType))),
         storeType)
     => _isGeography = IsGeography(storeType);
Esempio n. 9
0
 public MySqlGeometryTypeMapping(NtsGeometryServices geometryServices, string storeType, IMySqlOptions options)
     : base(
         new GeometryValueConverter <TGeometry>(geometryServices),
         storeType)
 {
     _options = options;
 }
Esempio n. 10
0
        public MiscellaneousTest()
        {
            var gs = new NtsGeometryServices(PrecisionModel.Fixed.Value, 0);

            _geometryFactory = gs.CreateGeometryFactory();
            _reader          = new WKTReader(gs);
        }
Esempio n. 11
0
        public LineStringImplTest()
        {
            var gs = new NtsGeometryServices(new PrecisionModel(1000));

            geometryFactory = gs.CreateGeometryFactory(0);
            reader          = new WKTReader(gs);
        }
Esempio n. 12
0
        private void Execute(NtsGeometryServices gs)
        {
            const string wkt1 = @"POLYGON ((34.8998882099012 30.3837960942026, 34.9010566737651 30.3644568453302, 34.952062587058 30.3841960548712, 34.9237694926759 30.3379967024143, 34.8688043479468 30.2722872698552, 34.8675239767921 30.2729668362851, 34.8644624659558 30.2746560404891, 34.8614352803289 30.2763912924804, 34.8584433396252 30.2781720660657, 34.8554875530179 30.2799978212197, 34.8525688188649 30.2818680042466, 34.8496880244379 30.2837820479458, 34.8468460456542 30.2857393717817, 34.8440437468117 30.2877393820578, 34.8412819803279 30.2897814720941, 34.8385615864812 30.291865022409, 34.8358833931563 30.2939894009049, 34.8332482155932 30.2961539630577, 34.8306568561393 30.2983580521099, 34.8281101040059 30.3006009992674, 34.8256087350277 30.3028821239005, 34.8231535114263 30.3052007337477, 34.8207451815784 30.3075561251236, 34.8183844797864 30.3099475831299, 34.8160721260548 30.3123743818706, 34.813808825869 30.3148357846692, 34.8115952699799 30.3173310442906, 34.8094321341915 30.3198594031656, 34.8073200791532 30.3224200936183, 34.8052597501567 30.3250123380972, 34.8038593775008 30.3268416420348, 34.8413134524996 30.34133631112, 34.8380456129141 30.3420679436136, 34.8345469119455 30.3429079098264, 34.8310655827664 30.3438006160548, 34.827824169131 30.3446853380141, 34.827602680711 30.3447457917824, 34.8241592556176 30.3457431505854, 34.8207363515157 30.3467923902175, 34.8173350063135 30.3478931927008, 34.8139562514873 30.34904522442, 34.8106011117732 30.3502481362226, 34.80727060486 30.3515015635225, 34.8039657410851 30.3528051264095, 34.8006875231308 30.3541584297621, 34.7974369457248 30.355561063366, 34.8114061852091 30.3793421607384, 34.8098261518056 30.3806388748041, 34.8072325551456 30.3828429255909, 34.8046836035397 30.3850858339783, 34.8021800734927 30.387366919357, 34.7997227278858 30.3896854894863, 34.797312315744 30.3920408407015, 34.7949495720071 30.3944322581256, 34.7926352173053 30.3968590158832, 34.7903699577383 30.3993203773193, 34.7881544846595 30.4018155952199, 34.8175519633847 30.421036532238, 34.8473374156124 30.4405111377535, 34.8473374156124 30.4405111377536, 34.8945946797018 30.4714093282142, 34.89504284421 30.4639917561117, 34.9249010902965 30.4502666241023, 34.9120339400511 30.4239712613602, 34.8990624811609 30.3974627330299, 34.8990624811609 30.3974627330298, 34.8998882099012 30.3837960942026), (34.8998882099012 30.3837960942026, 34.8896581575596 30.3782440174851, 34.8896581575596 30.3782440174851, 34.8998882099012 30.3837960942026))";
            const string wkt2 = @"POLYGON ((34.89504284421 30.4639917561117, 34.8974881525283 30.4235194508906, 34.8362388038152 30.4216169690234, 34.8683403196915 30.4762662772922, 34.89504284421 30.4639917561117))";

            var reader = new WKTReader(gs);

            var g1 = reader.Read(wkt1);

            Assert.IsFalse(g1.IsValid);
            var v1 = g1.Buffer(0);

            Assert.IsTrue(v1.IsValid);

            var g2 = reader.Read(wkt2);
            //Assert.IsFalse(g2.IsValid);
            var v2 = g2.Buffer(0);

            Assert.IsTrue(v2.IsValid);

            var union1 = g1.Union(g2);

            Assert.IsNotNull(union1);
            Assert.IsTrue(union1.IsValid);

            var union2 = v1.Union(v2);

            Assert.IsNotNull(union2);
            Assert.IsTrue(union2.IsValid);
        }
Esempio n. 13
0
        private void TestFormatting(Coordinate c)
        {
            var gs  = new NtsGeometryServices(PrecisionModel.Floating.Value, 0);
            var rdr = new WKTReader(gs);

            Geometry point  = gs.CreateGeometryFactory().CreatePoint(c);
            string   result = writer.Write(point);

            Debug.WriteLine(result);
            var    geom = rdr.Read(result);
            string tos  = geom.ToString();

            Assert.IsTrue(string.Equals(tos, result));

            point  = gs.CreateGeometryFactory(PrecisionModel.FloatingSingle.Value).CreatePoint(c);
            result = writer.Write(point);
            Debug.WriteLine(result);
            geom = rdr.Read(result);
            tos  = geom.ToString();
            Assert.IsTrue(string.Equals(tos, result));

            point  = gs.CreateGeometryFactory(PrecisionModel.Fixed.Value).CreatePoint(c);
            result = writer.Write(point);
            Debug.WriteLine(result);
            geom = rdr.Read(result);
            tos  = geom.ToString();
            Assert.IsTrue(string.Equals(tos, result));
        }
        public MinimumBoundingCircleTest()
        {
            var gs = new NtsGeometryServices(PrecisionModel.Fixed.Value, 0);

            _geometryFactory = gs.CreateGeometryFactory();
            _reader          = new WKTReader(gs);
        }
Esempio n. 15
0
        public void TestWithTolerance()
        {
            var i = new NtsGeometryServices(CsFactory, PrecisionModel.Floating.Value, 0,
                                            GeometryOverlay.Legacy, new PerOrdinateEqualityComparer());
            var          f         = i.CreateGeometryFactory();
            const double tolerance = 0.001;
            const double allowed   = tolerance;

            var pt = f.CreatePoint(new CoordinateZM(1, 2, 3, 4));

            Assert.That(pt == f.CreatePoint(new CoordinateZM(1 + allowed, 2, 3, 4)), Is.False);
            Assert.That(pt.EqualsExact(f.CreatePoint(new CoordinateZM(1 + allowed, 2, 3, 4)), tolerance), Is.True);
            Assert.That(pt.EqualsExact(f.CreatePoint(new CoordinateZM(Math.BitIncrement(1 + allowed), 2, 3, 4)), tolerance), Is.False);

            Assert.That(pt == f.CreatePoint(new CoordinateZM(1 + allowed, 2, 3, 4)), Is.False);
            Assert.That(pt.EqualsExact(f.CreatePoint(new CoordinateZM(1, 2 + allowed, 3, 4)), tolerance), Is.True);
            Assert.That(pt.EqualsExact(f.CreatePoint(new CoordinateZM(1, Math.BitIncrement(2 + allowed), 3, 4)), tolerance), Is.False);

            Assert.That(pt == f.CreatePoint(new CoordinateZM(1 + allowed, 2, 3, 4)), Is.False);
            Assert.That(pt.EqualsExact(f.CreatePoint(new CoordinateZM(1, 2, 3 - allowed, 4)), tolerance), Is.True);
            Assert.That(pt.EqualsExact(f.CreatePoint(new CoordinateZM(1, 2, Math.BitDecrement(3 - allowed), 4)), tolerance), Is.False);

            Assert.That(pt == f.CreatePoint(new CoordinateZM(1 + allowed, 2, 3, 4)), Is.False);
            Assert.That(pt.EqualsExact(f.CreatePoint(new CoordinateZM(1, 2, 3, 4 - allowed)), tolerance), Is.True);
            Assert.That(pt.EqualsExact(f.CreatePoint(new CoordinateZM(1, 2, 3, Math.BitDecrement(4 - allowed))), tolerance), Is.False);
        }
Esempio n. 16
0
        private static void Main()
        {
            var gss = new NtsGeometryServices();
            var css = new SharpMap.CoordinateSystems.CoordinateSystemServices(
                new CoordinateSystemFactory(),
                new CoordinateTransformationFactory(),
                SharpMap.Converters.WellKnownText.SpatialReference.GetAllReferenceSystems());

            // plug-in WebMercator so that correct spherical definition is directly available to Layer Transformations using SRID
            var pcs = (ProjectedCoordinateSystem)ProjectedCoordinateSystem.WebMercator;

            css.AddCoordinateSystem((int)pcs.AuthorityCode, pcs);

            GeoAPI.GeometryServiceProvider.Instance = gss;
            SharpMap.Session.Instance
            .SetGeometryServices(gss)
            .SetCoordinateSystemServices(css)
            .SetCoordinateSystemRepository(css);

            // for SqlServerSample referencing SharpMap.SqlServerSpatialObjects
            //SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new DlgSamplesMenu());
        }
        private void CheckIntersectionPM(NtsGeometryServices ntsGeometryServices, Geometry expected)
        {
            var a      = Read(ntsGeometryServices, "POLYGON ((1 1, 1 2, 5 1, 1 1))");
            var b      = Read(ntsGeometryServices, "POLYGON ((0 3, 4 3, 4 0, 0 0, 0 3))");
            var actual = a.Intersection(b);

            CheckEqual(expected, actual);
        }
 private void TryIntersection(NtsGeometryServices ntsGeometryServices)
 {
     var a = Read(ntsGeometryServices,
                  "POLYGON ((-1120500.000000126 850931.058865365, -1120500.0000001257 851343.3885007716, -1120500.0000001257 851342.2386007707, -1120399.762684411 851199.4941312922, -1120500.000000126 850931.058865365))");
     var b = Read(ntsGeometryServices,
                  "POLYGON ((-1120500.000000126 851253.4627870625, -1120500.0000001257 851299.8179383819, -1120492.1498410008 851293.8417889411, -1120500.000000126 851253.4627870625))");
     var result = a.Intersection(b);
 }
        public GeometryImplTest()
        {
            var gs = new NtsGeometryServices(CoordinateArraySequenceFactory.Instance, PrecisionModel.Fixed.Value, 0);

            _geometryFactory = gs.CreateGeometryFactory();
            _reader          = new WKTReader(gs);
            _readerFloat     = new WKTReader(new NtsGeometryServices(CoordinateArraySequenceFactory.Instance, PrecisionModel.Floating.Value, 0));
        }
Esempio n. 20
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public MySqlNetTopologySuiteTypeMappingSourcePlugin(
            [NotNull] NtsGeometryServices geometryServices,
            [NotNull] IMySqlOptions options)
        {
            Check.NotNull(geometryServices, nameof(geometryServices));

            _geometryServices = geometryServices;
            _options          = options;
        }
        public XmlTestFactory(PrecisionModel pm, IGeometryOperation geometryOperation, IResultMatcher resultMatcher)
        {
            var gs = new NtsGeometryServices(pm, 0);

            //ObjGeometryFactory = gs.CreateGeometryFactory();
            _geometryOperation = geometryOperation;
            _resultMatcher     = resultMatcher;
            _objReader         = new MultiFormatReader(gs);
        }
Esempio n. 22
0
        public WKBReader(NtsGeometryServices services)
        {
            services          = services ?? NtsGeometryServices.Instance;
            _geometryServices = services;
            _precisionModel   = services.DefaultPrecisionModel;
            _sequenceFactory  = services.DefaultCoordinateSequenceFactory;

            HandleSRID      = true;
            HandleOrdinates = AllowedOrdinates;
        }
        public void TestOverlayNGFloat()
        {
            //GeometryOverlay.setOverlayImpl(GeometryOverlay.OVERLAY_PROPERTY_VALUE_NG);
            var pmFloat             = new PrecisionModel();
            var instance            = NtsGeometryServices.Instance;
            var ntsGeometryServices = new NtsGeometryServices(instance.DefaultCoordinateSequenceFactory, pmFloat, instance.DefaultSRID, GeometryOverlay.NG, instance.CoordinateEqualityComparer);
            var expected            = Read(ntsGeometryServices, "POLYGON ((1 1, 1 2, 4 1.25, 4 1, 1 1))");

            CheckIntersectionPM(ntsGeometryServices, expected);
        }
Esempio n. 24
0
        private void RunWKBTestPackedCoordinate(string wkt)
        {
            var gs = new NtsGeometryServices(
                new PackedCoordinateSequenceFactory(PackedCoordinateSequenceFactory.PackedType.Double));
            var reader = new WKTReader(gs);
            var g      = reader.Read(wkt);

            // Since we are using a PCS of dim=2, only check 2-dimensional storage
            RunWKBTest(g, 2, true);
            RunWKBTest(g, 2, false);
        }
 private void CheckIntersectionSucceeds(NtsGeometryServices ntsGeometryServices)
 {
     try
     {
         TryIntersection(ntsGeometryServices);
     }
     catch (TopologyException)
     {
         Assert.Fail("Intersection operation failed.");
     }
 }
Esempio n. 26
0
        public virtual void  Intersection(string wktA, string wktB, PrecisionModel pm)
        {
            Console.WriteLine("Running example using Precision Model = " + pm);
            var gs     = new NtsGeometryServices(pm);
            var wktRdr = new WKTReader(gs);

            var A = wktRdr.Read(wktA);
            var B = wktRdr.Read(wktB);
            var C = A.Intersection(B);

            Console.WriteLine("A intersection B = " + C);
        }
 private void CheckIntersectionFails(NtsGeometryServices ntsGeometryServices)
 {
     try
     {
         TryIntersection(ntsGeometryServices);
         Assert.Fail("Intersection operation should have failed but did not");
     }
     catch (TopologyException)
     {
         // ignore - expected result
     }
 }
Esempio n. 28
0
        public void TestNormalizePackedCoordinateSequence()
        {
            var pcsGs     = new NtsGeometryServices(PackedCoordinateSequenceFactory.DoubleFactory);
            var pcsReader = new WKTReader(pcsGs);
            var geom      = pcsReader.Read("LINESTRING (100 100, 0 0)");

            geom.Normalize();
            // force PackedCoordinateSequence to be copied with empty coordinate cache
            var clone = (Geometry)geom.Copy();

            AssertAreEqualExact(geom, clone);
        }
        public void TestML()
        {
            {
                const double scale          = 2.0E10;
                var          precisionModel = new PrecisionModel(scale);
                var          gs             = new NtsGeometryServices(precisionModel, 0);
                //var geometryFactory = gs.CreateGeometryFactory();

                var reader      = new WKTReader(gs);
                var lineStringA = (LineString)
                                  reader.Read("LINESTRING (-93.40178610435 -235.5437531975, -401.24229900825 403.69365857925)");
                var lineStringB = (LineString)
                                  reader.Read("LINESTRING (-50.0134121926 -145.44686640725, -357.8539250965 493.7905453695)");
                var lineStringC = (LineString)
                                  reader.Read("LINESTRING (-193.8964147753 -30.64653554935, -186.68866383205 -34.1176054623)");

                var middlePoint = (Point)reader.Read("POINT (-203.93366864454998 174.171839481125)");

                var lineStrings = new List <LineString>();
                lineStrings.Add(lineStringA);
                lineStrings.Add(lineStringB);
                lineStrings.Add(lineStringC);

                var noder            = new GeometryNoder(precisionModel);
                var nodedLineStrings = noder.Node(lineStrings.ToArray());

                double shortestDistanceToPointBeforeNoding = double.MaxValue;

                foreach (var lineString in lineStrings)
                {
                    shortestDistanceToPointBeforeNoding = Math.Min(lineString.Distance(middlePoint),
                                                                   shortestDistanceToPointBeforeNoding);
                }

                double shortestDistanceToPointAfterNoding = double.MaxValue;

                foreach (var lineString in nodedLineStrings)
                {
                    shortestDistanceToPointAfterNoding = Math.Min(lineString.Distance(middlePoint),
                                                                  shortestDistanceToPointAfterNoding);
                }

                double difference = Math.Abs(shortestDistanceToPointAfterNoding - shortestDistanceToPointBeforeNoding);

                TestContext.WriteLine("Scale: {0}", scale);
                TestContext.WriteLine("Distance to point before noding: {0}", shortestDistanceToPointBeforeNoding);
                TestContext.WriteLine("Distance to point after noding:  {0}", shortestDistanceToPointAfterNoding);
                TestContext.WriteLine("Difference is {0} and should be lesser than {1}", difference, 1.0 / scale);

                const double roughTolerance = 10.0;
                Assert.IsTrue(difference < roughTolerance, "this difference should should be lesser than " + 1.0 / scale);
            }
        }
Esempio n. 30
0
        public void TestReadLargeNumbers()
        {
            var precisionModel  = new PrecisionModel(1E9);
            var gs              = new NtsGeometryServices(precisionModel, 0);
            var geometryFactory = gs.CreateGeometryFactory();
            var reader          = new WKTReader(gs);
            var point1          = ((Point)reader.Read("POINT (123456789.01234567890 10)")).CoordinateSequence;
            var point2          = geometryFactory.CreatePoint(new Coordinate(123456789.01234567890, 10)).CoordinateSequence;

            Assert.That(point1.GetOrdinate(0, Ordinate.X), Is.EqualTo(point2.GetOrdinate(0, Ordinate.X)).Within(1E-7));
            Assert.That(point1.GetOrdinate(0, Ordinate.Y), Is.EqualTo(point2.GetOrdinate(0, Ordinate.Y)).Within(1E-7));
        }
        public void TestUninitialized()
        {
            var nts = new NtsGeometryServices();
            var ntsFromGeoApi = GeometryServiceProvider.Instance;

            Assert.IsNotNull(ntsFromGeoApi);
            Assert.IsNotNull(ntsFromGeoApi.DefaultCoordinateSequenceFactory);
            Assert.IsNotNull(ntsFromGeoApi.DefaultPrecisionModel);

            Assert.IsTrue(nts.DefaultCoordinateSequenceFactory == ntsFromGeoApi.DefaultCoordinateSequenceFactory);
            Assert.IsTrue(nts.DefaultPrecisionModel.Equals(ntsFromGeoApi.DefaultPrecisionModel));
        }
        public void TestInitialized()
        {
            var nts =
                new NtsGeometryServices(
                    NetTopologySuite.Geometries.Implementation.DotSpatialAffineCoordinateSequenceFactory.Instance,
                    new PrecisionModel(10d), 4326);

            Assert.Throws<ArgumentNullException>(() => GeometryServiceProvider.Instance = null);

            GeometryServiceProvider.Instance = nts;
            var factory = nts.CreateGeometryFactory();

            Assert.IsNotNull(factory);
            Assert.AreEqual(nts.DefaultSRID, factory.SRID);
            Assert.AreEqual(nts.DefaultPrecisionModel, factory.PrecisionModel);
            Assert.AreEqual(nts.DefaultCoordinateSequenceFactory, factory.CoordinateSequenceFactory);

            // restore default!
            GeometryServiceProvider.Instance = new NtsGeometryServices();
        }