/// <summary> /// Set the current element's content from the current XML node /// </summary> /// <param name="node"></param> /// <param name="mgr"></param> public void ReadXml(XmlNode node, XmlNamespaceManager mgr) { if (!node.Name.Equals("fdo:DataStore")) //NOXLATE { throw new Exception(string.Format(Strings.ErrorBadDocumentExpectedElement, "fdo:DataStore")); //NOXLATE } _spatialContexts.Clear(); _schemas.Clear(); XmlNodeList csNodes = node.SelectNodes("gml:DerivedCRS", mgr); //NOXLATE foreach (XmlNode cs in csNodes) { var context = new FdoSpatialContextListSpatialContext(); context.ReadXml(cs, mgr); AddSpatialContext(context); } XmlNodeList schemaNodes = node.SelectNodes("xs:schema", mgr); //NOXLATE foreach (XmlNode sn in schemaNodes) { FeatureSchema fs = new FeatureSchema(); fs.ReadXml(sn, mgr); AddSchema(fs); } ReadSchemaMappings(node, mgr); }
/// <summary> /// Gets the default spatial context from this configuration document. If none is found, the first spatial /// context from the given Feature Source is used /// </summary> /// <param name="fs"></param> /// <param name="conn"></param> /// <returns></returns> public string GetDefaultSpatialContext(IFeatureSource fs, IServerConnection conn) { //BOGUS: This was not as sufficient as I originally thought, nevertheless this contains //information that would not exist if we constructed the document the old fashioned way. string defaultScName = string.Empty; if (this.SpatialContexts.Length > 0) { defaultScName = this.SpatialContexts[0].Name; } else { var list = conn.FeatureService.GetSpatialContextInfo(fs.ResourceID, false); if (list.SpatialContext.Count > 0) { defaultScName = list.SpatialContext[0].Name; } else //Really? What kind of WMS service are you???? { var sc = new FdoSpatialContextListSpatialContext() { Name = "EPSG:4326", //NOXLATE Description = "Maestro-generated spatial context", //NOXLATE CoordinateSystemName = "EPSG:4326", //NOXLATE CoordinateSystemWkt = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]", //NOXLATE Extent = new FdoSpatialContextListSpatialContextExtent() { LowerLeftCoordinate = new FdoSpatialContextListSpatialContextExtentLowerLeftCoordinate() { X = "-180.0", //NOXLATE Y = "-90.0" //NOXLATE }, UpperRightCoordinate = new FdoSpatialContextListSpatialContextExtentUpperRightCoordinate() { X = "180.0", //NOXLATE Y = "90.0" //NOXLATE } }, ExtentType = FdoSpatialContextListSpatialContextExtentType.Static, IsActive = true, XYTolerance = 0.0001, ZTolerance = 0.0001, }; this.AddSpatialContext(sc); defaultScName = sc.Name; } } return(defaultScName); }
public void TestLoadFromStream() { var spatialContext = new FdoSpatialContextListSpatialContext() { Name = "Default", Description = "Test Spatial Context", CoordinateSystemName = "Default", CoordinateSystemWkt = "", ExtentType = FdoSpatialContextListSpatialContextExtentType.Static, Extent = new FdoSpatialContextListSpatialContextExtent { LowerLeftCoordinate = new FdoSpatialContextListSpatialContextExtentLowerLeftCoordinate { X = "-180.0", Y = "-90.0" }, UpperRightCoordinate = new FdoSpatialContextListSpatialContextExtentUpperRightCoordinate { X = "180.0", Y = "90" } }, XYTolerance = 0.00001, ZTolerance = 0.00001 }; var doc = new GenericConfigurationDocument(); var schema = new FeatureSchema("Default", ""); var cls = new ClassDefinition("Test", ""); var id = new DataPropertyDefinition("ID", "") { DataType = DataPropertyType.Int32 }; var name = new DataPropertyDefinition("Name", "") { IsNullable = true }; var geom = new GeometricPropertyDefinition("Geometry", "") { SpatialContextAssociation = spatialContext.Name, GeometricTypes = FeatureGeometricType.Point }; cls.AddProperty(id, true); cls.AddProperty(name); cls.AddProperty(geom); cls.DefaultGeometryPropertyName = geom.Name; schema.AddClass(cls); doc.AddSchema(schema); doc.AddSpatialContext(spatialContext); var xmldoc = new XmlDocument(); using (var ms = new MemoryStream()) { var xml = doc.ToXml(); xmldoc.LoadXml(xml); using (var xw = XmlWriter.Create(ms)) { xmldoc.WriteTo(xw); } //Rewind ms.Position = 0L; var fsd = new FeatureSourceDescription(ms); Assert.Single(fsd.SchemaNames); foreach (var sn in fsd.SchemaNames) { var sch1 = fsd.GetSchema(sn); Assert.NotNull(sch1); Assert.Equal(schema.Name, sch1.Name); foreach (var klass in schema.Classes) { var c1 = fsd.GetClass($"{schema.Name}:{klass.Name}"); var c2 = fsd.GetClass(schema.Name, klass.Name); Assert.Equal(klass.Name, c1.Name); Assert.Equal(c1.Name, c2.Name); Assert.Equal(3, klass.Properties.Count); Assert.Equal(klass.Properties.Count, c1.Properties.Count); Assert.Equal(c1.Properties.Count, c2.Properties.Count); } } } }
public void TestOdbcSaveLoad() { var schema = new FeatureSchema("Default", "Test schema"); var cls = new ClassDefinition("Cities", "Cities class"); cls.AddProperty(new DataPropertyDefinition("ID", "Primary Key") { DataType = DataPropertyType.Int64, IsNullable = false, IsAutoGenerated = true }, true); cls.AddProperty(new DataPropertyDefinition("Name", "City Name") { DataType = DataPropertyType.String, IsNullable = true, IsAutoGenerated = false, Length = 255 }); cls.AddProperty(new GeometricPropertyDefinition("Geometry", "Geometry property") { GeometricTypes = FeatureGeometricType.Point, SpecificGeometryTypes = new SpecificGeometryType[] { SpecificGeometryType.Point }, HasElevation = false, HasMeasure = false, SpatialContextAssociation = "Default" }); cls.AddProperty(new DataPropertyDefinition("Population", "Population") { DataType = DataPropertyType.Int32, IsNullable = true, IsAutoGenerated = false }); cls.DefaultGeometryPropertyName = "Geometry"; schema.AddClass(cls); var sc = new FdoSpatialContextListSpatialContext(); sc.CoordinateSystemName = "LL84"; sc.CoordinateSystemWkt = ""; sc.Description = "Default Spatial Context"; sc.Extent = new FdoSpatialContextListSpatialContextExtent() { LowerLeftCoordinate = new FdoSpatialContextListSpatialContextExtentLowerLeftCoordinate() { X = "-180.0", Y = "-180.0" }, UpperRightCoordinate = new FdoSpatialContextListSpatialContextExtentUpperRightCoordinate() { X = "180.0", Y = "180.0" } }; sc.ExtentType = FdoSpatialContextListSpatialContextExtentType.Static; sc.Name = "Default"; sc.XYTolerance = 0.0001; sc.ZTolerance = 0.0001; var conf = new OdbcConfigurationDocument(); conf.AddSchema(schema); conf.AddSpatialContext(sc); var ov = new OdbcTableItem(); ov.SchemaName = schema.Name; ov.ClassName = cls.Name; ov.SpatialContextName = sc.Name; ov.XColumn = "Lon"; ov.YColumn = "Lat"; conf.AddOverride(ov); string path = "OdbcConfigTest.xml"; Utils.WriteAllText(path, conf.ToXml()); conf = null; string xml = Utils.ReadAllText(path); conf = ConfigurationDocument.LoadXml(xml) as OdbcConfigurationDocument; Assert.NotNull(conf); ov = conf.GetOverride("Default", "Cities"); Assert.NotNull(ov); Assert.AreEqual("Default", ov.SchemaName); Assert.AreEqual("Cities", ov.ClassName); Assert.AreEqual(sc.Name, ov.SpatialContextName); Assert.AreEqual("Lon", ov.XColumn); Assert.AreEqual("Lat", ov.YColumn); }