public bool AppendFeature(IFeatureClass fc, IFeature feature) { if (_doc == null || fc == null || feature == null) { return(false); } XmlNode featureCollection = _doc.SelectSingleNode("GML:FeatureCollection", _ns); if (featureCollection == null) { return(false); } XmlNode featureMember = _doc.CreateElement("gml", "featureMember", _ns.LookupNamespace("GML")); XmlNode featureclass = _doc.CreateElement("gv", fc.Name, _ns.LookupNamespace("myns")); featureMember.AppendChild(featureclass); if (feature.Shape != null) { try { string geom = GeometryTranslator.Geometry2GML(feature.Shape, String.Empty, _gmlVersion); geom = @"<gml:theGeometry xmlns:gml=""http://www.opengis.net/gml"">" + geom + "</gml:theGeometry>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(geom); XmlNode geomNode = _doc.CreateElement("gv", fc.ShapeFieldName.Replace("#", ""), _ns.LookupNamespace("myns")); foreach (XmlNode node in doc.ChildNodes[0].ChildNodes) { geomNode.AppendChild(_doc.ImportNode(node, true)); } if (!UpdateEnvelope(feature.Shape.Envelope)) { _errMsg = "Can't update envelope..."; return(false); } featureclass.AppendChild(geomNode); } catch (Exception ex) { _errMsg = ex.Message; return(false); } } foreach (FieldValue fv in feature.Fields) { XmlNode attrNode = _doc.CreateElement("gv", fv.Name.Replace("#", ""), _ns.LookupNamespace("myns")); if (fv.Value != null) { attrNode.InnerText = fv.Value.ToString(); } featureclass.AppendChild(attrNode); } featureCollection.AppendChild(featureMember); return(true); }
public static bool Create(string filename, IGeometryDef geomDef, Fields fields, GmlVersion gmlVersion) { try { FileInfo fi = new FileInfo(filename); string name = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length); string gml_filename = fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + ".gml"; string xsd_filename = fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + ".xsd"; FeatureClass featureClass = new FeatureClass(null, name, fields); XmlSchemaWriter schemaWriter = new XmlSchemaWriter(featureClass); string schema = schemaWriter.Write(); using (StreamWriter sw = new StreamWriter(xsd_filename, false, Encoding.UTF8)) { sw.WriteLine(schema.Trim()); sw.Flush(); sw.Close(); } using (StreamWriter sw = new StreamWriter(gml_filename, false, Encoding.UTF8)) { sw.Write(@"<?xml version=""1.0"" encoding=""UTF-8""?> <gml:FeatureCollection xmlns:gml=""http://www.opengis.net/gml"" xmlns:xlink=""http://www.w3.org/1999/xlink"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:gv=""http://www.gViewGIS.com/server"" xsi:schemaLocation=""http://www.gview.com/gml " + name + @".xsd"">".Trim()); string boundingBox = GeometryTranslator.Geometry2GML(new Envelope(), String.Empty, gmlVersion); sw.WriteLine(@" <gml:boundedBy>"); sw.Write(boundingBox); sw.Write(@" </gml:boundedBy>"); sw.Write(@" </gml:FeatureCollection>"); sw.Flush(); sw.Close(); } return(true); } catch { return(false); } }