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(); }
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)); }
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(); }
/// <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); }