Ejemplo n.º 1
0
        public void WriteToArray_WritesAllGeometryTypes(string wkt, byte[] expectedWkb)
        {
            IGeometry geometry = this.ParseWKT(wkt);

            byte[] wkb = WkbWriter.WriteToArray(geometry);
            this.CompareBytes(wkb, expectedWkb);
        }
Ejemplo n.º 2
0
        public void If_input_an_invalid_geometry_then_should_throw_exception()
        {
            var point = new Point();

            Should.Throw <ArgumentException>(() => WkbWriter.Write(point))
            .Message.ShouldBe("Invalid geometry");
        }
Ejemplo n.º 3
0
        public void Construcotor_PathSettings_SetsSettingsAndMakeThemReadOnly()
        {
            WkbWriterSettings settings = new WkbWriterSettings();

            using (WkbWriter target = new WkbWriter(new MemoryStream(), settings)) {
                Assert.Same(settings, target.Settings);
                Assert.True(settings.IsReadOnly);
            }
        }
Ejemplo n.º 4
0
        public void Dispose_ClosesOutputStreamIfWritingToStream()
        {
            MemoryStream stream = new MemoryStream();

            WkbWriter target = new WkbWriter(stream, new WkbWriterSettings());

            target.Dispose();

            Assert.False(stream.CanRead);
        }
Ejemplo n.º 5
0
        public void Write_Writes3DMeasuredLineString()
        {
            string     wkt        = "linestring zm (-10.1 15.5 100.5 1000.5, 20.2 -25.5 200.5 2000.5, 30.3 35.5 -300.5 -3000.5)";
            LineString linestring = (LineString)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream(); using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(linestring);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("linestring-3DM.wkb"));
            }
        }
Ejemplo n.º 6
0
        public void Constructor_PathSettings_CreatesOutputFile()
        {
            string filename = PathHelper.GetTempFilePath("wkbwriter-constructor-creates-output-test.bin");

            WkbWriterSettings settings = new WkbWriterSettings();

            using (WkbWriter target = new WkbWriter(filename, settings)) {
                ;
            }

            Assert.True(File.Exists(filename));
        }
Ejemplo n.º 7
0
        public void Write_Writes3DMultiPoint()
        {
            string     wkt        = "multipoint z ((-10.1 15.5 100.5),(20.2 -25.5 200.5))";
            MultiPoint multipoint = (MultiPoint)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(multipoint);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("multipoint-3D.wkb"));
            }
        }
Ejemplo n.º 8
0
        public void Write_Writes3DMeasuredPolygonOnlyExteriorRing()
        {
            string  wkt     = "polygon zm ((-10.1 15.5 100.5 1000.5, 20.2 -25.5 200.5 2000.5, 30.3 35.5 -300.5 -3000.5))";
            Polygon polygon = (Polygon)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(polygon);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("polygon-ext-3DM.wkb"));
            }
        }
Ejemplo n.º 9
0
        public void Write_Writes3DLineString()
        {
            string     wkt        = "linestring z (-10.1 15.5 100.5, 20.2 -25.5 200.5, 30.3 35.5 -300.5)";
            LineString linestring = (LineString)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(linestring);

                this.CompareBytes(stream.ToArray(), IOTestData.linestring_3D);
            }
        }
Ejemplo n.º 10
0
        public void Write_Writes3DMeasuredPoint()
        {
            string wkt   = "point zm (-10.1 15.5 100.5 1000.5)";
            Point  point = (Point)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(point);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("point-3DM.wkb"));
            }
        }
Ejemplo n.º 11
0
        public void Write_Writes3DMeasuredMultiPoint()
        {
            string     wkt        = "multipoint zm ((-10.1 15.5 100.5 1000.5),(20.2 -25.5 200.5 2000.5))";
            MultiPoint multipoint = (MultiPoint)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(multipoint);

                this.CompareBytes(stream.ToArray(), IOTestData.multipoint_3DM);
            }
        }
Ejemplo n.º 12
0
        public void Write_WritesEmptyMultiPolygon()
        {
            string       wkt          = "multipolygon empty";
            MultiPolygon multipolygon = (MultiPolygon)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(multipolygon);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("multipolygon-empty.wkb"));
            }
        }
Ejemplo n.º 13
0
        public void Write_Writes3DMeasuredMultiPolygon()
        {
            string       wkt          = "multipolygon zm (((-10.1 15.5 100.5 1000.5, 20.2 -25.5 200.5 2000.5, 30.3 35.5 -300.5 -3000.5)),((-10.1 15.5 100.5 1000.5, 20.2 -25.5 200.5 2000.5, 30.3 35.5 -300.5 -3000.5)))";
            MultiPolygon multipolygon = (MultiPolygon)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(multipolygon);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("multipolygon-3DM.wkb"));
            }
        }
Ejemplo n.º 14
0
        public void Write_Writes3DMeasuredGeometryCollection()
        {
            string wkt = "geometrycollection zm (point zm (-10.1 15.5 100.5 1000.5))";
            GeometryCollection <Geometry> collection = (GeometryCollection <Geometry>) this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(collection);

                this.CompareBytes(stream.ToArray(), IOTestData.collection_3DM);
            }
        }
Ejemplo n.º 15
0
        public void Write_WritesEmptyGeometryCollection()
        {
            string wkt = "geometrycollection empty";
            GeometryCollection <Geometry> collection = (GeometryCollection <Geometry>) this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(collection);

                this.CompareBytes(stream.ToArray(), IOTestData.collection_empty);
            }
        }
Ejemplo n.º 16
0
        public void Write_Writes2DMultiPolygon()
        {
            string       wkt          = "multipolygon (((-10.1 15.5, 20.2 -25.5, 30.3 35.5)),((-10.1 15.5, 20.2 -25.5, 30.3 35.5)))";
            MultiPolygon multipolygon = (MultiPolygon)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(multipolygon);

                this.CompareBytes(stream.ToArray(), IOTestData.multipolygon_2D);
            }
        }
Ejemplo n.º 17
0
        public void Write_Writes2DMeasuredMultiLineString()
        {
            string          wkt             = "multilinestring m ((-10.1 15.5 1000.5, 20.2 -25.5 2000.5, 30.3 35.5 -3000.5),(-10.1 15.5 1000.5, 20.2 -25.5 2000.5, 30.3 35.5 -3000.5))";
            MultiLineString multilinestring = (MultiLineString)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(multilinestring);

                this.CompareBytes(stream.ToArray(), IOTestData.multilinestring_2DM);
            }
        }
Ejemplo n.º 18
0
        public void Write_WritesEmptyMultiLineString()
        {
            string          wkt             = "multilinestring empty";
            MultiLineString multilinestring = (MultiLineString)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(multilinestring);

                this.CompareBytes(stream.ToArray(), IOTestData.multilinestring_empty);
            }
        }
Ejemplo n.º 19
0
        public void Write_WritesEmptyPolygon()
        {
            string  wkt     = "polygon empty";
            Polygon polygon = (Polygon)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(polygon);

                this.CompareBytes(stream.ToArray(), IOTestData.polygon_empty);
            }
        }
Ejemplo n.º 20
0
        public void Write_Writes3DMultiLineString()
        {
            string          wkt             = "multilinestring z ((-10.1 15.5 100.5, 20.2 -25.5 200.5, 30.3 35.5 -300.5),(-10.1 15.5 100.5, 20.2 -25.5 200.5, 30.3 35.5 -300.5))";
            MultiLineString multilinestring = (MultiLineString)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(multilinestring);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("multilinestring-3D.wkb"));
            }
        }
Ejemplo n.º 21
0
        public void Write_WritesCollectionWithMultiGeometries()
        {
            string wkt = "geometrycollection (multipoint empty,multilinestring empty,multipolygon empty)";
            GeometryCollection <Geometry> collection = (GeometryCollection <Geometry>) this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(collection);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("collection-multi.wkb"));
            }
        }
Ejemplo n.º 22
0
        public void Write_Writes3DPolygonOnlyExteriorRing()
        {
            string  wkt     = "polygon z ((-10.1 15.5 100.5, 20.2 -25.5 200.5, 30.3 35.5 -300.5))";
            Polygon polygon = (Polygon)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(polygon);

                this.CompareBytes(stream.ToArray(), IOTestData.polygon_ext_3D);
            }
        }
Ejemplo n.º 23
0
        public void Write_Writes3DMeasuredPolygon()
        {
            string  wkt     = "polygon zm ((-10.1 15.5 100.5 1000.5, 20.2 -25.5 200.5 2000.5, 30.3 35.5 -300.5 -3000.5),(-1.1 1.5 10.5 100.5, 2.2 -2.5 20.5 200.5, 3.3 3.5 -30.5 -300.5),(-1.1 1.5 10.5 100.5, 2.2 -2.5 20.5 200.5, 3.3 3.5 -30.5 -300.5))";
            Polygon polygon = (Polygon)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(polygon);

                this.CompareBytes(stream.ToArray(), IOTestData.polygon_3DM);
            }
        }
Ejemplo n.º 24
0
        public void Write_WritesCollectionWithPointLineStringAndPolygon()
        {
            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> collection = (GeometryCollection <Geometry>) this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(collection);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("collection-pt-ls-poly.wkb"));
            }
        }
Ejemplo n.º 25
0
        public void WkbWriter_Write_WritesLittleEndianEncodingByte()
        {
            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings()
            {
                Encoding = BinaryEncoding.LittleEndian
            })) {
                target.Write(new Point());

                CompareBytes(stream.ToArray(), 0, new byte[] { (byte)BinaryEncoding.LittleEndian });
            }
        }
Ejemplo n.º 26
0
        public void Write_WritesNestedCollection()
        {
            string wkt = "geometrycollection (geometrycollection (point (-10.1 15.5)))";
            GeometryCollection <Geometry> collection = (GeometryCollection <Geometry>) this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(collection);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("collection-nested.wkb"));
            }
        }
Ejemplo n.º 27
0
        public void Write_WritesEmptyPointAsEmptyGeoemtryCollection()
        {
            string wkt   = "point empty";
            Point  point = (Point)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(point);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("collection-empty.wkb"));
            }
        }
Ejemplo n.º 28
0
        public void Write_WritesEmptyLineString()
        {
            string     wkt        = "linestring empty";
            LineString linestring = (LineString)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(linestring);

                this.CompareBytes(stream.ToArray(), TestDataReader.Read("linestring-empty.wkb"));
            }
        }
Ejemplo n.º 29
0
        public void Write_Writes3DPoint()
        {
            string wkt   = "point z (-10.1 15.5 100.5)";
            Point  point = (Point)this.ParseWKT(wkt);

            MemoryStream stream = new MemoryStream();

            using (WkbWriter target = new WkbWriter(stream, new WkbWriterSettings())) {
                target.Write(point);

                this.CompareBytes(stream.ToArray(), IOTestData.point_3D);
            }
        }
Ejemplo n.º 30
0
        public void Dispose_ClosesOutputStreamIfWritingToFiles()
        {
            string filename = PathHelper.GetTempFilePath("wkbwriter-closes-output-filestream-test.bin");

            WkbWriterSettings settings = new WkbWriterSettings();
            WkbWriter         target   = new WkbWriter(filename, settings);

            target.Dispose();

            FileStream testStream = null;

            testStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite);
            testStream.Dispose();
        }