示例#1
0
        private static void DoTest(Type expectedType)
        {
            string name    = expectedType.Name;
            string file    = String.Format("{0}s", name.ToLowerInvariant().Substring(1));
            string resname = String.Format("NetTopologySuite.Tests.NUnit.TestData.{0}.xml", file);
            string path    = EmbeddedResourceManager.SaveEmbeddedResourceToTempFile(resname);

            var doc =
#if !PCL
                new XmlDocument();

            doc.Load(path);
#else
                XDocument.Load(path);
#endif

            GMLReader           gr = new GMLReader();
            IGeometryCollection gc = (IGeometryCollection)gr.Read(doc);
            Assert.IsTrue(gc.NumGeometries == 25);
            for (int i = 0; i < 25; i++)
            {
                IGeometry g = gc.GetGeometryN(i);
                Assert.IsNotNull(g);
                Assert.IsInstanceOf(expectedType, g);
            }
        }
        public void TestPerformanceAfrica()
        {
            var filePath = EmbeddedResourceManager.SaveEmbeddedResourceToTempFile("NetTopologySuite.Tests.NUnit.TestData.africa.wkt");

            //    runTest(TestFiles.DATA_DIR + "world.wkt");
            PerformanceTest(filePath);

            EmbeddedResourceManager.CleanUpTempFile(filePath);
        }
示例#3
0
        public void TestAll()
        {
            var filePath = EmbeddedResourceManager.SaveEmbeddedResourceToTempFile("NetTopologySuite.Tests.NUnit.TestData.europe.wkt");

            CheckInteriorPointFile(filePath);
            filePath = EmbeddedResourceManager.SaveEmbeddedResourceToTempFile("NetTopologySuite.Tests.NUnit.TestData.africa.wkt");
            CheckInteriorPointFile(filePath);
            //checkInteriorPointFile("../../../../../data/africa.wkt");
        }
        public void TestEurope()
        {
#if !PCL
            var filePath = EmbeddedResourceManager.SaveEmbeddedResourceToTempFile(
                "NetTopologySuite.Tests.NUnit.TestData.europe.wkt");

            RunTest(filePath,
                    CascadedPolygonUnionTester.MinSimilarityMeaure);

            EmbeddedResourceManager.CleanUpTempFile(filePath);
#else
            var europe = EmbeddedResourceManager.GetResourceStream("NetTopologySuite.Tests.NUnit.TestData.europe.wkt");
            RunTest(europe, CascadedPolygonUnionTester.MinSimilarityMeaure);
#endif
        }
        public void Test()
        {
            Trace.WriteLine("Loading data...");
            string filePath = EmbeddedResourceManager.SaveEmbeddedResourceToTempFile(
                "NetTopologySuite.Tests.NUnit.TestData.world.wkt");
            IList <IGeometry> data = GeometryUtils.ReadWKTFile(filePath);

            const int maxTimes = 5;

            for (int i = 1; i <= maxTimes; i++)
            {
                Trace.WriteLine(String.Format("Iteration {0} of {1} started", i, maxTimes));
                RunDissolverWorld(data);
                RunBruteForceWorld(data);
                Trace.WriteLine(String.Format("Iteration {0} of {1} terminated", i, maxTimes));
                Trace.WriteLine(Environment.NewLine);
            }

            EmbeddedResourceManager.CleanUpTempFile(filePath);
            Trace.WriteLine("Test terminated");
        }
        public void TestNewResultsIdenticalToOldResults()
        {
            // at 0.02, Simplify deletes about 50% of world.wkt points
            const double DistanceTolerance = 0.02;

            int pointsRemoved   = 0;
            int totalPointCount = 0;

            // track how long the new takes compared to the old
            long oldTicks = 0;
            long newTicks = 0;

            string filePath = EmbeddedResourceManager.SaveEmbeddedResourceToTempFile("NetTopologySuite.Tests.NUnit.TestData.world.wkt");

            foreach (ILineString line in GeometryUtils.ReadWKTFile(filePath).SelectMany(LinearComponentExtracter.GetLines))
            {
                Coordinate[] coordinates = line.Coordinates;

                Stopwatch    sw         = Stopwatch.StartNew();
                Coordinate[] oldResults = OldVWLineSimplifier.Simplify(coordinates, DistanceTolerance);
                sw.Stop();

                oldTicks += sw.ElapsedTicks;

                sw.Restart();
                Coordinate[] newResults = VWLineSimplifier.Simplify(coordinates, DistanceTolerance);
                sw.Stop();

                newTicks += sw.ElapsedTicks;

                CollectionAssert.AreEqual(oldResults, newResults);

                pointsRemoved   += coordinates.Length - newResults.Length;
                totalPointCount += coordinates.Length;
            }

            Console.WriteLine("Total: Removed {0} of {1} points (reduction: {2:P0}).", pointsRemoved, totalPointCount, pointsRemoved / (double)totalPointCount);
            Console.WriteLine("Old: {0:N3} seconds.  New: {1:N3} seconds (reduction: {2:P0}).", oldTicks / (double)Stopwatch.Frequency, newTicks / (double)Stopwatch.Frequency, (oldTicks - newTicks) / (double)oldTicks);
        }
        private static void ReadAndTest(string file)
        {
            Console.WriteLine(file);
            var path = EmbeddedResourceManager.SaveEmbeddedResourceToTempFile("NetTopologySuite.Samples.Tests.Various." + file);
            var gml  = File.ReadAllText(path);

            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(gml);
            var gmlNode = xmlDoc.DocumentElement.FirstChild.NextSibling.FirstChild.LastChild.InnerXml;

            Console.WriteLine(gmlNode);

            var gmlReader = new NetTopologySuite.IO.GML2.GMLReader();
            var geom      = gmlReader.Read(gmlNode);

            Assert.IsNotNull(geom);
            Assert.IsFalse(geom.IsEmpty);

            Console.WriteLine(geom.ToString());
            Console.WriteLine(new string('=', 60));

            EmbeddedResourceManager.CleanUpTempFile(path);
        }