Example #1
0
        public static GeometryObject ToGeometry(this GeoRssPolygon georssPolygon)
        {
            if (georssPolygon.Item == null)
            {
                return(null);
            }

            Polygon polygon = new Polygon();

            polygon.LineStrings = new List <LineString>();

            LineString ls = new LineString(new DirectPositionListType()
            {
                Text = georssPolygon.Item
            }.ToGeometry());

            if (ls.Positions.Count < 4 || !ls.IsClosed())
            {
                throw new InvalidFormatException("invalid GML representation: linearring is not a closed ring of minimum 4 positions");
            }

            polygon.LineStrings.Add(ls);

            return(polygon);
        }
Example #2
0
        public void GeoRssPloygonTestCase()
        {
            string xml = "<georss:polygon xmlns:georss=\"http://www.georss.org/georss\">45.256 -110.45 46.46 -109.48 43.84 -109.86 45.256 -110.45</georss:polygon>";

            var reader = XmlReader.Create(new StringReader(xml));

            Terradue.GeoJson.GeoRss.GeoRssPolygon line = (Terradue.GeoJson.GeoRss.GeoRssPolygon)Terradue.GeoJson.GeoRss.GeoRssHelper.Deserialize(reader);

            var geom = line.ToGeometry();

            Assert.That(geom is Polygon);

            Assert.That(((Polygon)geom).LineStrings[0].Positions[0] is GeographicPosition);

            Assert.AreEqual(45.256, ((GeographicPosition)((Polygon)geom).LineStrings[0].Positions[0]).Latitude);

            Assert.AreEqual(-110.45, ((GeographicPosition)((Polygon)geom).LineStrings[0].Positions[0]).Longitude);

            Assert.True(((Polygon)geom).LineStrings[0].IsClosed());

            line = (GeoRssPolygon)geom.ToGeoRss();
            var sw = new StringWriter();

            GeoRssHelper.Serialize(XmlWriter.Create(sw), line);

            sw.Close();

            var xml1 = sw.ToString();

            Assert.IsTrue(XNode.DeepEquals(XDocument.Parse(xml).Root, XDocument.Parse(xml1).Root));
        }