Exemplo n.º 1
0
        public void GmlMultiCurveWithLinearStringTestCase()
        {
            var fs = new FileStream(TestContext.CurrentContext.TestPath("../Samples/MultiCurveWithLinearString.gml"), FileMode.Open);

            var reader = XmlReader.Create(fs);

            var gml = GmlHelper.Deserialize(reader);

            fs.Close();

            var geom = (MultiLineString)gml.ToGeometry();

            gml = geom.ToGmlMultiLineString();

            var sw = new StringWriter();

            var xw = XmlWriter.Create(sw);

            GmlHelper.Serialize(xw, gml);

            var xml1 = sw.ToString();

            gml = geom.ToGmlMultiCurve();

            sw = new StringWriter();

            xw = XmlWriter.Create(sw);

            GmlHelper.Serialize(xw, gml);

            xw.Close();

            xml1 = sw.ToString();
        }
Exemplo n.º 2
0
        public void GmlMultiPolygonTestCase()
        {
            var fs = new FileStream(TestContext.CurrentContext.TestPath("../Samples/MultiPolygon.xml"), FileMode.Open);

            var reader = XmlReader.Create(fs);

            var gml = GmlHelper.Deserialize(reader);

            fs.Close();

            var geom = (MultiPolygon)gml.ToGeometry();

            gml = geom.ToGmlMultiSurface();

            var sw = new StringWriter();

            var xw = XmlWriter.Create(sw);

            GmlHelper.Serialize(xw, gml);

            xw.Close();

            gml = geom.ToGmlMultiPolygon();

            sw = new StringWriter();

            xw = XmlWriter.Create(sw);

            GmlHelper.Serialize(xw, gml);

            //Assert.IsTrue(XNode.DeepEquals(XDocument.Load("../Samples/MultiPolygon.xml").Root, XDocument.Parse(xml1).Root));
        }
Exemplo n.º 3
0
        public void Gml32MultiSurfaceToGeorss4()
        {
            var fs = new FileStream(TestContext.CurrentContext.TestPath("../Samples/multisurface32-4.xml"), FileMode.Open, FileAccess.Read);

            var reader = XmlReader.Create(fs);

            var gml = GmlHelper.Deserialize(reader);

            fs.Close();

            var geom = gml.ToGeometry();

            Assert.IsTrue(geom is MultiPolygon);

            var georss = (GeoRssWhere)geom.ToGeoRss();

            Assert.AreEqual("multipolygon", georss.Type);

            var georss2 = (GeoRssWhere)GeoRssHelper.Deserialize(georss.CreateReader());

            Assert.AreEqual("multipolygon", georss2.Type);

            var geom2 = georss.ToGeometry();

            Assert.IsTrue(geom2 is MultiPolygon);

            var json = new Feature.Feature(geom, null);
        }
Exemplo n.º 4
0
        public void Gml32MultiSurfaceToGeorss()
        {
            var fs = new FileStream(TestContext.CurrentContext.TestPath("../Samples/multisurface32-3.xml"), FileMode.Open, FileAccess.Read);

            var reader = XmlReader.Create(fs);

            var gml = GmlHelper.Deserialize(reader);

            fs.Close();

            Assert.Throws <IndexOutOfRangeException>(() => gml.ToGeometry());
        }
Exemplo n.º 5
0
        public void Gml32MultiSurfaceToGeorss()
        {
            var fs = new FileStream(TestContext.CurrentContext.TestPath("../Samples/multisurface32-2.xml"), FileMode.Open, FileAccess.Read);

            XmlReader reader = XmlReader.Create(fs);

            var gml = GmlHelper.Deserialize(reader);

            fs.Close();

            MultiPolygon geom = (MultiPolygon)Terradue.GeoJson.Gml321.Gml321Extensions.ToGeometry(gml);

            XmlDocument doc = new XmlDocument();

            doc.Load(geom.ToGeoRss().CreateReader());
            doc.Save(TestContext.CurrentContext.TestPath("../out/georssfromgml32.xml"));
        }
Exemplo n.º 6
0
        public void GmlMultiSurfaceTestCase()
        {
            var fs = new FileStream(TestContext.CurrentContext.TestPath("../Samples/MultiSurface311.gml"), FileMode.Open);

            var reader = XmlReader.Create(fs);

            var gml = GmlHelper.Deserialize(reader);

            fs.Close();

            var geom = (MultiPolygon)gml.ToGeometry();

            gml = geom.ToGml();

            Assert.That(gml is MultiPolygonType);

            var sw = new StringWriter();

            var xw = XmlWriter.Create(sw);

            GmlHelper.Serialize(xw, gml);

            var xml1 = sw.ToString();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Feature转换成GGGX数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public static XmlDocument FeatureToGGGX(List <GeoFeature> list)
        {
            List <GeoFeature> ftList = list;
            //初始化一个xml实例
            XmlDocument myXmlDoc = new XmlDocument();

            //GeoFeature current2 = null;
            try
            {
                XmlDeclaration declaration = myXmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
                myXmlDoc.AppendChild(declaration);

                XmlNamespaceManager xnm = new XmlNamespaceManager(myXmlDoc.NameTable);
                xnm.AddNamespace("gml", "http://www.opengis.net/gml");
                xnm.AddNamespace(string.Empty, "http://www.jurassic.com.cn/3gx");

                //创建xml的根节点
                XmlElement rootElement = myXmlDoc.CreateElement("", "FeatureCollection", "http://www.jurassic.com.cn/3gx");

                rootElement.SetAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
                rootElement.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");

                rootElement.SetAttribute("name", "GGGX数据 ");//设置该节点genre属性
                rootElement.SetAttribute("xsi:schemaLocation", "http://www.jurassic.com.cn/3gx 3GX.Data.Feature.GeoMap.xsd");
                myXmlDoc.AppendChild(rootElement);

                XmlElement crsElement = myXmlDoc.CreateElement("CRS", "http://www.jurassic.com.cn/3gx");
                crsElement.SetAttribute("codeSpace", "china");
                crsElement.InnerText = "地理坐标(经纬度)";
                rootElement.AppendChild(crsElement);

                foreach (GeoFeature ft in ftList)
                {
                    //current2 = ft;
                    XmlElement gfElement = myXmlDoc.CreateElement("GF", "http://www.jurassic.com.cn/3gx");
                    gfElement.SetAttribute("class", ft.CLASS);
                    gfElement.SetAttribute("id", ft.BOID);
                    gfElement.SetAttribute("bot", ft.BOT);
                    gfElement.SetAttribute("type", ft.FT);

                    XmlElement titleElement = myXmlDoc.CreateElement("Title", "http://www.jurassic.com.cn/3gx");
                    titleElement.InnerText = ft.NAME;
                    gfElement.AppendChild(titleElement);
                    if (ft.AliasNameList != null)
                    {
                        foreach (AliasName aliasName in ft.AliasNameList)
                        {
                            XmlElement nameElement = myXmlDoc.CreateElement("Name");
                            nameElement.SetAttribute("codeSpace", aliasName.APPDOMAIN);
                            nameElement.InnerText = aliasName.NAME;
                            gfElement.AppendChild(nameElement);
                        }
                    }
                    XmlElement PropertySetsElement = myXmlDoc.CreateElement("PropertySets", "http://www.jurassic.com.cn/3gx");
                    if (ft.PropertyList != null)
                    {
                        foreach (Property property in ft.PropertyList)
                        {
                            XmlDocumentFragment propertyElement = myXmlDoc.CreateDocumentFragment();
                            propertyElement.InnerXml = XMLHelper.RemoveAllNamespaces(property.MD);
                            PropertySetsElement.AppendChild(propertyElement);
                        }
                    }
                    gfElement.AppendChild(PropertySetsElement);

                    XmlElement shapesElement = myXmlDoc.CreateElement("Shapes", "http://www.jurassic.com.cn/3gx");
                    if (ft.GeometryList != null)
                    {
                        foreach (Geometry geometry in ft.GeometryList)
                        {
                            XmlElement shapeElement = myXmlDoc.CreateElement("Shape", "http://www.jurassic.com.cn/3gx");
                            shapeElement.SetAttribute("name", geometry.NAME);
                            XmlReader reader = XmlReader.Create(new StringReader(DbGeography.FromText(geometry.GEOMETRY).AsGml()));
                            reader.Read();
                            AbstractGeometryType gml = GmlHelper.Deserialize(reader);
                            StringWriter         sw  = new StringWriter();
                            XmlWriter            xw  = XmlWriter.Create(sw);
                            GmlHelper.Serialize(xw, gml);

                            XmlDocument shapeDoc = new XmlDocument();
                            shapeDoc.LoadXml(sw.ToString());

                            XmlDocumentFragment shape = myXmlDoc.CreateDocumentFragment();
                            shape.InnerXml = shapeDoc.DocumentElement.OuterXml;

                            shapeElement.AppendChild(shape);
                            shapesElement.AppendChild(shapeElement);
                        }
                    }
                    gfElement.AppendChild(shapesElement);

                    rootElement.AppendChild(gfElement);
                }
            }
            catch (Exception ex)
            {
                //Jurassic.So.Infrastructure.Logging.Logger.InfoBO(current2, myXmlDoc);
                throw ex;
            }
            myXmlDoc.LoadXml(myXmlDoc.OuterXml.Replace("xmlns=\"\"", ""));
            return(myXmlDoc);
        }