public static GeometryObject ToGeometry(this AbstractGeometryType gmlObject) { if (gmlObject == null) { throw new ArgumentNullException("gmlObject"); } if (gmlObject is MultiPolygonType) { return(((MultiPolygonType)gmlObject).ToGeometry()); } if (gmlObject is MultiLineStringType) { return(((MultiLineStringType)gmlObject).ToGeometry()); } if (gmlObject is MultiCurveType) { return(((MultiCurveType)gmlObject).ToGeometry()); } if (gmlObject is MultiSurfaceType) { return(((MultiSurfaceType)gmlObject).ToGeometry()); } if (gmlObject is PolygonType) { return(((PolygonType)gmlObject).ToGeometry()); } if (gmlObject is PointType) { return(((PointType)gmlObject).ToGeometry()); } if (gmlObject is LineStringType) { return(((LineStringType)gmlObject).ToGeometry()); } if (gmlObject is LinearRingType) { return(((LinearRingType)gmlObject).ToGeometry()); } if (gmlObject is MultiPointType) { return(((MultiPointType)gmlObject).ToGeometry()); } throw new NotImplementedException(); }
public static void Serialize(XmlWriter writer, AbstractGeometryType gmlObject) { XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); namespaces.Add("gml", "http://www.opengis.net/gml/3.2"); if (gmlObject is MultiCurveType) { MultiCurveSerializer.Serialize(writer, gmlObject, namespaces); return; } if (gmlObject is MultiSurfaceType) { MultiSurfaceSerializer.Serialize(writer, gmlObject, namespaces); return; } if (gmlObject is MultiPointType) { MultiPointSerializer.Serialize(writer, gmlObject, namespaces); return; } if (gmlObject is LineStringType) { LineStringSerializer.Serialize(writer, gmlObject, namespaces); return; } if (gmlObject is PolygonType) { PolygonSerializer.Serialize(writer, gmlObject, namespaces); return; } if (gmlObject is PointType) { PointSerializer.Serialize(writer, gmlObject, namespaces); return; } throw new NotImplementedException(gmlObject.GetType().ToString()); }
public static IGeometryObject ToGeometry(this AbstractGeometryType gmlObject) { if (gmlObject == null) { throw new ArgumentNullException("gmlObject"); } if (gmlObject is MultiCurveType) { return(((MultiCurveType)gmlObject).ToGeometry()); } if (gmlObject is MultiSurfaceType) { return(((MultiSurfaceType)gmlObject).ToGeometry()); } if (gmlObject is MultiPointType) { return(((MultiPointType)gmlObject).ToGeometry()); } throw new NotImplementedException(gmlObject.GetType().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); }