Пример #1
0
        private static string GetGeometryUsingNTS(Geometry geometry)
        {
            var gmlWriter = new GMLWriter();
            var ms        = new MemoryStream();

            gmlWriter.Write(geometry, ms);
            return(System.Text.Encoding.Default.GetString(ms.ToArray()));
        }
Пример #2
0
        private static string GenerateTestFragment()
        {
            StringBuilder sb     = new StringBuilder();
            XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb));

            writer.WriteStartElement("test");
            writer.WriteAttributeString("xmlns", "gml", null, "http://www.opengis.net/gml");

            Point     geom      = new Point(52, -0.9);
            GMLWriter gmlWriter = new GMLWriter();

            gmlWriter.Write(geom, writer);

            writer.WriteEndElement();
            return(sb.ToString());
        }
Пример #3
0
        public GMLTesting()
        {
            _point = Factory.CreatePoint(new Coordinate(100, 100));

            Coordinate[] coordinates =
            {
                new Coordinate(10, 10),
                new Coordinate(20, 20),
                new Coordinate(20, 10)
            };
            _line = Factory.CreateLineString(coordinates);

            coordinates = new[]
            {
                new Coordinate(100, 100),
                new Coordinate(200, 100),
                new Coordinate(200, 200),
                new Coordinate(100, 200),
                new Coordinate(100, 100)
            };
            Coordinate[] interior1 =
            {
                new Coordinate(120, 120),
                new Coordinate(180, 120),
                new Coordinate(180, 180),
                new Coordinate(120, 180),
                new Coordinate(120, 120)
            };
            var linearRing = Factory.CreateLinearRing(coordinates);

            LinearRing[] holes = { Factory.CreateLinearRing(interior1) };
            _polygon = Factory.CreatePolygon(linearRing, holes);

            coordinates = new[]
            {
                new Coordinate(100, 100),
                new Coordinate(200, 200),
                new Coordinate(300, 300),
                new Coordinate(400, 400),
                new Coordinate(500, 500)
            };
            _multiPoint = Factory.CreateMultiPointFromCoords(coordinates);

            _writer = new GMLWriter();
            _reader = new GMLReader();
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        public GMLTesting()
        {
            point = Factory.CreatePoint(new Coordinate(100, 100));

            ICoordinate[] coordinates = new ICoordinate[]
            {
                new Coordinate(10, 10),
                new Coordinate(20, 20),
                new Coordinate(20, 10),
            };
            line = Factory.CreateLineString(coordinates);

            coordinates = new ICoordinate[]
            {
                new Coordinate(100, 100),
                new Coordinate(200, 100),
                new Coordinate(200, 200),
                new Coordinate(100, 200),
                new Coordinate(100, 100),
            };
            ICoordinate[] interior1 = new ICoordinate[]
            {
                new Coordinate(120, 120),
                new Coordinate(180, 120),
                new Coordinate(180, 180),
                new Coordinate(120, 180),
                new Coordinate(120, 120),
            };
            ILinearRing linearRing = Factory.CreateLinearRing(coordinates);

            ILinearRing[] holes = new ILinearRing[] { Factory.CreateLinearRing(interior1), };
            polygon = Factory.CreatePolygon(linearRing, holes);

            coordinates = new ICoordinate[]
            {
                new Coordinate(100, 100),
                new Coordinate(200, 200),
                new Coordinate(300, 300),
                new Coordinate(400, 400),
                new Coordinate(500, 500),
            };
            multiPoint = Factory.CreateMultiPoint(coordinates);

            writer = new GMLWriter();
            reader = new GMLReader();
        }
Пример #5
0
        public void WriteEmptyGeometryCollection()
        {
            var geometry = new WKTReader().Read("GEOMETRYCOLLECTION EMPTY");

            var gmlWriter = new GMLWriter();
            var reader    = gmlWriter.Write(geometry);
            var document  = XDocument.Load(reader);

            document.Validate(CreateSchemaSet(), (sender, args) =>
            {
                // Currently also fails because of other issue 469, that is why we filter out the message
                if (args.Message.StartsWith("The element 'MultiGeometry' in namespace 'http://www.opengis.net/gml' has incomplete content"))
                {
                    Assert.Fail(args.Message);
                }
            });

            Assert.IsNotNull(document.Element(XName.Get("MultiGeometry", "http://www.opengis.net/gml")).Element(XName.Get("geometryMember", "http://www.opengis.net/gml")));
        }
Пример #6
0
        public void Issue469GeometryCollection()
        {
            int srid     = 31370;
            var geometry = new WKTReader(new NtsGeometryServices(new PrecisionModel(), srid)).Read("GEOMETRYCOLLECTION (POINT (40 10), LINESTRING(10 10, 20 20, 10 40), POLYGON((40 40, 20 45, 45 30, 40 40)))");

            var gmlWriter = new GMLWriter();
            var reader    = gmlWriter.Write(geometry);
            var document  = XDocument.Load(reader);

            document.Validate(CreateSchemaSet(), (sender, args) =>
            {
                Assert.Fail(args.Message);
            });

            var element   = document.Element(XName.Get("MultiGeometry", "http://www.opengis.net/gml"));
            var attribute = element.Attribute(XName.Get("srsName"));

            Assert.IsNotNull(attribute);
            Assert.AreEqual(attribute.Value, $"EPSG:{geometry.Factory.SRID}");
            Assert.AreEqual(attribute.Value, $"EPSG:{srid}");
        }
Пример #7
0
        public void Issue469MultiPoint()
        {
            int srid     = 31370;
            var geometry = new WKTReader(new NtsGeometryServices(new PrecisionModel(), srid)).Read("MULTIPOINT (10 40, 40 30, 20 20, 30 10)");

            var gmlWriter = new GMLWriter();
            var reader    = gmlWriter.Write(geometry);
            var document  = XDocument.Load(reader);

            document.Validate(CreateSchemaSet(), (sender, args) =>
            {
                Assert.Fail(args.Message);
            });

            var element   = document.Element(XName.Get($"{geometry.GeometryType}", "http://www.opengis.net/gml"));
            var attribute = element.Attribute(XName.Get("srsName"));

            Assert.IsNotNull(attribute);
            Assert.AreEqual(attribute.Value, $"EPSG:{geometry.Factory.SRID}");
            Assert.AreEqual(attribute.Value, $"EPSG:{srid}");
        }