Exemplo n.º 1
0
        public void Read_ReturnsNullIfNoMoreGeometriesAreAvailableInInputStream()
        {
            using (WktReader target = new WktReader(TestDataReader.Open("wkt-point-3DM.wkt"))) {
                target.Read();
                IGeometry readGeometry = target.Read();

                Assert.Null(readGeometry);
            }
        }
Exemplo n.º 2
0
        public void Read_ReturnsNullIfNoMoreGeometriesAreAvailableInInputStream()
        {
            using (WktReader target = new WktReader(new MemoryStream(Data.IOTestData.wkt_point_3DM))) {
                target.Read();
                IGeometry readGeometry = target.Read();

                Assert.Null(readGeometry);
            }
        }
Exemplo n.º 3
0
        public void Read_ReadsMultipleGeometries()
        {
            using (WktReader target = new WktReader(new MemoryStream(Data.IOTestData.wkt_point_and_linestring_3DM))) {
                IGeometry readGeometry = target.Read();
                Assert.True(readGeometry is Point);

                readGeometry = target.Read();
                Assert.True(readGeometry is LineString);
            }
        }
Exemplo n.º 4
0
        public void Read_ReadsMultipleGeometries()
        {
            using (WktReader target = new WktReader(TestDataReader.Open("wkt-point-and-linestring-3DM.wkt"))) {
                IGeometry readGeometry = target.Read();
                Assert.True(readGeometry is Point);

                readGeometry = target.Read();
                Assert.True(readGeometry is LineString);
            }
        }
Exemplo n.º 5
0
        public void Polygon()
        {
            var reader = new WktReader();

            var xy = reader.Read("POLYGON ((0.0 65.9, -34.5 9, -20 40, 0 65.9))");

            Assert.AreEqual(new Polygon(new LinearRing(new Coordinate(65.9, 0), new Coordinate(9, -34.5), new Coordinate(40, -20), new Coordinate(65.9, 0))), xy);

            var empty = reader.Read("POLYGON ZM EMPTY");

            Assert.AreEqual(global::Geo.Geometries.Polygon.Empty, empty);
        }
Exemplo n.º 6
0
        public void Triangle()
        {
            var reader = new WktReader();

            var xy = reader.Read("TRIANGLE ((0.0 65.9, -34.5 9, -20 40, 0 65.9))");

            Assert.AreEqual(new Triangle(new LinearRing(new Coordinate(65.9, 0), new Coordinate(9, -34.5), new Coordinate(40, -20), new Coordinate(65.9, 0))), xy);

            var empty = reader.Read("Triangle ZM EMPTY");

            Assert.AreEqual(global::Geo.Geometries.Triangle.Empty, empty);
        }
Exemplo n.º 7
0
        public void GeometryCollection()
        {
            var reader = new WktReader();

            var points = reader.Read("GEOMETRYCOLLECTION (POINT (0.0 65.9), POINT (-34.5 9), POINT  (-20 40), POINT (0 65.9))");

            Assert.AreEqual(new GeometryCollection(new Point(65.9, 0), new Point(9, -34.5), new Point(40, -20), new Point(65.9, 0)), points);

            var empty = reader.Read("GEOMETRYCOLLECTION ZM EMPTY");

            Assert.AreEqual(new GeometryCollection(), empty);
        }
Exemplo n.º 8
0
        public void LinearRing()
        {
            var reader = new WktReader();

            var xy = reader.Read("LINEARRING (0.0 65.9, -34.5 9, 5.0 65.9, 0.0 65.9)");

            Assert.AreEqual(new LinearRing(new Coordinate(65.9, 0), new Coordinate(9, -34.5), new Coordinate(65.9, 5), new Coordinate(65.9, 0)), xy);

            var empty = reader.Read("LINEARRING ZM EMPTY");

            Assert.AreEqual(new LinearRing(), empty);
        }
Exemplo n.º 9
0
 public void ReadT_ReadsGeometry()
 {
     using (WktReader target = new WktReader(TestDataReader.Open("wkt-point-3DM.wkt"))) {
         Point read = target.Read <Point>();
         Assert.NotNull(read);
     }
 }
Exemplo n.º 10
0
        public static void LoadRestaurants(string csvFile, BulkInsertOperation bulkInsert)
        {
            var wktReader = new WktReader();

            using (var reader = new StreamReader(csvFile))
                using (var csv = new CsvReader(reader, new CsvConfiguration {
                    UseInvariantCulture = true
                }))
                {
                    var restaurantCsvRows = csv.GetRecords <RestaurantCsvRow>();
                    foreach (var row in restaurantCsvRows)
                    {
                        Polygon deliveryArea = null;

                        if (!string.IsNullOrEmpty(row.DeliveryArea))
                        {
                            deliveryArea = (Polygon)wktReader.Read(row.DeliveryArea);
                        }

                        var restaurant = new Restaurant
                        {
                            Name          = row.Name,
                            Street        = row.Street,
                            City          = row.City,
                            PostCode      = row.PostCode,
                            Phone         = row.Phone,
                            Location      = new Point(row.Latitude, row.Longitude),
                            DeliveryArea  = deliveryArea,
                            DriveThruArea = string.IsNullOrEmpty(row.DriveThruArea) ? null : row.DriveThruArea
                        };

                        bulkInsert.Store(restaurant);
                    }
                }
        }
Exemplo n.º 11
0
 public void Read_ReadsAllGeometryTypes(byte[] data)
 {
     using (WktReader target = new WktReader(new MemoryStream(data))) {
         IGeometry readGeometry = target.Read();
         Assert.NotNull(readGeometry);
     }
 }
Exemplo n.º 12
0
        public ISpatial4nShape Read(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            ISpatial4nShape result;

            if (TryReadCircle(value, out result))
            {
                return(result);
            }

            if (TryReadGeoPoint(value, out result))
            {
                return(result);
            }

            if (TryReadPoint(value, out result))
            {
                return(result);
            }

            if (TryReadEnvelope(value, out result))
            {
                return(result);
            }

            return(_wktReader.Read(value));
        }
Exemplo n.º 13
0
        public void MultiPoint()
        {
            var reader = new WktReader();

            var none = reader.Read("MULTIPOINT (0.0 65.9, -34.5 9, -20 40, 0 65.9)");

            Assert.AreEqual(new MultiPoint(new Point(65.9, 0), new Point(9, -34.5), new Point(40, -20), new Point(65.9, 0)), none);

            var brackets = reader.Read("MULTIPOINT (EMPTY, (0.0 65.9), (-34.5 9), (-20 40), (0 65.9))");

            Assert.AreEqual(new MultiPoint(new Point(), new Point(65.9, 0), new Point(9, -34.5), new Point(40, -20), new Point(65.9, 0)), brackets);

            var empty = reader.Read("MULTIPOINT ZM EMPTY");

            Assert.AreEqual(new MultiPoint(), empty);
        }
Exemplo n.º 14
0
 public void ReadT_ReadsGeometry()
 {
     using (WktReader target = new WktReader(new MemoryStream(Data.IOTestData.wkt_point_3DM))) {
         Point read = target.Read <Point>();
         Assert.NotNull(read);
     }
 }
Exemplo n.º 15
0
        public void ExponentialNumber()
        {
            var reader = new WktReader();

            var xyWithE = reader.Read("POINT (5.5980439826435563E-06 -71.4920233210601)");

            Assert.AreEqual(new Point(-71.4920233210601, 5.5980439826435563E-06), xyWithE);
        }
Exemplo n.º 16
0
        public void ReadT_ReturnsNullIfStreamIsEmpty()
        {
            using (WktReader target = new WktReader(new MemoryStream())) {
                IGeometry readGeometry = target.Read <Point>();

                Assert.Null(readGeometry);
            }
        }
Exemplo n.º 17
0
        public void MultiLineString()
        {
            var reader = new WktReader();

            var one = reader.Read("MULTILINESTRING ((0.0 65.9, -34.5 9, -20 40, 0 65.9))");

            Assert.AreEqual(new MultiLineString(new LineString(new Coordinate(65.9, 0), new Coordinate(9, -34.5), new Coordinate(40, -20), new Coordinate(65.9, 0))), one);


            var two = reader.Read("MULTILINESTRING ((0.0 65.9, -34.5 9, -20 40, 0 65.9), (0.0 65.9, -34.5 9, -20 40, 0 65.9))");

            Assert.AreEqual(new MultiLineString(new LineString(new Coordinate(65.9, 0), new Coordinate(9, -34.5), new Coordinate(40, -20), new Coordinate(65.9, 0)), new LineString(new Coordinate(65.9, 0), new Coordinate(9, -34.5), new Coordinate(40, -20), new Coordinate(65.9, 0))), two);

            var empty = reader.Read("MULTILINESTRING ZM EMPTY");

            Assert.AreEqual(new MultiLineString(), empty);
        }
Exemplo n.º 18
0
        public void If_wkt_is_valid_multipoint_then_should_return_correct_multipoint(string wkt)
        {
            var expectedMultiPoint = new MultiPoint(new[] { new Point(10, 40), new Point(40, 30), new Point(20, 20), new Point(30, 10) });

            var resultMultiPoint = WktReader.Read(wkt);

            resultMultiPoint.ShouldBe(expectedMultiPoint);
        }
Exemplo n.º 19
0
        public void MultiPolygon()
        {
            var reader = new WktReader();

            var one = reader.Read("MULTIPOLYGON (((0.0 65.9, -34.5 9, -20 40, 0 65.9)))");

            Assert.AreEqual(new MultiPolygon(new Polygon(new LinearRing(new Coordinate(65.9, 0), new Coordinate(9, -34.5), new Coordinate(40, -20), new Coordinate(65.9, 0)))), one);


            var two = reader.Read("MULTIPOLYGON (((0.0 65.9, -34.5 9, -20 40, 0 65.9)),((0.0 65.9, -34.5 9, -20 40, 0 65.9)))");

            Assert.AreEqual(new MultiPolygon(new Polygon(new LinearRing(new Coordinate(65.9, 0), new Coordinate(9, -34.5), new Coordinate(40, -20), new Coordinate(65.9, 0))), new Polygon(new LinearRing(new Coordinate(65.9, 0), new Coordinate(9, -34.5), new Coordinate(40, -20), new Coordinate(65.9, 0)))), two);

            var empty = reader.Read("MULTIPOLYGON ZM EMPTY");

            Assert.AreEqual(new MultiPolygon(), empty);
        }
Exemplo n.º 20
0
        public void Null()
        {
            var reader = new WktReader();

            var nothing = reader.Read("");

            Assert.AreEqual(null, nothing);
        }
Exemplo n.º 21
0
        public void Point()
        {
            var reader = new WktReader();

            var xy = reader.Read("POINT (0.0 65.9)");

            Assert.AreEqual(new Point(65.9, 0), xy);

            var xyz = reader.Read("POINT Z (0.0 65.9 5)");

            Assert.AreEqual(new Point(65.9, 0, 5), xyz);

            var xyz2 = reader.Read("POINT (0.0 65.9 5)");

            Assert.AreEqual(new Point(65.9, 0, 5), xyz2);

            var xym = reader.Read("POINT M (0.0 65.9 5)");

            Assert.AreEqual(new Point(new CoordinateM(65.9, 0, 5)), xym);

            var xyzm = reader.Read("POINT ZM (0.0 65.9 4 5)");

            Assert.AreEqual(new Point(65.9, 0, 4, 5), xyzm);

            var xyzm2 = reader.Read("POINT (0.0 65.9 4 5)");

            Assert.AreEqual(new Point(65.9, 0, 4, 5), xyzm2);

            var empty = reader.Read("POINT ZM EMPTY");

            Assert.AreEqual(global::Geo.Geometries.Point.Empty, empty);
        }
Exemplo n.º 22
0
        public void If_wkt_is_valid_point_then_should_return_correct_point()
        {
            const string wkt           = "POINT (10 20)";
            var          expectedPoint = new Point(10, 20);

            var resultPoint = WktReader.Read(wkt);

            resultPoint.ShouldBe(expectedPoint);
        }
Exemplo n.º 23
0
        public void If_wkt_is_valid_linestring_then_should_return_correct_linestring()
        {
            const string wkt = "LINESTRING (30 10, 10 30, 40 40)";
            var          expectedLineString = new LineString(new[] { new Point(30, 10), new Point(10, 30), new Point(40, 40) });

            var resultLineString = WktReader.Read(wkt);

            resultLineString.ShouldBe(expectedLineString);
        }
Exemplo n.º 24
0
        public void If_wkt_is_valid_polygon_then_should_return_correct_polygon()
        {
            const string wkt             = "POLYGON ((30 10, 40 40, 20 40, 5E-03 20, 30 10))";
            var          expectedPolygon = new Polygon(new[] { new Point(30, 10), new Point(40, 40), new Point(20, 40), new Point(0.005, 20), new Point(30, 10) });

            var resultPolygon = WktReader.Read(wkt);

            resultPolygon.ShouldBe(expectedPolygon);
        }
Exemplo n.º 25
0
        public void If_wkt_is_valid_polygon_with_hole_then_should_return_correct_polygon()
        {
            const string wkt             = "POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10), (20 30, 35 35, 30 20, 20 30))";
            var          expectedPolygon = new Polygon(new[] { new Point(30, 10), new Point(40, 40), new Point(20, 40), new Point(10, 20), new Point(30, 10) });

            expectedPolygon.LineStrings.Add(new LineString(new[] { new Point(20, 30), new Point(35, 35), new Point(30, 20), new Point(20, 30) }));

            var resultPolygon = WktReader.Read(wkt);

            resultPolygon.ShouldBe(expectedPolygon);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Reads a Well-Known-Text geometry.
        /// </summary>
        /// <example>
        /// Format: [geometry] [dimension] [empty?] ([geometric_information])
        /// </example>
        /// <remarks>
        /// Not implemented: [SRID];[WKT]
        /// </remarks>
        /// <param name="str"></param>
        public static Geometry Deserialize(string str)
        {
            Geometry value = null;

            using (WktReader reader = new WktReader(str))
            {
                value = reader.Read();
                //value = reader.ReadArgs();
            }

            return(value);
        }
Exemplo n.º 27
0
        public void If_wkt_is_valid_multipolygon_then_should_return_correct_polygon()
        {
            const string wkt             = "MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))";
            var          expectedPolygon = new MultiPolygon(new[]
            {
                new Polygon(new[] { new LineString(new[] { new Point(30, 20), new Point(45, 40), new Point(10, 40), new Point(30, 20) }) }),
                new Polygon(new[] { new LineString(new[] { new Point(15, 5), new Point(40, 10), new Point(10, 20), new Point(5, 10), new Point(15, 5) }) })
            });

            var resultMultiPolygon = WktReader.Read(wkt);

            resultMultiPolygon.ShouldBe(expectedPolygon);
        }
Exemplo n.º 28
0
        public void If_wkt_is_valid_multipolygon_with_hole_then_should_return_correct_polygon()
        {
            const string wkt             = "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))";
            var          expectedPolygon = new MultiPolygon(new[]
            {
                new Polygon(new[] { new LineString(new[] { new Point(40, 40), new Point(20, 45), new Point(45, 30), new Point(40, 40) }) }),
                new Polygon(new[]
                {
                    new LineString(new[] { new Point(20, 35), new Point(10, 30), new Point(10, 10), new Point(30, 5), new Point(45, 20), new Point(20, 35) }),
                    new LineString(new[] { new Point(30, 20), new Point(20, 15), new Point(20, 25), new Point(30, 20) })
                })
            });

            var resultMultiPolygon = WktReader.Read(wkt);

            resultMultiPolygon.ShouldBe(expectedPolygon);
        }
Exemplo n.º 29
0
 private void Test(string wkt)
 {
     var wktReader = new WktReader();
     var geometry  = wktReader.Read(wkt);
     {
         var wkbWriter = new WkbWriter(new WkbWriterSettings {
             Triangle = true
         });
         var wkb       = wkbWriter.Write(geometry);
         var wkbReader = new WkbReader();
         var geometry2 = wkbReader.Read(wkb);
         Assert.AreEqual(geometry, geometry2);
     }
     {
         var wkbWriter = new WkbWriter(new WkbWriterSettings {
             Encoding = WkbEncoding.BigEndian, Triangle = true
         });
         var wkb       = wkbWriter.Write(geometry);
         var wkbReader = new WkbReader();
         var geometry2 = wkbReader.Read(wkb);
         Assert.AreEqual(geometry, geometry2);
     }
 }
Exemplo n.º 30
0
        public void If_wkt_is_valid_point_then_should_return_correct_point_in_different_cultures()
        {
            var cultures        = new string[] { "en-US", "sv-SE" };
            var originalCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                foreach (var culture in cultures)
                {
                    Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);

                    const string wkt           = "POINT (10.1 20.2)";
                    var          expectedPoint = new Point(10.1, 20.2);

                    var resultPoint = WktReader.Read(wkt);

                    resultPoint.ShouldBe(expectedPoint);
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
Exemplo n.º 31
0
        public void Read_ReturnsNullIfStreamIsEmpty()
        {
            using (WktReader target = new WktReader(new MemoryStream())) {
                IGeometry readGeometry = target.Read();

                Assert.Null(readGeometry);
            }
        }
Exemplo n.º 32
0
        public void Read_ReturnsNullIfNoMoreGeometriesAreAvailableInInputStream()
        {
            using (WktReader target = new WktReader(new MemoryStream(Data.IOTestData.wkt_point_3DM))) {
                target.Read();
                IGeometry readGeometry = target.Read();

                Assert.Null(readGeometry);
            }
        }
Exemplo n.º 33
0
        public void Read_ReadsMultipleGeometries()
        {
            using (WktReader target = new WktReader(new MemoryStream(Data.IOTestData.wkt_point_and_linestring_3DM))) {
                IGeometry readGeometry = target.Read();
                Assert.True(readGeometry is Point);

                readGeometry = target.Read();
                Assert.True(readGeometry is LineString);
            }
        }
Exemplo n.º 34
0
 public void ReadT_ReadsGeometry()
 {
     using (WktReader target = new WktReader(new MemoryStream(Data.IOTestData.wkt_point_3DM))) {
         Point read = target.Read<Point>();
         Assert.NotNull(read);
     }
 }
Exemplo n.º 35
0
 public void Read_ReadsAllGeometryTypes(byte[] data)
 {
     using (WktReader target = new WktReader(new MemoryStream(data))) {
         IGeometry readGeometry = target.Read();
         Assert.NotNull(readGeometry);
     }
 }
Exemplo n.º 36
0
 public void ReadT_ThrowsExceptionIfWKTDoesNotRepresentGeometryOfSpecificType()
 {
     using (WktReader target = new WktReader(new MemoryStream(Data.IOTestData.wkt_point_3DM))) {
         Assert.Throws<WktParseException>(() => target.Read<LineString>());
     }
 }