Example #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"));
        }
Example #2
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);
        }