public void GeoJsonReaderReadContentTest() { //test 1st input file GeoJsonReader reader = new GeoJsonReader(_inputFilePaths[0]); IGeometry result = reader.Read(); Assert.IsInstanceOf(typeof(IGeometryCollection <IGeometry>), result); IGeometryCollection <IGeometry> collection = result as IGeometryCollection <IGeometry>; Assert.IsTrue(collection[0] is IPoint); Assert.IsTrue((collection[0] as IPoint).Coordinate == new Coordinate(1, 1, 9)); Assert.IsTrue(collection[1] is IMultiLineString); Assert.AreEqual((collection[1] as IMultiLineString).Count, 2); ILineString lstr = (collection[1] as IMultiLineString)[1]; Assert.AreEqual(5, lstr.Coordinates.Count); Assert.AreEqual(lstr.Coordinates[0], new Coordinate(401, 28)); Assert.AreEqual(lstr.Coordinates[1], new Coordinate(36, 12)); Assert.AreEqual(lstr.Coordinates[2], new Coordinate(100, 37)); Assert.AreEqual(lstr.Coordinates[3], new Coordinate(49, 46)); Assert.AreEqual(lstr.Coordinates[4], new Coordinate(28, 34)); Assert.IsTrue(collection[2] is IMultiPolygon); Assert.AreEqual(2, (collection[2] as IMultiPolygon).Count); Assert.IsTrue(reader.EndOfStream); Assert.AreEqual(0, reader.ReadToEnd().Count); reader.Close(); }
public void GeoJsonReaderHandleUnsupportedCrsTest() { GeoJsonReader reader = new GeoJsonReader(_invalidInputJsonFilePath); Assert.Throws <InvalidDataException>(() => reader.Read()); reader.Close(); }
public void GeoJsonWriterWrittenContentTest() { 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 + ".geojson"; GeoJsonWriter writer = new GeoJsonWriter(outFileName); writer.Write(mp as IGeometry); writer.Write(geo); writer.Close(); GeoJsonReader reader = new GeoJsonReader(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 GeoJsonReaderOpenCloseTest() { foreach (string path in _inputFilePaths) { GeoJsonReader reader = new GeoJsonReader(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 GeoJsonReaderReadToEndTest() { foreach (string path in _inputFilePaths) { GeoJsonReader reader = new GeoJsonReader(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 GeoJsonWriterWriteTest() { IList<IGeometry> geometries = null; byte i = 1; foreach (string path in _inputFilePaths) { GeoJsonReader reader = new GeoJsonReader(path); geometries = reader.ReadToEnd(); reader.Close(); string outFileName = _outputPath + i + ".geojson"; GeoJsonWriter writer = new GeoJsonWriter(outFileName); writer.Write(geometries); writer.Close(); i++; } }