示例#1
0
        public void DescribeSHPSchema()
        {
            IConnectionManager connMgr = FdoFeatureAccessManager.GetConnectionManager();
            FdoIConnection     conn    = connMgr.CreateConnection("OSGeo.SHP");

            conn.ConnectionString = "DefaultFileLocation=" + TestDataStore.SHP;
            Assert.Equal(FdoConnectionState.FdoConnectionState_Open, conn.Open());

            FdoIDescribeSchema desc = conn.CreateCommand((int)FdoCommandType.FdoCommandType_DescribeSchema) as FdoIDescribeSchema;

            Assert.NotNull(desc);
            FdoFeatureSchemaCollection schemas = desc.Execute();

            Assert.Equal(1, schemas.Count);

            FdoFeatureSchema   schema  = schemas.GetItem(0);
            FdoClassCollection classes = schema.GetClasses();

            Assert.Equal(1, classes.Count);

            FdoClassDefinition clsDef = classes.GetItem(0);

            VerifyClass(clsDef);

            //Re-test with sugar
            clsDef = schemas.GetClassDefinition(schema.Name, "World_Countries");
            Assert.NotNull(clsDef);
            VerifyClass(clsDef);
            clsDef = schemas.GetClassDefinition(null, "World_Countries");
            Assert.NotNull(clsDef);
            VerifyClass(clsDef);
            Assert.Throws <ManagedFdoException>(() => schemas.GetClassDefinition(null, "WorldCountries"));
            Assert.Throws <ManagedFdoException>(() => schemas.GetClassDefinition("BogusSchema", "World_Countries"));
        }
示例#2
0
        private static void VerifyClass(FdoClassDefinition clsDef)
        {
            Assert.Equal(FdoClassType.FdoClassType_FeatureClass, clsDef.ClassType);
            Assert.IsAssignableFrom <FdoFeatureClass>(clsDef);
            FdoFeatureClass featCls = (FdoFeatureClass)clsDef;

            FdoPropertyDefinitionCollection clsProps = clsDef.GetProperties();

            Assert.Equal(5, clsProps.Count);

            FdoDataPropertyDefinitionCollection clsIdProps = clsDef.GetIdentityProperties();

            Assert.Equal(1, clsIdProps.Count);

            FdoGeometricPropertyDefinition geomProp = featCls.GetGeometryProperty();

            Assert.NotNull(geomProp);

            Assert.True(clsProps.IndexOf("NAME") >= 0);
            Assert.True(clsProps.IndexOf("KEY") >= 0);
            Assert.True(clsProps.IndexOf("MAPKEY") >= 0);
            Assert.True(clsProps.IndexOf(geomProp) >= 0);

            var name   = clsProps.GetItem("NAME");
            var key    = clsProps.GetItem("KEY");
            var mapkey = clsProps.GetItem("MAPKEY");

            Assert.IsAssignableFrom <FdoDataPropertyDefinition>(name);
            Assert.IsAssignableFrom <FdoDataPropertyDefinition>(key);
            Assert.IsAssignableFrom <FdoDataPropertyDefinition>(mapkey);
        }
示例#3
0
        private void DoFilteredSpatialExtents(FdoIConnection conn)
        {
            FdoIDescribeSchema desc = conn.CreateCommand((int)FdoCommandType.FdoCommandType_DescribeSchema) as FdoIDescribeSchema;

            Assert.NotNull(desc);
            FdoFeatureSchemaCollection schemas = desc.Execute();

            Assert.NotNull(schemas);
            Assert.Equal(1, schemas.Count);
            FdoFeatureSchema   schema   = schemas.GetItem(0);
            FdoClassCollection classes  = schema.GetClasses();
            string             geomName = null;

            for (int i = 0; i < classes.Count; i++)
            {
                FdoClassDefinition cls = classes.GetItem(i);
                if (cls.Name == "World_Countries")
                {
                    Assert.IsAssignableFrom <FdoFeatureClass>(cls);
                    FdoGeometricPropertyDefinition geomProp = ((FdoFeatureClass)cls).GetGeometryProperty();
                    Assert.NotNull(geomProp);
                    geomName = geomProp.Name;
                }
            }
            Assert.NotNull(geomName);

            FdoISelectAggregates selectCmd = conn.CreateCommand((int)FdoCommandType.FdoCommandType_SelectAggregates) as FdoISelectAggregates;

            Assert.NotNull(selectCmd);
            selectCmd.SetFeatureClassName("World_Countries");
            selectCmd.SetFilter("NAME = 'Canada'");

            FdoIdentifierCollection propNames  = selectCmd.GetPropertyNames();
            FdoExpression           countExpr  = FdoExpression.Parse("SpatialExtents(" + geomName + ")");
            FdoComputedIdentifier   countIdent = FdoComputedIdentifier.Create("EXTENTS", countExpr);

            propNames.Add(countIdent);

            FdoIDataReader        rdr         = selectCmd.Execute();
            FdoFgfGeometryFactory geomFactory = FdoFgfGeometryFactory.GetInstance();
            int iterations = 0;

            while (rdr.ReadNext())
            {
                Assert.False(rdr.IsNull("EXTENTS"));
                Assert.Equal(FdoPropertyType.FdoPropertyType_GeometricProperty, rdr.GetPropertyType("EXTENTS"));

                FdoByteArrayHandle bytes = rdr.GetGeometryBytes("EXTENTS");
                Assert.NotNull(bytes);
                FdoIGeometry geom = geomFactory.CreateGeometryFromFgf(bytes);
                Assert.NotNull(geom);
                string wkt = geom.Text;
                Assert.NotNull(wkt);
                System.Diagnostics.Debug.WriteLine(string.Format("SpatialExtents() - {0}", wkt));
                iterations++;
            }
            rdr.Close();
            Assert.Equal(1, iterations);

            //Re-test with sugar methods
            propNames.Clear();
            Assert.Equal(0, propNames.Count);
            propNames.AddComputedIdentifier("EXTENTS", "SpatialExtents(" + geomName + ")");
            Assert.Equal(1, propNames.Count);

            rdr        = selectCmd.Execute();
            iterations = 0;
            while (rdr.ReadNext())
            {
                Assert.False(rdr.IsNull("EXTENTS"));
                Assert.Equal(FdoPropertyType.FdoPropertyType_GeometricProperty, rdr.GetPropertyType("EXTENTS"));

                FdoByteArrayHandle bytes = rdr.GetGeometryBytes("EXTENTS");
                Assert.NotNull(bytes);
                FdoIGeometry geom = geomFactory.CreateGeometryFromFgf(bytes);
                Assert.NotNull(geom);
                string wkt = geom.Text;
                Assert.NotNull(wkt);
                System.Diagnostics.Debug.WriteLine(string.Format("SpatialExtents() - {0}", wkt));
                iterations++;
            }
            rdr.Close();
            Assert.Equal(1, iterations);
        }
示例#4
0
        private static void VerifyClass(FdoClassDefinition clsDef)
        {
            Assert.Equal(FdoClassType.FdoClassType_FeatureClass, clsDef.ClassType);
            Assert.IsAssignableFrom<FdoFeatureClass>(clsDef);
            FdoFeatureClass featCls = (FdoFeatureClass)clsDef;

            FdoPropertyDefinitionCollection clsProps = clsDef.GetProperties();
            Assert.Equal(5, clsProps.Count);

            FdoDataPropertyDefinitionCollection clsIdProps = clsDef.GetIdentityProperties();
            Assert.Equal(1, clsIdProps.Count);

            FdoGeometricPropertyDefinition geomProp = featCls.GetGeometryProperty();
            Assert.NotNull(geomProp);

            Assert.True(clsProps.IndexOf("NAME") >= 0);
            Assert.True(clsProps.IndexOf("KEY") >= 0);
            Assert.True(clsProps.IndexOf("MAPKEY") >= 0);
            Assert.True(clsProps.IndexOf(geomProp) >= 0);

            var name = clsProps.GetItem("NAME");
            var key = clsProps.GetItem("KEY");
            var mapkey = clsProps.GetItem("MAPKEY");

            Assert.IsAssignableFrom<FdoDataPropertyDefinition>(name);
            Assert.IsAssignableFrom<FdoDataPropertyDefinition>(key);
            Assert.IsAssignableFrom<FdoDataPropertyDefinition>(mapkey);
        }