예제 #1
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);
     }
 }
예제 #2
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);
                    }
                }
        }
예제 #3
0
        public void NoPrjFileThenSetCoordinateSystemGivesSpatialRefToGeometries()
        {
            //Layer name: BCROADSWithoutDbf
            //Geometry: Line String
            //Feature Count: 7291
            //Extent: (7332083.212797, 236823.718672) - (7538428.618000, 405610.346926)
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsWithOutDbfShapeFile,
                _geoFactory);

            shapeFile.Open();
            ICoordinateSystemFactory <BufferedCoordinate2D> coordSysFactory
                = _coordSysFactory;
            String wkt = File.ReadAllText(BcRoadsPrjFile);
            IProjectedCoordinateSystem cs = WktReader <BufferedCoordinate2D>
                                            .ToCoordinateSystemInfo(wkt, coordSysFactory) as IProjectedCoordinateSystem;

            shapeFile.SpatialReference = cs;
            Assert.IsNotNull(shapeFile.SpatialReference);

            IGeometry g = shapeFile.GetGeometryByOid(0);

            Assert.IsTrue(g.SpatialReference.EqualParams(createExpectedCoordinateSystem()));

            shapeFile.Close();
        }
예제 #4
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);
        }
예제 #5
0
 public void Read_ReadsAllGeometryTypes(byte[] data)
 {
     using (WktReader target = new WktReader(new MemoryStream(data))) {
         IGeometry readGeometry = target.Read();
         Assert.NotNull(readGeometry);
     }
 }
예제 #6
0
 public void ReadT_ReadsGeometry()
 {
     using (WktReader target = new WktReader(TestDataReader.Open("wkt-point-3DM.wkt"))) {
         Point read = target.Read <Point>();
         Assert.NotNull(read);
     }
 }
예제 #7
0
        public void Execute(IVectorImageProvider imageProvider)
        {
            WktLoaderDialog wktDlg = new WktLoaderDialog();

            if (wktDlg.ShowDialog() == DialogResult.OK)
            {
                string filename = wktDlg.WktFileName;
                if (File.Exists(filename))
                {
                    if (filename.ToLower().EndsWith("wkb"))
                    {
                        WkbReader wkb = new WkbReader(File.ReadAllText(filename));
                        wkb.LoadIntoImage(imageProvider.CurrImage, wktDlg.FlipYAxis);
                    }
                    else
                    {
                        WktReader.ReadFile(imageProvider.LayeredVectorImage, filename, wktDlg.ScaleDivider, wktDlg.FlipYAxis, wktDlg.IncermentalCoordinates);
                    }
                }

                if (wktDlg.WktFreeText.Length > 1)
                {
                    if (IsHexString(wktDlg.WktFreeText))
                    {
                        WkbReader wkb = new WkbReader(wktDlg.WktFreeText);
                        wkb.LoadIntoImage(imageProvider.CurrImage, wktDlg.FlipYAxis);
                    }
                    else
                    {
                        WktReader.ReadText(imageProvider.LayeredVectorImage, wktDlg.WktFreeText, wktDlg.ScaleDivider, wktDlg.FlipYAxis, wktDlg.IncermentalCoordinates);
                    }
                }
            }
            wktDlg.Dispose();
        }
예제 #8
0
        public void ReadT_ReturnsNullIfStreamIsEmpty()
        {
            using (WktReader target = new WktReader(new MemoryStream())) {
                IGeometry readGeometry = target.Read <Point>();

                Assert.Null(readGeometry);
            }
        }
예제 #9
0
        public void Parse_ParsesEmptyPoint()
        {
            string wkt = "point empty";

            Point parsed = WktReader.Parse <Point>(wkt);

            this.CompareCoordinate(Coordinate.Empty, parsed.Position);
        }
예제 #10
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);
        }
예제 #11
0
        public void Null()
        {
            var reader = new WktReader();

            var nothing = reader.Read("");

            Assert.AreEqual(null, nothing);
        }
예제 #12
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);
        }
예제 #13
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);
            }
        }
예제 #14
0
 /// <summary>
 /// Parse WKT entities from the <paramref name="reader"/>.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <returns>A WKT entity.</returns>
 public object Parse(TextReader reader)
 {
     if(reader == null) throw new ArgumentNullException("reader");
     Contract.EndContractBlock();
     var wktReader = new WktReader(reader, Options);
     return wktReader.MoveNext()
         ? wktReader.ReadEntity()
         : null;
 }
예제 #15
0
        public void Parse_Parses3DMeasuredPoint()
        {
            string wkt = "point zm (-10.1 15.5 100.5 1000.5)";

            Point parsed = WktReader.Parse <Point>(wkt);

            Assert.NotNull(parsed);
            this.CompareCoordinate(_coordinatesXYZM[0], parsed.Position);
        }
예제 #16
0
        public void Parse_ParsesMultiPoint()
        {
            string wkt = "multipoint empty";

            MultiPoint parsed = (MultiPoint)WktReader.Parse(wkt);

            Assert.NotNull(parsed);
            Assert.Empty(parsed.Geometries);
        }
예제 #17
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);
        }
예제 #18
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);
            }
        }
예제 #19
0
        public void Parse_ParsesEmptyMultiLineString()
        {
            string wkt = "multilinestring empty";

            MultiLineString parsed = WktReader.Parse <MultiLineString>(wkt);

            Assert.NotNull(parsed);
            Assert.Empty(parsed.Geometries);
        }
예제 #20
0
        public void Parse_ParsesEmptyMultiPolygon()
        {
            string wkt = "multipolygon empty";

            MultiPolygon parsed = WktReader.Parse <MultiPolygon>(wkt);

            Assert.NotNull(parsed);
            Assert.Empty(parsed.Geometries);
        }
예제 #21
0
        public void Parse_Parses3DMeasuredLineString()
        {
            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 parsed = WktReader.Parse <LineString>(wkt);

            Assert.NotNull(parsed);
            this.CompareCoordinates(_coordinatesXYZM, parsed.Coordinates);
        }
예제 #22
0
        public void Parse_Parses2DLineString()
        {
            string wkt = "linestring (-10.1 15.5, 20.2 -25.5, 30.3 35.5)";

            LineString parsed = WktReader.Parse <LineString>(wkt);

            Assert.NotNull(parsed);
            this.CompareCoordinates(_coordinatesXY, parsed.Coordinates);
        }
예제 #23
0
        public void Parse_ParsesEmptyLineString()
        {
            string wkt = "linestring empty";

            LineString parsed = WktReader.Parse <LineString>(wkt);

            Assert.NotNull(parsed);
            Assert.Empty(parsed.Coordinates);
        }
예제 #24
0
        public void Parse_ParsesEmptyGeometryCollection()
        {
            string wkt = "geometrycollection empty";

            GeometryCollection <Geometry> parsed = WktReader.Parse <GeometryCollection <Geometry> >(wkt);

            Assert.NotNull(parsed);
            Assert.Empty(parsed.Geometries);
        }
예제 #25
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);
        }
예제 #26
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);
        }
예제 #27
0
        public void Parse_ParsesPolygon()
        {
            string wkt = "polygon empty";

            Polygon parsed = (Polygon)WktReader.Parse(wkt);

            Assert.NotNull(parsed);
            Assert.Empty(parsed.ExteriorRing);
        }
        public void IsInRing_ReturnsFalseIfPointIsInRingAndCYCoordinateIsSameAsVertexYCoordinate()
        {
            string     wktRing = "linestring (-1 -1, 1 -1, 1 0.5, 1 1, -1 1, -1 -1)";
            LineString ring    = WktReader.Parse <LineString>(wktRing);

            Coordinate         c      = new Coordinate(-2, 0.5);
            Euclidean2DLocator target = new Euclidean2DLocator();

            Assert.False(target.IsInRing(c, ring.Coordinates));
        }
        public void IsInRing_ReturnsTrueIfPointIsInConcaveRing()
        {
            string     wktRing = "linestring (0 0, 2 0, 1 1, 1 2, 0 0)";
            LineString ring    = WktReader.Parse <LineString>(wktRing);

            Coordinate         c      = new Coordinate(1, 0.5);
            Euclidean2DLocator target = new Euclidean2DLocator();

            Assert.True(target.IsInRing(c, ring.Coordinates));
        }
        public void IsInRing_ReturnsFalseIfPointIsOutsideRing()
        {
            string     wktRing = "linestring (0 0, 2 0, 1 1, 1 2, 0 0)";
            LineString ring    = WktReader.Parse <LineString>(wktRing);

            Coordinate         c      = new Coordinate(3, 0);
            Euclidean2DLocator target = new Euclidean2DLocator();

            Assert.False(target.IsInRing(c, ring.Coordinates));
        }
        public void IsInRing_ReturnsTrueIfPointIsInSimpleRing()
        {
            string     wktRing = "linestring (-1 -1, 1 -1, 1 1, -1 1, -1 -1)";
            LineString ring    = WktReader.Parse <LineString>(wktRing);

            Coordinate         c      = new Coordinate(0.5, 0.5);
            Euclidean2DLocator target = new Euclidean2DLocator();

            Assert.True(target.IsInRing(c, ring.Coordinates));
        }
예제 #32
0
        public void Dispose_ClosesOutputStreamIfWritingToFiles()
        {
            string filename = "../../src/Tests.SpatialLite.Core/Data/IO/wkt-point-3DM.wkt";

            WktReader target = new WktReader(filename);
            target.Dispose();

            FileStream testStream = null;
            Assert.DoesNotThrow(() => testStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite));
            testStream.Dispose();
        }
예제 #33
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);
     }
 }
예제 #34
0
 public void ReadT_ThrowsExceptionIfWKTDoesNotRepresentGeometryOfSpecificType()
 {
     using (WktReader target = new WktReader(new MemoryStream(Data.IOTestData.wkt_point_3DM))) {
         Assert.Throws<WktParseException>(() => target.Read<LineString>());
     }
 }
예제 #35
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);
            }
        }
예제 #36
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);
            }
        }
예제 #37
0
        public void Read_ReturnsNullIfStreamIsEmpty()
        {
            using (WktReader target = new WktReader(new MemoryStream())) {
                IGeometry readGeometry = target.Read();

                Assert.Null(readGeometry);
            }
        }
예제 #38
0
 public void Read_ReadsAllGeometryTypes(byte[] data)
 {
     using (WktReader target = new WktReader(new MemoryStream(data))) {
         IGeometry readGeometry = target.Read();
         Assert.NotNull(readGeometry);
     }
 }
예제 #39
0
        public void Dispose_ClosesOutputStreamIfWritingToStream()
        {
            MemoryStream stream = new MemoryStream(Data.IOTestData.wkt_point_3DM);

            WktReader target = new WktReader(stream);
            target.Dispose();

            Assert.False(stream.CanRead);
        }