private void TestParseMultiLineString(byte[] wkb, string expectedAsWkt) { MultiLineString expected = (MultiLineString)this.ParseWKT(expectedAsWkt); MultiLineString parsed = WkbReader.Parse <MultiLineString>(wkb); this.CompareMultiLineStrings(parsed, expected); }
public void MultiLsToByteArray() { var rnd = new Random(); var ls = new LineString[40]; for (var ii = 0; ii < 40; ii++) { var coord = new Coordinate[36]; for (var i = 0; i < 36; i++) { coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); } ls[ii] = new LineString(coord); } var mls = new MultiLineString(ls); var vals = mls.ToBinary(); var wkr = new WkbReader(); var g = wkr.Read(vals); var mlscheck = g as MultiLineString; if (mlscheck != null) { for (var ii = 0; ii < mls.Coordinates.Count; ii++) { Assert.AreEqual(mls.Coordinates[ii].X, mlscheck.Coordinates[ii].X); Assert.AreEqual(mls.Coordinates[ii].Y, mlscheck.Coordinates[ii].Y); } } else { Assert.Fail("The test failed bc the check multilinestring was null."); } }
private void TestParseMultiPoint(byte[] wkb, string expectedAsWkt) { MultiPoint expected = (MultiPoint)this.ParseWKT(expectedAsWkt); MultiPoint parsed = WkbReader.Parse <MultiPoint>(wkb); this.CompareMultiPoints(parsed, expected); }
public void If_input_valid_multipolygon_with_lower_endian_then_should_return_correct_multipolygon() { const string hex = "010600000002000000010300000001000000040000000000000000003e40000000000000344000000000008046400000000000004440000000000000244000000000000044400000000000003e400000000000003440010300000001000000050000000000000000002e4000000000000014400000000000004440000000000000244000000000000024400000000000003440000000000000144000000000000024400000000000002e400000000000001440"; var expectGeo = new MultiPolygon(new List <Polygon> { new Polygon(new List <Point> { new Point(30, 20), new Point(45, 40), new Point(10, 40), new Point(30, 20) }), new Polygon(new List <Point> { new Point(15, 5), new Point(40, 10), new Point(10, 20), new Point(5, 10), new Point(15, 5) }) }); var geoResult = WkbReader.Read(hex); geoResult.Equals(expectGeo).ShouldBeTrue(); }
public void MultiPointToByteArray() { var c = new Coordinate[36]; var rnd = new Random(); for (var i = 0; i < 36; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); } var mps = new MultiPoint(c); var vals = mps.ToBinary(); var wkb = new WkbReader(); var g = wkb.Read(vals); var mpsCheck = g as MultiPoint; if (mpsCheck != null) { for (var ii = 0; ii < mps.Coordinates.Count; ii++) { Assert.AreEqual(mps.Coordinates[ii].X, mpsCheck.Coordinates[ii].X); Assert.AreEqual(mps.Coordinates[ii].Y, mpsCheck.Coordinates[ii].Y); } } else { Assert.Fail("The test failed because the MpsCheck was null."); } }
public void If_input_a_null_string_then_should_throw_exception() { string wkbHex = null; Should.Throw <ArgumentException>(() => WkbReader.Read(wkbHex)) .Message.ShouldBe("Invalid hex wkb string"); }
private void TestParseMultiPolygon(byte[] wkb, string expectedAsWkt) { MultiPolygon expected = (MultiPolygon)this.ParseWKT(expectedAsWkt); MultiPolygon parsed = WkbReader.Parse <MultiPolygon>(wkb); this.CompareMultiPolygons(parsed, expected); }
public void LsToByteArray() { var coords = new Coordinate[36]; var rnd = new Random(); for (var i = 0; i < 36; i++) { coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); } var ls = new LineString(coords); var vals = ls.ToBinary(); var wkr = new WkbReader(); var g = wkr.Read(vals); var lscheck = g as LineString; if (lscheck != null) { for (var i = 0; i < ls.Count; i++) { Assert.AreEqual(ls.Coordinates[i].X, lscheck.Coordinates[i].X); Assert.AreEqual(ls.Coordinates[i].Y, lscheck.Coordinates[i].Y); } Assert.AreEqual(ls.Length, lscheck.Length); Assert.AreEqual(ls.Envelope.Height, lscheck.Envelope.Height); Assert.AreEqual(ls.Envelope.Width, lscheck.Envelope.Width); } else { Assert.Fail("The test failed bc the check lscheck was null."); } }
public void MultipolygonToByteArray() { var rnd = new Random(); var pg = new Polygon[50]; for (var i = 0; i < 50; i++) { var center = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var coord = new Coordinate[36]; for (var ii = 0; ii < 36; ii++) { coord[ii] = new Coordinate(center.X + Math.Cos((ii * 10) * Math.PI / 10), center.Y + (ii * 10) * Math.PI / 10); } coord[35] = new Coordinate(coord[0].X, coord[0].Y); pg[i] = new Polygon(coord); } var mpg = new MultiPolygon(pg); var vals = mpg.ToBinary(); var wkr = new WkbReader(); var g = wkr.Read(vals); var mpgcheck = g as MultiPolygon; if (mpgcheck != null) { for (var ii = 0; ii < mpg.Coordinates.Count; ii++) { Assert.AreEqual(mpg.Coordinates[ii].X, mpgcheck.Coordinates[ii].X); Assert.AreEqual(mpg.Coordinates[ii].Y, mpgcheck.Coordinates[ii].Y); } } else { Assert.Fail("The test failed bc the check mpgcheck was null."); } }
public void Buffer() { Coordinate[] c = new Coordinate[36]; Random rnd = new Random(); for (int i = 0; i < 36; i++) { c[i] = new Coordinate((rnd.NextDouble() + 360) - 180, (rnd.NextDouble() * 180) - 90); } MultiPoint mps = new MultiPoint(c); byte[] vals = mps.ToBinary(); WkbReader wkb = new WkbReader(); IGeometry g = wkb.Read(vals); MultiPoint mpsCheck = g as MultiPoint; if (mpsCheck != null) { Assert.AreEqual(mps.Buffer(200).Area, mpsCheck.Buffer(200).Area); } else { Assert.Fail("The test failed because the MpsCheck was null."); } }
public static void PopulateFeatureSet(IEnumerable <JoobGeometry> geometries, IFeatureSet featureSet) { if (geometries != null && geometries.Count() > 0) { var reader = new WkbReader(); var minX = double.PositiveInfinity; var minY = double.PositiveInfinity; var maxX = double.NegativeInfinity; var maxY = double.NegativeInfinity; foreach (var geom in geometries.Where(g => g != null)) { var feature = reader.Read(geom.GeoData); var envelope = feature.Envelope; if (envelope != null) { if (envelope.Minimum.X < minX) { minX = envelope.Minimum.X; } if (envelope.Minimum.Y < minY) { minY = envelope.Minimum.Y; } if (envelope.Maximum.X > maxX) { maxX = envelope.Maximum.X; } if (envelope.Maximum.Y > maxY) { maxY = envelope.Maximum.Y; } } featureSet.AddFeature(feature); } if (!double.IsInfinity(minX)) { featureSet.Extent.MinX = minX; } if (!double.IsInfinity(minY)) { featureSet.Extent.MinY = minY; } if (!double.IsInfinity(maxX)) { featureSet.Extent.MaxX = maxX; } if (!double.IsInfinity(maxY)) { featureSet.Extent.MaxY = maxY; } } }
public void ParseGeometryCollection_ParsesEmptyGeometryCollection() { string wkt = "geometrycollection empty"; GeometryCollection <Geometry> expected = (GeometryCollection <Geometry>) this.ParseWKT(wkt); GeometryCollection <Geometry> parsed = WkbReader.Parse <GeometryCollection <Geometry> >(Data.IOTestData.collection_empty); Assert.Equal(0, parsed.Geometries.Count); }
public void Parse_ReturnsParsedGeometry() { string wkt = "point m (-10.1 15.5 1000.5)"; Point expected = (Point)this.ParseWKT(wkt); Point parsed = (Point)WkbReader.Parse(TestDataReader.Read("point-2DM.wkb")); this.ComparePoints(parsed, expected); }
public void ParseGeometryCollection_ParsesEmptyGeometryCollection() { string wkt = "geometrycollection empty"; GeometryCollection <Geometry> expected = (GeometryCollection <Geometry>) this.ParseWKT(wkt); GeometryCollection <Geometry> parsed = WkbReader.Parse <GeometryCollection <Geometry> >(TestDataReader.Read("collection-empty.wkb")); Assert.Empty(parsed.Geometries); }
public void If_input_valid_point_with_lower_endian_then_should_return_correct_point() { const string hex = "0101000020E61000005DA450163E1A5D40C44FD2B2A4F64340"; var expectGeo = new Point(116.4100395, 39.9269012); var geoResult = WkbReader.Read(hex); geoResult.Equals(expectGeo).ShouldBeTrue(); }
public void If_input_valid_point_with_big_endian_then_should_return_correct_point() { const string hex = "000000000140000000000000004010000000000000"; var expectGeo = new Point(2, 4); var geoResult = WkbReader.Read(hex); geoResult.Equals(expectGeo).ShouldBeTrue(); }
public void ParseGeometryCollection_Parses3DGeometryCollection() { string wkt = "geometrycollection z (point z (-10.1 15.5 100.5))"; GeometryCollection <Geometry> expected = (GeometryCollection <Geometry>) this.ParseWKT(wkt); GeometryCollection <Geometry> parsed = WkbReader.Parse <GeometryCollection <Geometry> >(Data.IOTestData.collection_3D); Assert.Equal(expected.Geometries.Count, parsed.Geometries.Count); this.ComparePoints((Point)parsed.Geometries[0], (Point)expected.Geometries[0]); }
public void Dispose_ClosesOutputStreamIfWritingToStream() { MemoryStream stream = new MemoryStream(Data.IOTestData.point_3DM); WkbReader target = new WkbReader(stream); target.Dispose(); Assert.False(stream.CanRead); }
/// <summary> /// Opens the specified file /// </summary> /// <param name="fileName"></param> /// <returns></returns> public IFeatureSet Open(string fileName) { IFeatureSet fs = new FeatureSet(); fs.Name = Path.GetFileNameWithoutExtension(fileName); fs.Filename = fileName; using (var reader = new OgrDataReader(fileName)) { // skip the geometry column which is always column 0 for (int i = 1; i < reader.FieldCount; i++) { string sFieldName = reader.GetName(i); Type type = reader.GetFieldType(i); int uniqueNumber = 1; string uniqueName = sFieldName; while (fs.DataTable.Columns.Contains(uniqueName)) { uniqueName = sFieldName + uniqueNumber; uniqueNumber++; } fs.DataTable.Columns.Add(new DataColumn(uniqueName, type)); } var wkbReader = new WkbReader(); while (reader.Read()) { var wkbGeometry = (byte[])reader["Geometry"]; var geometry = wkbReader.Read(wkbGeometry); IFeature feature = new Feature(geometry); feature.DataRow = fs.DataTable.NewRow(); for (int i = 1; i < reader.FieldCount; i++) { object value = reader[i]; if (value == null) { value = DBNull.Value; } feature.DataRow[i - 1] = value; } fs.Features.Add(feature); } try { fs.Projection = reader.GetProj4ProjectionInfo(); } catch (Exception ex) { Trace.WriteLine(ex); } } return(fs); }
public void Read_ReadsGeometry() { Point expected = (Point)this.ParseWKT("point zm (-10.1 15.5 100.5 1000.5)"); WkbReader target = new WkbReader(new MemoryStream(Data.IOTestData.point_3DM)); Point parsed = (Point)target.Read(); this.ComparePoints(parsed, expected); }
public void Read_ReturnsNullIfNoMoreGeometriesAreAvailable() { WkbReader target = new WkbReader(TestDataReader.Open("point-3DM.wkb")); target.Read(); Geometry parsed = target.Read(); Assert.Null(parsed); }
public void Read_ReturnsNullIfStreamIsEmpty() { MemoryStream stream = new MemoryStream(); WkbReader target = new WkbReader(stream); Geometry read = target.Read(); Assert.Null(read); }
public void ReadT_ReturnsNullIfNoMoreGeometriesAreAvailable() { WkbReader target = new WkbReader(new MemoryStream(Data.IOTestData.point_3DM)); target.Read <Point>(); Geometry parsed = target.Read <Point>(); Assert.Null(parsed); }
public void Read_ReadsGeometry() { Point expected = (Point)this.ParseWKT("point zm (-10.1 15.5 100.5 1000.5)"); WkbReader target = new WkbReader(TestDataReader.Open("point-3DM.wkb")); Point parsed = (Point)target.Read(); this.ComparePoints(parsed, expected); }
public void ParseGeometryCollection_Parses3DMeasuredGeometryCollection() { string wkt = "geometrycollection zm (point zm (-10.1 15.5 100.5 1000.5))"; GeometryCollection <Geometry> expected = (GeometryCollection <Geometry>) this.ParseWKT(wkt); GeometryCollection <Geometry> parsed = WkbReader.Parse <GeometryCollection <Geometry> >(TestDataReader.Read("collection-3DM.wkb")); Assert.Equal(expected.Geometries.Count, parsed.Geometries.Count); this.ComparePoints((Point)parsed.Geometries[0], (Point)expected.Geometries[0]); }
public void ReadT_ThrowsExceptionIfWKBDoesNotRepresentGeometry() { byte[] wkb = new byte[] { 12, 0, 0, 45, 78, 124, 36, 0 }; using (MemoryStream ms = new MemoryStream(wkb)) { WkbReader target = new WkbReader(ms); Assert.Throws <WkbFormatException>(() => target.Read <Point>()); } }
public void Dispose_ClosesOutputStreamIfWritingToStream() { MemoryStream stream = new MemoryStream(Data.IOTestData.point_3DM); WkbReader target = new WkbReader(stream); target.Dispose(); Assert.False(stream.CanRead); }
public void ParseGeometryCollection_ParsesNestedCollection() { string wkt = "geometrycollection (geometrycollection (point (-10.1 15.5)))"; GeometryCollection <Geometry> expected = (GeometryCollection <Geometry>) this.ParseWKT(wkt); GeometryCollection <Geometry> parsed = WkbReader.Parse <GeometryCollection <Geometry> >(TestDataReader.Read("collection-nested.wkb")); Assert.Equal(expected.Geometries.Count, parsed.Geometries.Count); Assert.Equal(((GeometryCollection <Geometry>)expected.Geometries[0]).Geometries.Count, ((GeometryCollection <Geometry>)parsed.Geometries[0]).Geometries.Count); this.ComparePoints((Point)((GeometryCollection <Geometry>)parsed.Geometries[0]).Geometries[0], (Point)((GeometryCollection <Geometry>)expected.Geometries[0]).Geometries[0]); }
public void Dispose_ClosesOutputStreamIfWritingToStream() { var stream = TestDataReader.Open("point-3DM.wkb"); WkbReader target = new WkbReader(stream); target.Dispose(); Assert.False(stream.CanRead); }
public void Dispose_ClosesOutputStreamIfWritingToFiles() { string filename = "../../src/Tests.SpatialLite.Core/Data/IO/point-3DM.wkb"; WkbReader target = new WkbReader(filename); target.Dispose(); FileStream testStream = null; Assert.DoesNotThrow(() => testStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite)); testStream.Dispose(); }
public void ParseGeometryCollection_ParsesCollectionWithMultiGeometries() { string wkt = "geometrycollection (multipoint empty,multilinestring empty,multipolygon empty)"; GeometryCollection <Geometry> expected = (GeometryCollection <Geometry>) this.ParseWKT(wkt); GeometryCollection <Geometry> parsed = WkbReader.Parse <GeometryCollection <Geometry> >(TestDataReader.Read("collection-multi.wkb")); Assert.Equal(expected.Geometries.Count, parsed.Geometries.Count); this.CompareMultiPoints((MultiPoint)parsed.Geometries[0], (MultiPoint)expected.Geometries[0]); this.CompareMultiLineStrings((MultiLineString)parsed.Geometries[1], (MultiLineString)expected.Geometries[1]); this.CompareMultiPolygons((MultiPolygon)parsed.Geometries[2], (MultiPolygon)expected.Geometries[2]); }
public void ParseGeometryCollection_ParsesCollectionWithPointLineStringAndPolygon() { string wkt = "geometrycollection (point (-10.1 15.5),linestring (-10.1 15.5, 20.2 -25.5, 30.3 35.5),polygon ((-10.1 15.5, 20.2 -25.5, 30.3 35.5)))"; GeometryCollection <Geometry> expected = (GeometryCollection <Geometry>) this.ParseWKT(wkt); GeometryCollection <Geometry> parsed = WkbReader.Parse <GeometryCollection <Geometry> >(TestDataReader.Read("collection-pt-ls-poly.wkb")); Assert.Equal(expected.Geometries.Count, parsed.Geometries.Count); this.ComparePoints((Point)parsed.Geometries[0], (Point)expected.Geometries[0]); this.CompareLineStrings((LineString)parsed.Geometries[1], (LineString)expected.Geometries[1]); this.ComparePolygons((Polygon)parsed.Geometries[2], (Polygon)expected.Geometries[2]); }
public void ReadT_ThrowsExceptionIfWKBDoesNotRepresentSpecifiecGeometryType() { WkbReader target = new WkbReader(new MemoryStream(Data.IOTestData.point_3DM)); Assert.Throws<WkbFormatException>(() => target.Read<LineString>()); }
public void Read_ReadsGeometry() { Point expected = (Point)this.ParseWKT("point zm (-10.1 15.5 100.5 1000.5)"); WkbReader target = new WkbReader(new MemoryStream(Data.IOTestData.point_3DM)); Point parsed = (Point)target.Read(); this.ComparePoints(parsed, expected); }
public void Read_ThrowsExceptionIfWKBDoesNotRepresentGeometry() { byte[] wkb = new byte[] { 12, 0, 0, 45, 78, 124, 36, 0 }; using (MemoryStream ms = new MemoryStream(wkb)) { WkbReader target = new WkbReader(ms); Assert.Throws<WkbFormatException>(() => target.Read()); } }
public void Read_ReadsMultipleGeometries() { Point expected1 = (Point)this.ParseWKT("point zm (-10.1 15.5 100.5 1000.5)"); Point expected2 = (Point)this.ParseWKT("point zm (-10.2 15.6 100.6 1000.6)"); WkbReader target = new WkbReader(new MemoryStream(Data.IOTestData.two_points_3DM)); Point parsed1 = (Point)target.Read(); this.ComparePoints(parsed1, expected1); Point parsed2 = (Point)target.Read(); this.ComparePoints(parsed2, expected2); }
public void Read_ReturnsNullIfNoMoreGeometriesAreAvailable() { WkbReader target = new WkbReader(new MemoryStream(Data.IOTestData.point_3DM)); target.Read(); Geometry parsed = target.Read(); Assert.Null(parsed); }
public void Read_ReturnsNullIfStreamIsEmpty() { MemoryStream stream = new MemoryStream(); WkbReader target = new WkbReader(stream); Geometry read = target.Read(); Assert.Null(read); }