/// <summary> /// Initializes a new instance of the <see cref="FeatureSourceDescription"/> class. /// </summary> /// <param name="stream">The stream.</param> public FeatureSourceDescription(System.IO.Stream stream) { List<FeatureSchema> schemas = new List<FeatureSchema>(); XmlDocument doc = new XmlDocument(); doc.Load(stream); XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable); mgr.AddNamespace("xs", XmlNamespaces.XS); //NOXLATE mgr.AddNamespace("gml", XmlNamespaces.GML); //NOXLATE mgr.AddNamespace("fdo", XmlNamespaces.FDO); //NOXLATE //Assume XML configuration document XmlNodeList schemaNodes = doc.SelectNodes("fdo:DataStore/xs:schema", mgr); //NOXLATE if (schemaNodes.Count == 0) //Then assume FDO schema schemaNodes = doc.SelectNodes("xs:schema", mgr); //NOXLATE foreach (XmlNode sn in schemaNodes) { FeatureSchema fs = new FeatureSchema(); fs.ReadXml(sn, mgr); schemas.Add(fs); } this.Schemas = schemas.ToArray(); }
/// <summary> /// Initializes a new instance of the <see cref="FeatureSourceDescription"/> class. /// </summary> /// <param name="stream">The stream.</param> public FeatureSourceDescription(System.IO.Stream stream) { List <FeatureSchema> schemas = new List <FeatureSchema>(); XmlDocument doc = new XmlDocument(); doc.Load(stream); XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable); mgr.AddNamespace("xs", XmlNamespaces.XS); //NOXLATE mgr.AddNamespace("gml", XmlNamespaces.GML); //NOXLATE mgr.AddNamespace("fdo", XmlNamespaces.FDO); //NOXLATE //Assume XML configuration document XmlNodeList schemaNodes = doc.SelectNodes("fdo:DataStore/xs:schema", mgr); //NOXLATE if (schemaNodes.Count == 0) //Then assume FDO schema { schemaNodes = doc.SelectNodes("xs:schema", mgr); //NOXLATE } foreach (XmlNode sn in schemaNodes) { FeatureSchema fs = new FeatureSchema(); fs.ReadXml(sn, mgr); schemas.Add(fs); } this.Schemas = schemas.ToArray(); }
/// <summary> /// Creates a clone of the specified instance /// </summary> /// <param name="fs">The instance to clone</param> /// <returns></returns> public static FeatureSchema Clone(FeatureSchema fs) { var clone = new FeatureSchema(fs.Name, fs.Description); foreach (var cls in fs.Classes) { clone.AddClass(ClassDefinition.Clone(cls)); } return(clone); }
/// <summary> /// Creates a clone of the specified instance /// </summary> /// <param name="fsd">The instance to clone</param> /// <returns></returns> public static FeatureSourceDescription Clone(FeatureSourceDescription fsd) { var schemas = new List <FeatureSchema>(); foreach (var fs in fsd.Schemas) { schemas.Add(FeatureSchema.Clone(fs)); } return(new FeatureSourceDescription(schemas, fsd.IsPartial)); }
private TreeNode CreateSchemaNode(FeatureSchema schema) { var node = new TreeNode(); node.Name = schema.Name; node.Text = schema.Name; foreach (ClassDefinition cls in schema.Classes) { var clsNode = CreateClassNode(cls); node.Nodes.Add(clsNode); } node.Tag = schema; return node; }
private WmsConfigurationDocument BuildDefaultWmsDocument() { var doc = new WmsConfigurationDocument(); var contexts = _fs.GetSpatialInfo(false); var schemaName = _fs.GetSchemaNames()[0]; var clsNames = _fs.GetClassNames(schemaName); var schema = new FeatureSchema(schemaName, string.Empty); doc.AddSchema(schema); foreach (var sc in contexts.SpatialContext) { doc.AddSpatialContext(sc); } var defaultSc = contexts.SpatialContext[0]; foreach (var clsName in clsNames) { var className = clsName.Split(':')[1]; //NOXLATE var cls = new ClassDefinition(className, string.Empty); cls.AddProperty(new DataPropertyDefinition("Id", string.Empty) //NOXLATE { DataType = DataPropertyType.String, Length = 256, IsNullable = false }, true); cls.AddProperty(new RasterPropertyDefinition("Image", string.Empty) //NOXLATE { DefaultImageXSize = 1024, DefaultImageYSize = 1024, SpatialContextAssociation = defaultSc.Name }); schema.AddClass(cls); var item = CreateDefaultItem(schema.Name, cls.Name, "Image", defaultSc); //NOXLATE doc.AddRasterItem(item); } return doc; }
protected override ClassDefinition GetClassDefinitionInternal(string resourceId, string schemaName, string className) { var fsvc = (MgFeatureService)this.Connection.CreateService(MgServiceType.FeatureService); var cls = fsvc.GetClassDefinition(new MgResourceIdentifier(resourceId ?? ""), schemaName ?? "", className ?? ""); var klass = Native.Utility.ConvertClassDefinition(cls); var parent = new FeatureSchema(schemaName, ""); parent.AddClass(klass); return klass; }
protected override ClassDefinition GetClassDefinitionInternal(string resourceId, string schemaName, string className) { var cls = GetFeatureService().GetClassDefinition(new MgResourceIdentifier(resourceId), schemaName, className); var klass = Native.Utility.ConvertClassDefinition(cls); var parent = new FeatureSchema(schemaName, ""); parent.AddClass(klass); return klass; }
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"; File.WriteAllText(path, conf.ToXml()); conf = null; string xml = File.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); }
public void TestWmsSaveLoad() { var conf = new WmsConfigurationDocument(); var schema = new FeatureSchema("WMS", "WMS Test Schema"); var cls = new ClassDefinition("NASAWMSGlobalPan", "WMS Test Class"); cls.AddProperty(new DataPropertyDefinition("Id", "ID Property") { DataType = DataPropertyType.String, Length = 256, IsNullable = false }, true); cls.AddProperty(new RasterPropertyDefinition("Image", "Raster Property") { DefaultImageXSize = 800, DefaultImageYSize = 800 }); schema.AddClass(cls); conf.AddSchema(schema); var item = new RasterWmsItem(schema.Name, cls.Name, "Image"); item.ImageFormat = RasterWmsItem.WmsImageFormat.PNG; item.IsTransparent = true; item.BackgroundColor = ColorTranslator.FromHtml("#FFFFFF"); item.Time = "current"; item.ElevationDimension = "0"; item.SpatialContextName = "EPSG:4326"; for (int i = 0; i < 5; i++) { item.AddLayer(new WmsLayerDefinition("Layer" + i)); } conf.AddRasterItem(item); string path = "WmsConfigTest.xml"; File.WriteAllText(path, conf.ToXml()); conf = null; string xml = File.ReadAllText(path); conf = ConfigurationDocument.LoadXml(xml) as WmsConfigurationDocument; Assert.NotNull(conf); Assert.AreEqual(1, conf.RasterOverrides.Length); var ritem = conf.RasterOverrides[0]; cls = conf.GetClass("WMS", "NASAWMSGlobalPan"); Assert.NotNull(cls); Assert.NotNull(cls.Parent); Assert.AreEqual("WMS", cls.Parent.Name); Assert.AreEqual("WMS Test Schema", cls.Parent.Description); Assert.AreEqual("NASAWMSGlobalPan", cls.Name); Assert.AreEqual("WMS Test Class", cls.Description); var prop = cls.FindProperty("Id"); Assert.NotNull(prop); Assert.AreEqual("Id", prop.Name); Assert.AreEqual("ID Property", prop.Description); prop = cls.FindProperty("Image"); Assert.NotNull(prop); Assert.AreEqual("Image", prop.Name); Assert.AreEqual("Raster Property", prop.Description); Assert.AreEqual(item.ImageFormat, ritem.ImageFormat); Assert.AreEqual(item.IsTransparent, ritem.IsTransparent); Assert.AreEqual(item.BackgroundColor, ritem.BackgroundColor); Assert.AreEqual(item.Time, ritem.Time); Assert.AreEqual(item.ElevationDimension, ritem.ElevationDimension); Assert.AreEqual(item.SpatialContextName, ritem.SpatialContextName); Assert.AreEqual(5, item.Layers.Length); }
public void TestBidirectional() { FeatureSchema schema = new FeatureSchema("Default", "Default Schema"); ClassDefinition cls = new ClassDefinition("Class1", "Test Class"); cls.AddProperty(new DataPropertyDefinition("ID", "ID Property") { IsAutoGenerated = true, DataType = DataPropertyType.Int64, IsNullable = false, }, true); var prop = cls.FindProperty("ID") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(1, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.Int64, prop.DataType); Assert.IsTrue(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); cls.AddProperty(new DataPropertyDefinition("Name", "The name") { DataType = DataPropertyType.String, Length = 255 }); prop = cls.FindProperty("Name") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(2, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.String, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); cls.AddProperty(new DataPropertyDefinition("Date", "The date") { DataType = DataPropertyType.DateTime, IsNullable = true }); prop = cls.FindProperty("Date") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.DateTime, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsTrue(prop.IsNullable); schema.AddClass(cls); Assert.AreEqual(1, schema.Classes.Count); XmlDocument doc = new XmlDocument(); schema.WriteXml(doc, doc); string path = Path.GetTempFileName(); doc.Save(path); FeatureSourceDescription fsd = new FeatureSourceDescription(File.OpenRead(path)); Assert.AreEqual(1, fsd.Schemas.Length); schema = fsd.Schemas[0]; Assert.NotNull(schema); cls = schema.GetClass("Class1"); Assert.NotNull(cls); prop = cls.FindProperty("ID") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.Int64, prop.DataType); Assert.IsTrue(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); prop = cls.FindProperty("Name") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.String, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); prop = cls.FindProperty("Date") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.DateTime, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsTrue(prop.IsNullable); }
public void TestCreate() { var schema = new FeatureSchema("Default", "Default Schema"); Assert.AreEqual("Default", schema.Name); Assert.AreEqual("Default Schema", schema.Description); var cls = new ClassDefinition("Class1", "My Class"); Assert.AreEqual("Class1", cls.Name); Assert.AreEqual("My Class", cls.Description); Assert.IsTrue(string.IsNullOrEmpty(cls.DefaultGeometryPropertyName)); Assert.AreEqual(0, cls.Properties.Count); Assert.AreEqual(0, cls.IdentityProperties.Count); var prop = new DataPropertyDefinition("ID", "identity"); Assert.AreEqual("ID", prop.Name); Assert.AreEqual("identity", prop.Description); Assert.AreEqual(false, prop.IsAutoGenerated); Assert.AreEqual(false, prop.IsReadOnly); Assert.IsTrue(string.IsNullOrEmpty(prop.DefaultValue)); prop.DataType = DataPropertyType.Int32; Assert.AreEqual(DataPropertyType.Int32, prop.DataType); prop.IsAutoGenerated = true; Assert.IsTrue(prop.IsAutoGenerated); prop.IsReadOnly = true; Assert.IsTrue(prop.IsReadOnly); cls.AddProperty(prop, true); Assert.AreEqual(1, cls.Properties.Count); Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(cls, prop.Parent); Assert.NotNull(cls.FindProperty(prop.Name)); cls.RemoveProperty(prop); Assert.AreEqual(0, cls.Properties.Count); Assert.AreEqual(0, cls.Properties.Count); Assert.IsNull(prop.Parent); Assert.IsNull(cls.FindProperty(prop.Name)); cls.AddProperty(prop, true); Assert.AreEqual(1, cls.Properties.Count); Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(cls, prop.Parent); Assert.NotNull(cls.FindProperty(prop.Name)); cls.AddProperty(new DataPropertyDefinition("Name", "") { DataType = DataPropertyType.String, Length = 255, IsNullable = true }); Assert.AreEqual(2, cls.Properties.Count); Assert.AreEqual(1, cls.IdentityProperties.Count); cls.AddProperty(new GeometricPropertyDefinition("Geom", "") { HasMeasure = false, HasElevation = false, GeometricTypes = FeatureGeometricType.All, SpecificGeometryTypes = (SpecificGeometryType[])Enum.GetValues(typeof(SpecificGeometryType)) }); Assert.AreEqual(3, cls.Properties.Count); Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.IsTrue(string.IsNullOrEmpty(cls.DefaultGeometryPropertyName)); var geom = cls.FindProperty("Geom"); Assert.NotNull(geom); cls.DefaultGeometryPropertyName = geom.Name; Assert.IsNotNullOrEmpty(cls.DefaultGeometryPropertyName); schema.AddClass(cls); Assert.AreEqual(schema, cls.Parent); }
/// <summary> /// Creates a clone of the specified instance /// </summary> /// <param name="fs">The instance to clone</param> /// <returns></returns> public static FeatureSchema Clone(FeatureSchema fs) { var clone = new FeatureSchema(fs.Name, fs.Description); foreach (var cls in fs.Classes) { clone.AddClass(ClassDefinition.Clone(cls)); } return clone; }
protected void PopulateTestDataStore(IServerConnection conn, string fsId, ref FeatureSchema schema, ref ClassDefinition cls) { CreateTestDataStore(conn, fsId, ref schema, ref cls); IInsertFeatures insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature); insert.ClassName = cls.Name; insert.FeatureSourceId = fsId; var feat = new MutableRecord(); var reader = new FixedWKTReader(); //Initialize this record feat.PutValue("GEOM", new GeometryValue(reader.Read("POINT (0 0)"))); feat.PutValue("NAME", new StringValue("Test1")); //Attach to command. insert.RecordToInsert = feat; var res = insert.Execute(); feat.SetGeometry("GEOM", reader.Read("POINT (0 1)")); feat.SetString("NAME", "Test2"); res = insert.Execute(); feat.SetGeometry("GEOM", reader.Read("POINT (1 1)")); feat.SetString("NAME", "Test3"); res = insert.Execute(); feat.SetGeometry("GEOM", reader.Read("POINT (1 0)")); feat.SetString("NAME", "Test4"); res = insert.Execute(); }
protected void CreateTestDataStore(IServerConnection conn, string fsId, ref FeatureSchema schema, ref ClassDefinition cls) { schema = new FeatureSchema("Default", ""); cls = new ClassDefinition("Class1", ""); try { if (conn.ResourceService.ResourceExists(fsId)) conn.ResourceService.DeleteResource(fsId); cls.DefaultGeometryPropertyName = "GEOM"; cls.AddProperty(new DataPropertyDefinition("KEY", "") { DataType = DataPropertyType.Int32, IsAutoGenerated = true, IsReadOnly = true, IsNullable = false }, true); cls.AddProperty(new DataPropertyDefinition("NAME", "") { DataType = DataPropertyType.String, Length = 255, IsNullable = true, IsReadOnly = false }); cls.AddProperty(new GeometricPropertyDefinition("GEOM", "") { GeometricTypes = FeatureGeometricType.Point, SpatialContextAssociation = "Default" }); schema.AddClass(cls); ICreateDataStore create = (ICreateDataStore)conn.CreateCommand((int)CommandType.CreateDataStore); CoordinateSystemDefinitionBase coordSys = conn.CoordinateSystemCatalog.FindCoordSys("LL84"); create.FeatureSourceId = fsId; create.CoordinateSystemWkt = coordSys.WKT; create.Name = "Default"; create.ExtentType = OSGeo.MapGuide.ObjectModels.Common.FdoSpatialContextListSpatialContextExtentType.Dynamic; create.FileName = "Test.sdf"; create.Provider = "OSGeo.SDF"; create.Schema = schema; create.XYTolerance = 0.001; create.ZTolerance = 0.001; create.Execute(); } catch { schema = null; cls = null; throw; } }