async static public Task <FeatureClass> CreateAsync(Dataset dataset, string name, Fields fields) { var fc = new FeatureClass(dataset, name, fields); if (dataset != null) { fc.SpatialReference = await dataset.GetSpatialReference(); fc.Envelope = await dataset.Envelope(); } return(fc); }
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); } }
public bool Open() { try { _state = DatasetState.unknown; _elements.Clear(); FileInfo fi_gml = new FileInfo(_connectionString); if (!fi_gml.Exists) { return(false); } FileInfo fi_xsd = new FileInfo(fi_gml.FullName.Substring(0, fi_gml.FullName.Length - fi_gml.Extension.Length) + ".xsd"); if (!fi_xsd.Exists) { return(false); } _gml_file = fi_gml.FullName; _xsd_file = fi_xsd.FullName; XmlDocument schema = new XmlDocument(); schema.Load(System.IO.File.ReadAllText(fi_xsd.FullName)); XmlSchemaReader schemaReader = new XmlSchemaReader(schema); string targetNamespace = schemaReader.TargetNamespaceURI; if (targetNamespace == String.Empty) { return(false); } PlugInManager compMan = new PlugInManager(); foreach (string elementName in schemaReader.ElementNames) { string shapeFieldName; geometryType geomType; Fields fields = schemaReader.ElementFields(elementName, out shapeFieldName, out geomType); FeatureClass fc = new FeatureClass(this, elementName, fields); fc.ShapeFieldName = shapeFieldName; fc.GeometryType = geomType; IFeatureLayer layer = LayerFactory.Create(fc) as IFeatureLayer; if (layer == null) { continue; } //layer.FeatureRenderer = compMan.getComponent(KnownObjects.Carto_UniversalGeometryRenderer) as IFeatureRenderer; _elements.Add(layer); } _doc = new XmlDocument(); using (XmlTextReader xmlTextReader = new XmlTextReader(fi_gml.FullName)) { xmlTextReader.ReadToDescendant("boundedBy", "http://www.opengis.net/gml"); string boundedBy = xmlTextReader.ReadOuterXml(); _doc.LoadXml(boundedBy); } _ns = new XmlNamespaceManager(_doc.NameTable); _ns.AddNamespace("GML", "http://www.opengis.net/gml"); _ns.AddNamespace("WFS", "http://www.opengis.net/wfs"); _ns.AddNamespace("OGC", "http://www.opengis.net/ogc"); _ns.AddNamespace("myns", targetNamespace); XmlNode boundedByNode = _doc.ChildNodes[0]; if (boundedByNode != null) { XmlNode geomNode = boundedByNode.SelectSingleNode("GML:*", _ns); if (geomNode != null) { _envelope = GeometryTranslator.GML2Geometry(geomNode.OuterXml, _gmlVersion) as IEnvelope; if (geomNode.Attributes["srsName"] != null) { _sRef = gView.Framework.Geometry.SpatialReference.FromID(geomNode.Attributes["srsName"].Value); } } } _state = DatasetState.opened; return(true); } catch (Exception ex) { _errMsg = ex.Message; return(false); } }