Exemple #1
0
        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);
                    }
                }
            }
        }
Exemple #2
0
        public void TestMySqlSchema()
        {
            var fds = new FeatureSourceDescription(Utils.OpenFile("UserTestData\\gen_default1_MySql_master.xml"));

            Assert.AreEqual(1, fds.Schemas.Length);

            var fs = fds.GetSchema("AutoGen");

            Assert.IsNotNull(fs);

            Assert.AreEqual(12, fs.Classes.Count);

            var c1  = fds.GetClass("AutoGen:rtable1");
            var c2  = fds.GetClass("AutoGen:rtable2");
            var c3  = fds.GetClass("AutoGen:rtable5");
            var c4  = fds.GetClass("AutoGen:rtable6");
            var c5  = fds.GetClass("AutoGen:rtable7");
            var c6  = fds.GetClass("AutoGen:table1");
            var c7  = fds.GetClass("AutoGen:table3");
            var c8  = fds.GetClass("AutoGen:table4");
            var c9  = fds.GetClass("AutoGen:table5");
            var c10 = fds.GetClass("AutoGen:table6");
            var c11 = fds.GetClass("AutoGen:table7");
            var c12 = fds.GetClass("AutoGen:view1");

            Assert.NotNull(c1);
            Assert.NotNull(c2);
            Assert.NotNull(c3);
            Assert.NotNull(c4);
            Assert.NotNull(c5);
            Assert.NotNull(c6);
            Assert.NotNull(c7);
            Assert.NotNull(c8);
            Assert.NotNull(c9);
            Assert.NotNull(c10);
            Assert.NotNull(c11);
            Assert.NotNull(c12);

            Assert.AreEqual(1, c1.IdentityProperties.Count);
            Assert.AreEqual(1, c2.IdentityProperties.Count);
            Assert.AreEqual(1, c3.IdentityProperties.Count);
            Assert.AreEqual(1, c4.IdentityProperties.Count);
            Assert.AreEqual(1, c5.IdentityProperties.Count);
            Assert.AreEqual(1, c6.IdentityProperties.Count);
            Assert.AreEqual(2, c7.IdentityProperties.Count);
            Assert.AreEqual(1, c8.IdentityProperties.Count);
            Assert.AreEqual(1, c9.IdentityProperties.Count);
            Assert.AreEqual(2, c10.IdentityProperties.Count);
            Assert.AreEqual(1, c11.IdentityProperties.Count);
            Assert.AreEqual(0, c12.IdentityProperties.Count);

            Assert.AreEqual(c1.Properties.Count, 3);
            Assert.AreEqual(c2.Properties.Count, 5);
            Assert.AreEqual(c3.Properties.Count, 3);
            Assert.AreEqual(c4.Properties.Count, 4);
            Assert.AreEqual(c5.Properties.Count, 3);
            Assert.AreEqual(c6.Properties.Count, 47);
            Assert.AreEqual(c7.Properties.Count, 3);
            Assert.AreEqual(c8.Properties.Count, 4);
            Assert.AreEqual(c9.Properties.Count, 2);
            Assert.AreEqual(c10.Properties.Count, 3);
            Assert.AreEqual(c11.Properties.Count, 2);
            Assert.AreEqual(c12.Properties.Count, 3);

            Assert.AreEqual(c1, fds.GetClass("AutoGen", "rtable1"));
            Assert.AreEqual(c2, fds.GetClass("AutoGen", "rtable2"));
            Assert.AreEqual(c3, fds.GetClass("AutoGen", "rtable5"));
            Assert.AreEqual(c4, fds.GetClass("AutoGen", "rtable6"));
            Assert.AreEqual(c5, fds.GetClass("AutoGen", "rtable7"));
            Assert.AreEqual(c6, fds.GetClass("AutoGen", "table1"));
            Assert.AreEqual(c7, fds.GetClass("AutoGen", "table3"));
            Assert.AreEqual(c8, fds.GetClass("AutoGen", "table4"));
            Assert.AreEqual(c9, fds.GetClass("AutoGen", "table5"));
            Assert.AreEqual(c10, fds.GetClass("AutoGen", "table6"));
            Assert.AreEqual(c11, fds.GetClass("AutoGen", "table7"));
            Assert.AreEqual(c12, fds.GetClass("AutoGen", "view1"));

            Assert.IsTrue(string.IsNullOrEmpty(c1.DefaultGeometryPropertyName));
            Assert.IsTrue(string.IsNullOrEmpty(c2.DefaultGeometryPropertyName));
            Assert.IsTrue(string.IsNullOrEmpty(c3.DefaultGeometryPropertyName));
            Assert.IsTrue(string.IsNullOrEmpty(c4.DefaultGeometryPropertyName));
            Assert.IsTrue(string.IsNullOrEmpty(c5.DefaultGeometryPropertyName));
            //Though this feature class has geometries, the XML schema says none
            //are designated
            Assert.IsTrue(string.IsNullOrEmpty(c6.DefaultGeometryPropertyName));
            Assert.IsTrue(string.IsNullOrEmpty(c7.DefaultGeometryPropertyName));
            Assert.IsFalse(string.IsNullOrEmpty(c8.DefaultGeometryPropertyName));
            Assert.IsTrue(string.IsNullOrEmpty(c9.DefaultGeometryPropertyName));
            Assert.IsTrue(string.IsNullOrEmpty(c10.DefaultGeometryPropertyName));
            Assert.IsTrue(string.IsNullOrEmpty(c11.DefaultGeometryPropertyName));
            Assert.IsTrue(string.IsNullOrEmpty(c12.DefaultGeometryPropertyName));
        }