public void TopoJsonWriterWrittenContentTest()
        {
            GeometryFactory factory = new GeometryFactory();
            IMultiPolygon   mp      = factory.CreateMultiPolygon
                                      (
                new List <IPolygon>
            {
                factory.CreatePolygon(factory.CreatePoint(10, 10),
                                      factory.CreatePoint(20, 10),
                                      factory.CreatePoint(25, 17),
                                      factory.CreatePoint(10, 10)),

                factory.CreatePolygon(factory.CreatePoint(50, 30),
                                      factory.CreatePoint(40, 20),
                                      factory.CreatePoint(20, 10),
                                      factory.CreatePoint(25, 17),
                                      factory.CreatePoint(30, 30),
                                      factory.CreatePoint(50, 30))
            }
                                      );

            Assert.AreEqual(2, mp.Count);

            IMultiPoint p = factory.CreateMultiPoint(
                new IPoint[2]
            {
                factory.CreatePoint(10, 10),
                factory.CreatePoint(23, 23)
            });

            ILineString lstr = factory.CreateLineString(
                factory.CreatePoint(50, 60),
                factory.CreatePoint(55, 60),
                factory.CreatePoint(71, 71)
                );

            List <IGeometry> geo = new List <IGeometry>()
            {
                p, lstr
            };

            string outFileName = _outputPath + ".topojson";

            TopoJsonWriter writer = new TopoJsonWriter(outFileName);

            writer.Write(mp as IGeometry);
            writer.Write(geo);
            writer.Close();

            TopoJsonReader    reader     = new TopoJsonReader(outFileName);
            IList <IGeometry> geometries = reader.ReadToEnd();

            reader.Close();

            GeometryComparer comp = new GeometryComparer();

            Assert.AreEqual(0, comp.Compare(geometries[0], mp));
            Assert.AreEqual(0, comp.Compare(geometries[1], p));
            Assert.AreEqual(0, comp.Compare(geometries[2], lstr));
        }
 public void read_quantized_data()
 {
     const string data = TopoData.Quantized;
     TopoJsonReader reader = new TopoJsonReader(Factory);
     IDictionary<string, FeatureCollection> coll = reader.
         Read<IDictionary<string, FeatureCollection>>(data);
     ValidateData(coll);       
 }
 public void read_reference_data()
 {
     const string data = TopoReaderData.Reference;
     TopoJsonReader reader = new TopoJsonReader(Factory);
     IDictionary<string, FeatureCollection> coll = reader.
         Read<IDictionary<string, FeatureCollection>>(data);
     ValidateData(coll);
 }
Esempio n. 4
0
        public void read_multi_reference_data()
        {
            const string   data   = TopoData.MultiReference;
            TopoJsonReader reader = new TopoJsonReader(Factory);
            IDictionary <string, FeatureCollection> coll = reader.
                                                           Read <IDictionary <string, FeatureCollection> >(data);

            ValidateMulti(coll);
        }
Esempio n. 5
0
        public void read_quantized_data()
        {
            const string   data   = TopoData.Quantized;
            TopoJsonReader reader = new TopoJsonReader(Factory);
            IDictionary <string, FeatureCollection> coll = reader.
                                                           Read <IDictionary <string, FeatureCollection> >(data);

            ValidateData(coll);
        }
Esempio n. 6
0
        public void read_airports_data()
        {
            const string   data   = TopoData.Airports;
            TopoJsonReader reader = new TopoJsonReader(Factory);
            IDictionary <string, FeatureCollection> coll = reader.
                                                           Read <IDictionary <string, FeatureCollection> >(data);
            FeatureCollection fc = coll["airports"];

            Assert.That(fc.Count, Is.EqualTo(1));
            // test here: http://jsfiddle.net/D_Guidi/3atZU/embedded/result/
            Console.WriteLine(fc[0].Geometry);
        }
        public void TopoJsonReaderHandleInvalidJsonTest()
        {
            TopoJsonReader reader = new TopoJsonReader(_invalidInputJsonFilePath);

            Assert.Throws <InvalidDataException>(() => reader.Read());

            reader.Close();

            reader = new TopoJsonReader(_invalidInputTopoJsonFilePath);

            Assert.Throws <InvalidDataException>(() => reader.Read());

            reader.Close();
        }
        public void TopoJsonReaderOpenCloseTest()
        {
            foreach (string path in _inputFilePaths)
            {
                TopoJsonReader reader = new TopoJsonReader(path);

                Assert.AreEqual(0, reader.Parameters.Count);
                Assert.IsNotNull(reader.BaseStream);
                Assert.IsNotNull(reader.Path);
                Assert.IsFalse(reader.EndOfStream);

                reader.Close();

                Assert.Throws <ObjectDisposedException>(() => reader.Read());
                Assert.Throws <ObjectDisposedException>(() => { bool value = reader.EndOfStream; });
            }
        }
        public void TopoJsonWriterWriteTest()
        {
            IList <IGeometry> geometries = null;

            foreach (string path in _inputFilePaths)
            {
                TopoJsonReader reader = new TopoJsonReader(path);
                geometries = reader.ReadToEnd();
                reader.Close();

                string outFileName = _outputPath + Path.GetFileName(path);

                TopoJsonWriter writer = new TopoJsonWriter(outFileName);
                writer.Write(geometries);
                writer.Close();
            }
        }
        public void TopoJsonReaderReadContentTest()
        {
            GeometryFactory factory = new GeometryFactory();

            //test 1st input file
            TopoJsonReader reader = new TopoJsonReader(_inputFilePaths[0]);

            IGeometry result = reader.Read();

            Assert.IsInstanceOf(typeof(IGeometryCollection <IGeometry>), result);

            IGeometryCollection <IGeometry> collection = result as IGeometryCollection <IGeometry>;

            Assert.AreEqual(2, collection.Count);
            Assert.IsInstanceOf(typeof(IPolygon), collection[0]);
            Assert.IsInstanceOf(typeof(IPolygon), collection[1]);

            IPolygon left_polygon = factory.CreatePolygon(new Coordinate[]
            {
                new Coordinate(1, 2),
                new Coordinate(1, 0),
                new Coordinate(0, 0),
                new Coordinate(0, 2),
                new Coordinate(1, 2)
            });

            IPolygon right_polygon = factory.CreatePolygon(new Coordinate[]
            {
                new Coordinate(1, 2),
                new Coordinate(2, 2),
                new Coordinate(2, 0),
                new Coordinate(1, 0),
                new Coordinate(1, 2)
            });

            GeometryComparer comp = new GeometryComparer();

            //System.Diagnostics.Debug.WriteLine((collection[0] as IPolygon).Shell.ToString());

            Assert.AreEqual(0, comp.Compare(collection[0], left_polygon));
            Assert.AreEqual(0, comp.Compare(collection[1], right_polygon));

            reader.Close();
        }
        public void TopoJsonReaderReadToEndTest()
        {
            foreach (string path in _inputFilePaths)
            {
                TopoJsonReader reader = new TopoJsonReader(path);

                Assert.AreEqual(0, reader.Parameters.Count);
                Assert.IsNotNull(reader.BaseStream);
                Assert.IsNotNull(reader.Path);
                Assert.IsFalse(reader.EndOfStream);

                IList <IGeometry> result = reader.ReadToEnd();

                Assert.IsTrue(reader.EndOfStream);
                Assert.AreEqual(0, reader.ReadToEnd().Count);

                reader.Close();
            }
        }
 public void read_counties_data()
 {
     const string data = TopoData.Counties;
     TopoJsonReader reader = new TopoJsonReader(Factory);
     IDictionary<string, FeatureCollection> coll = reader.
         Read<IDictionary<string, FeatureCollection>>(data);
     FeatureCollection fc = coll["counties"];
     Assert.That(fc.Count, Is.EqualTo(2));
     // test here: http://jsfiddle.net/D_Guidi/3atZU/embedded/result/
     Console.WriteLine(fc[0].Geometry);
     Console.WriteLine(fc[1].Geometry);
 }