Exemplo n.º 1
0
        public void CanCreateQueryLayerFeatureClassForUnegisteredStGeometryTable()
        {
            IWorkspace workspace = TestUtils.OpenDDxWorkspaceOracle();

            const string periFclass = "UNITTEST_MANAGER.TOPDD_WFL_REVISIONPERI_POLY";
            const string rpView     = "UNITTEST_MANAGER.V_TOPDD_WFL_REVISIONPERIMETER";
            string       periFK     = string.Format("{0}.PERIMETER_OID", rpView);
            string       periPK     = "OBJECTID";

            string tables = string.Format("{0}, {1}", periFclass, rpView);

            string joinExpression = string.Format("{0} = {1}", periFK, periPK);

            string sql = $"SELECT * FROM {tables} WHERE {joinExpression}";

            string queryClassName =
                DatasetUtils.GetQueryLayerClassName((IFeatureWorkspace)workspace,
                                                    "TEST_CLASS");

            // Unqualified Name must start with %, and it is owned by the current user:
            Assert.AreEqual("UNITTEST.%TEST_CLASS", queryClassName);

            double xyTolerance = 0.01;

            IFeatureClass fclass = (IFeatureClass)
                                   DatasetUtils.CreateQueryLayerClass((ISqlWorkspace)workspace, sql, queryClassName,
                                                                      periPK, xyTolerance);

            var filter = new SpatialFilterClass
            {
                Geometry =
                    GeometryFactory.CreateEnvelope(2600000, 1200000, 2700000, 1300000),
                SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
            };

            IFeatureCursor cursor = fclass.Search(filter, true);

            Assert.NotNull(cursor.NextFeature());
            Marshal.ReleaseComObject(cursor);

            int countInBox = GdbQueryUtils.Count(fclass, filter.Geometry);
            int countAll   = GdbQueryUtils.Count(fclass);

            Assert.AreEqual(78, countInBox);
            Assert.AreEqual(260, countAll);

            Assert.AreEqual(countInBox, fclass.FeatureCount(filter));
            Assert.AreEqual(countAll, fclass.FeatureCount(null));

            // solution found elsewhere: only spatial queries work, need to pass spatial filter with geometry
            IFeatureCursor cursorWithNullFilter = fclass.Search(null, true);

            IFeature feature = cursorWithNullFilter.NextFeature();

            Assert.NotNull(feature);
            Assert.AreEqual(xyTolerance, GeometryUtils.GetXyTolerance(feature.Shape));

            Marshal.ReleaseComObject(cursorWithNullFilter);
        }
Exemplo n.º 2
0
        public void CanCreateGdbFeatureClass()
        {
            // An in-memory backing dataset is created automatically, if no factory method is provided
            GdbFeatureClass gdbFeatureClass =
                new GdbFeatureClass(41, "TESTABLE", esriGeometryType.esriGeometryPoint,
                                    "Test table");

            IFeatureClass featureClass = gdbFeatureClass;

            Assert.AreEqual(41, featureClass.ObjectClassID);
            Assert.AreEqual("TESTABLE", DatasetUtils.GetName(featureClass));
            Assert.AreEqual("Test table",
                            DatasetUtils.GetAliasName(featureClass));
            Assert.AreEqual(esriGeometryType.esriGeometryPoint,
                            featureClass.ShapeType);

            Assert.False(featureClass.HasOID);
            Assert.Null(featureClass.OIDFieldName);

            Assert.AreEqual(0, GdbQueryUtils.Count(featureClass, ""));

            // Add OID field
            gdbFeatureClass.AddField(FieldUtils.CreateOIDField());

            // Add Shape field
            gdbFeatureClass.AddField(
                FieldUtils.CreateShapeField(
                    esriGeometryType.esriGeometryPoint,
                    SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95)));

            Assert.True(featureClass.HasOID);
            Assert.AreEqual("OBJECTID", featureClass.OIDFieldName);
            Assert.AreEqual("SHAPE", featureClass.ShapeFieldName);

            IQueryFilter queryFilter = GdbQueryUtils.CreateQueryFilter("OBJECTID");

            queryFilter.WhereClause = "OBJECTID < 0";

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(featureClass, queryFilter));

            var backingDataset = gdbFeatureClass.BackingDataset as InMemoryDataset;

            Assert.NotNull(backingDataset);

            backingDataset.AllRows.Add(new GdbRow(1, gdbFeatureClass));

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(featureClass, queryFilter));

            queryFilter.WhereClause = "OBJECTID > 0";

            Assert.AreEqual(1,
                            GdbQueryUtils.Count(featureClass, queryFilter));
        }
Exemplo n.º 3
0
        public void CanCreateGdbTable()
        {
            // An in-memory backing dataset is created automatically, if no factory method is provided
            GdbTable gdbTable = new GdbTable(41, "TESTABLE", "Test table");

            IObjectClass objectClass = gdbTable;

            Assert.AreEqual(41, objectClass.ObjectClassID);
            Assert.AreEqual("TESTABLE", DatasetUtils.GetName(objectClass));
            Assert.AreEqual("Test table", DatasetUtils.GetAliasName(objectClass));

            Assert.False(objectClass.HasOID);
            Assert.Null(objectClass.OIDFieldName);

            Assert.AreEqual(0, GdbQueryUtils.Count(objectClass, ""));

            // Add OID field
            gdbTable.AddField(FieldUtils.CreateOIDField());

            Assert.True(objectClass.HasOID);
            Assert.AreEqual("OBJECTID", objectClass.OIDFieldName);

            IQueryFilter queryFilter = GdbQueryUtils.CreateQueryFilter("OBJECTID");

            queryFilter.WhereClause = "OBJECTID < 0";

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(objectClass, queryFilter));

            var backingDataset = gdbTable.BackingDataset as InMemoryDataset;

            Assert.NotNull(backingDataset);

            backingDataset.AllRows.Add(new GdbRow(1, gdbTable));

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(objectClass, queryFilter));

            queryFilter.WhereClause = "OBJECTID > 0";

            Assert.AreEqual(1,
                            GdbQueryUtils.Count(objectClass, queryFilter));
        }
Exemplo n.º 4
0
        public void CanCreateGdbFeatureClassWithBackingDataset()
        {
            IWorkspace ws = TestUtils.OpenUserWorkspaceOracle();

            const string tlmStrasse = "TOPGIS_TLM.TLM_STRASSE";

            IFeatureClass realFeatureClass = DatasetUtils.OpenFeatureClass(ws, tlmStrasse);

            var rowCache = GdbQueryUtils.GetRows((ITable)realFeatureClass, false)
                           .Take(100)
                           .ToList();

            Assert.AreEqual(100, rowCache.Count);

            GdbTable tableWithBackingData =
                new GdbFeatureClass(41, "TESTABLE", esriGeometryType.esriGeometryPoint,
                                    "Test table",
                                    table => new InMemoryDataset(table, rowCache));

            IFeatureClass featureClassWithBackingData = (IFeatureClass)tableWithBackingData;

            Assert.AreEqual(41, featureClassWithBackingData.ObjectClassID);
            Assert.AreEqual("TESTABLE", DatasetUtils.GetName(featureClassWithBackingData));
            Assert.AreEqual("Test table",
                            DatasetUtils.GetAliasName(featureClassWithBackingData));
            Assert.AreEqual(esriGeometryType.esriGeometryPoint,
                            featureClassWithBackingData.ShapeType);

            Assert.False(featureClassWithBackingData.HasOID);
            Assert.Null(featureClassWithBackingData.OIDFieldName);

            for (int i = 0; i < realFeatureClass.Fields.FieldCount; i++)
            {
                featureClassWithBackingData.AddField(realFeatureClass.Fields.Field[i]);
            }

            Assert.AreEqual("OBJECTID", featureClassWithBackingData.OIDFieldName);
            Assert.AreEqual("SHAPE", featureClassWithBackingData.ShapeFieldName);

            Assert.AreEqual(100, GdbQueryUtils.Count(featureClassWithBackingData, ""));

            IQueryFilter queryFilter = GdbQueryUtils.CreateQueryFilter("OBJECTID");

            queryFilter.WhereClause = "OBJECTID < 0";

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(featureClassWithBackingData, queryFilter));

            var backingDataset = tableWithBackingData.BackingDataset as InMemoryDataset;

            Assert.NotNull(backingDataset);

            backingDataset.AllRows.Add(new GdbRow(1, tableWithBackingData));

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(featureClassWithBackingData, queryFilter));

            queryFilter.WhereClause = "OBJECTID >= 0";

            Assert.AreEqual(101,
                            GdbQueryUtils.Count(featureClassWithBackingData, queryFilter));
        }
Exemplo n.º 5
0
        public void CanQueryDateField()
        {
            const string featureClassName = "points";
            const string fieldName        = "date";
            var          equalDateTime    = new DateTime(2012, 03, 22, 12, 00, 00);
            var          greaterDateTime  = new DateTime(2012, 03, 22, 12, 00, 01);
            var          lowerDateTime    = new DateTime(2012, 03, 22, 11, 59, 59);

            IFeatureWorkspace workspace =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetFileGdb93Path());
            IFeatureClass fc = DatasetUtils.OpenFeatureClass(workspace,
                                                             featureClassName);
            int    fieldIndex = fc.Fields.FindField(fieldName);
            IField dateField  = fc.Fields.get_Field(fieldIndex);

            Assert.True(dateField.Type == esriFieldType.esriFieldTypeDate,
                        "Wrong FieldType in test data");

            IList <IFeature> rows = GdbQueryUtils.FindList(fc, "OBJECTID = 1");

            Assert.True(rows.Count == 1, "Expected object not in test data");

            DateTime dateTime = Convert.ToDateTime(rows[0].get_Value(fieldIndex));

            _msg.InfoFormat(@"Testing with dateTime: {0}", dateTime);

            Assert.True(dateTime == equalDateTime, "Expected DateTime = DateTime failed.");
            Assert.True(dateTime <= greaterDateTime, "Expected DateTime <= DateTime failed.");
            Assert.True(dateTime < greaterDateTime, "Expected DateTime < DateTime failed.");
            Assert.True(dateTime >= lowerDateTime, "Expected DateTime >= DateTime failed.");
            Assert.True(dateTime > lowerDateTime, "Expected DateTime > DateTime failed.");

            //Test query logic for date field
            const string equals          = "=";
            const string lowerOrEquals   = "<=";
            const string lower           = "<";
            const string greaterOrEquals = ">=";
            const string greater         = ">";

            string where = string.Format("{0} {1} {2}", fieldName, equals,
                                         GdbSqlUtils.GetFGDBDateLiteral(equalDateTime));
            Assert.True(GdbQueryUtils.Count(fc, where) == 1, "Query '{0}' fails.", equals);

            where = string.Format("{0} {1} {2}", fieldName, lowerOrEquals,
                                  GdbSqlUtils.GetFGDBDateLiteral(greaterDateTime));
            Assert.True(GdbQueryUtils.Count(fc, where) == 1, "Query '{0}' fails.",
                        lowerOrEquals);

            where = string.Format("{0} {1} {2}", fieldName, lower,
                                  GdbSqlUtils.GetFGDBDateLiteral(greaterDateTime));
            Assert.True(GdbQueryUtils.Count(fc, where) == 1, "Query '{0}' fails.", lower);

            where = string.Format("{0} {1} {2}", fieldName, greaterOrEquals,
                                  GdbSqlUtils.GetFGDBDateLiteral(lowerDateTime));
            Assert.True(GdbQueryUtils.Count(fc, where) == 1, "Query '{0}' fails.",
                        greaterOrEquals);

            where = string.Format("{0} {1} {2}", fieldName, greater,
                                  GdbSqlUtils.GetFGDBDateLiteral(lowerDateTime));
            Assert.True(GdbQueryUtils.Count(fc, where) == 1, "Query '{0}' fails.", greater);
        }