Ejemplo n.º 1
0
        public void CanSortByStringField()
        {
            IFeatureWorkspace featureWs =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath());

            ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL");

            const string operatorFieldName = "OPERATEUR";
            ICursor      cursor            = TableSortUtils.GetSortedTableCursor(table, operatorFieldName);

            int fieldIndex = cursor.FindField(operatorFieldName);

            Assert.True(fieldIndex >= 0, "Field not found");

            string lastValue = null;
            IRow   row;

            while ((row = cursor.NextRow()) != null)
            {
                object value = row.get_Value(fieldIndex);

                Assert.False(value == DBNull.Value, "Empty field");

                var currentValue = (string)value;
                Console.WriteLine(currentValue);

                if (lastValue != null)
                {
                    Assert.False(currentValue.CompareTo(lastValue) < 0, "Not sorted");
                }

                lastValue = currentValue;
            }
        }
Ejemplo n.º 2
0
        public void CanCreateSpatialFilterWithNonZSimpleGeometry()
        {
            IFeatureWorkspace ws = OpenTestWorkspace();
            IFeatureClass     fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE");

            IEnvelope nonZSimpleEnvelope = GeometryFactory.CreateEnvelope(2600000, 1200000,
                                                                          2700000, 1300000);

            GeometryUtils.MakeZAware(nonZSimpleEnvelope);

            Assert.False(((IZAware)nonZSimpleEnvelope).ZSimple, "Must be non-Z-simple");

            ISpatialReference spatialReference =
                Assert.NotNull(DatasetUtils.GetSpatialReference(fc));

            IGeometry validGeometry;
            string    message;

            Assert.False(GdbQueryUtils.IsValidFilterGeometry(
                             nonZSimpleEnvelope,
                             SpatialReferenceUtils.GetXyResolution(spatialReference),
                             out validGeometry, out message),
                         "Search geometry should not be valid");

            Assert.NotNull(validGeometry);

            IQueryFilter filter = GdbQueryUtils.CreateSpatialFilter(fc, nonZSimpleEnvelope);

            Assert.True(GdbQueryUtils.GetFeatures(fc, filter, true).Any(), "No features found");
        }
Ejemplo n.º 3
0
        public void Learning_CanFindFeaturesWithNonZSimpleSearchGeometry()
        {
            // 10.2.1: Test fails (correct) with COM Exception on OpenCursor
            // 10.4.1: Test fails (correct) with COM Exception on OpenCursor
            // 10.6.1: Test passes (incorrectly!), no features found

            IFeatureWorkspace ws = OpenTestWorkspace();
            IFeatureClass     fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE");

            IEnvelope nonZSimpleEnvelope = GeometryFactory.CreateEnvelope(2600000, 1200000,
                                                                          2700000, 1300000);

            GeometryUtils.MakeZAware(nonZSimpleEnvelope);

            Assert.False(((IZAware)nonZSimpleEnvelope).ZSimple, "Must be non-Z-simple");

            ISpatialReference spatialReference = DatasetUtils.GetSpatialReference(fc);

            nonZSimpleEnvelope.SpatialReference = spatialReference;

            ISpatialFilter spatialFilter = new SpatialFilterClass();

            spatialFilter.GeometryField = fc.ShapeFieldName;
            spatialFilter.set_GeometryEx(nonZSimpleEnvelope, true);
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            Assert.AreEqual(0, GdbQueryUtils.GetFeatures(fc, spatialFilter, true).Count(),
                            "Behaviour changed: Now features are found even with non-Z-simple search geometry.");
        }
Ejemplo n.º 4
0
        public void TableSortGuidFileGdb()
        {
            IFeatureWorkspace featureWs =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath());
            //IFeatureWorkspace featureWs = OpenTestWorkspace();

            ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL");

            ITableSort tableSort = new TableSortClass();

            tableSort.Table  = table;
            tableSort.Fields = "UUID";

            tableSort.Sort(null);

            ICursor cursor = tableSort.Rows;

            IRow row;
            Guid lastValue = Guid.Empty;

            while ((row = cursor.NextRow()) != null)
            {
                object value = row.get_Value(1);

                Assert.False(value == DBNull.Value, "Empty UUID field");

                var         currentGuid  = new Guid((string)value);
                IComparable currentValue = currentGuid;

                Console.WriteLine(currentValue);

                if (lastValue != Guid.Empty)
                {
                    // ITableSort on a GUID field in a file GDB does not sort the byte array or at least not in an obvious way
                    byte[] currentGuidAsByteArray = currentGuid.ToByteArray();
                    byte[] lastGuidAsByteArray    = lastValue.ToByteArray();
                    int    byteArrayCompare       = ByteArrayCompare(currentGuidAsByteArray,
                                                                     lastGuidAsByteArray);
                    //Assert.True(byteArrayCompare > 0, "Different compare algorithm from byte array");

                    // ITableSort on a GUID field in a file GDB does not sort the same way as SqlGuid in .NET (i.e. SQL Server sorting)
                    var sqlGuid        = new SqlGuid(currentGuid);
                    int sqlGuidCompare = sqlGuid.CompareTo(new SqlGuid(lastValue));
                    //Assert.True(sqlGuidCompare < 0, "Different compare algorithm from sql server");

                    // ITableSort on a GUID field in a file GDB does not sort the same way as Guid in .NET
                    IComparable comparableGuid = lastValue;
                    int         guidCompare    = comparableGuid.CompareTo(currentValue);
                    //Assert.True(guidCompare < 0, "Different compare algorithm from .Net.");
                }

                lastValue = currentGuid;
            }
        }
Ejemplo n.º 5
0
        public void CanCreateSpatialFilterWithSubResolutionEnvelope()
        {
            IFeatureWorkspace ws = OpenTestWorkspace();
            IFeatureClass     fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE");

            IEnvelope subResolutionEnv = GeometryFactory.CreateEnvelope(2600000, 1200000,
                                                                        2600000.0001,
                                                                        1200000.0001);

            ISpatialReference spatialReference = DatasetUtils.GetSpatialReference(fc);

            subResolutionEnv.SpatialReference = spatialReference;

            double xyResolution =
                SpatialReferenceUtils.GetXyResolution(Assert.NotNull(spatialReference));

            IGeometry validGeometry;
            string    message;

            Assert.False(GdbQueryUtils.IsValidFilterGeometry(
                             subResolutionEnv, xyResolution, out validGeometry, out message),
                         "Sub-resolution polygon should not be valid");
            Assert.NotNull(validGeometry);
            Assert.False(subResolutionEnv == validGeometry,
                         "Corrected geometry must be different to input");

            Assert.True(GdbQueryUtils.IsValidFilterGeometry(
                            validGeometry, xyResolution, out validGeometry, out message),
                        "Corrected geometry should be valid");

            IQueryFilter filter = GdbQueryUtils.CreateSpatialFilter(
                fc, subResolutionEnv, esriSpatialRelEnum.esriSpatialRelIntersects, false,
                spatialReference);

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

            Marshal.ReleaseComObject(cursor);

            IEnvelope linearEnv = GeometryFactory.CreateEnvelope(2600000, 1200000,
                                                                 2600000.0001, 1201010);

            linearEnv.SpatialReference = ((IGeoDataset)fc).SpatialReference;

            filter = GdbQueryUtils.CreateSpatialFilter(
                fc, linearEnv, esriSpatialRelEnum.esriSpatialRelIntersects, true,
                null);

            cursor = fc.Search(filter, true);

            Marshal.ReleaseComObject(cursor);
        }
Ejemplo n.º 6
0
        public void CanCreateSpatialFilterWithEmptyPolygon()
        {
            IFeatureWorkspace ws = OpenTestWorkspace();
            IFeatureClass     fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE");

            IPolygon emptyPoly = new PolygonClass();

            emptyPoly.SpatialReference = ((IGeoDataset)fc).SpatialReference;

            IGeometry validGeometry;
            string    message;

            Assert.False(GdbQueryUtils.IsValidFilterGeometry(
                             emptyPoly, 0.001, out validGeometry, out message),
                         "Empty polygon should not be valid");

            Assert.Null(validGeometry);

            if (RuntimeUtils.Is10_4orHigher)
            {
                NUnit.Framework.Assert.Catch <Exception>(
                    () => GdbQueryUtils.CreateSpatialFilter(fc, emptyPoly));
            }

            ISpatialFilter spatialFilter = new SpatialFilterClass();

            spatialFilter.GeometryField = fc.ShapeFieldName;
            spatialFilter.set_GeometryEx(emptyPoly, true);
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            IFeatureCursor cursor = null;

            if (RuntimeUtils.Is10_1 || RuntimeUtils.Is10_2 || RuntimeUtils.Is10_3 ||
                RuntimeUtils.Is10_4orHigher)
            {
                NUnit.Framework.Assert.Throws <NullReferenceException>(
                    () => cursor = fc.Search(spatialFilter, true));
            }
            else
            {
                cursor = fc.Search(spatialFilter, true);
            }

            if (cursor != null)
            {
                Marshal.ReleaseComObject(cursor);
            }
        }
Ejemplo n.º 7
0
        private static void LoopAndWrite(ICursor cursor, string uuidFieldName)
        {
            int fieldIndex = cursor.FindField(uuidFieldName);

            Assert.True(fieldIndex >= 0, "Field not found");

            IRow row;

            while ((row = cursor.NextRow()) != null)
            {
                object value = row.get_Value(fieldIndex);

                Assert.False(value == DBNull.Value, "Empty UUID field");

                var         currentGuid  = new Guid((string)value);
                IComparable currentValue = currentGuid;                 // value as IComparable; // currentGuid;

                Console.WriteLine(currentValue);
            }
        }
Ejemplo n.º 8
0
        public void OrderByGuidFileGdb()
        {
            IFeatureWorkspace featureWs =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath());
            ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL");

            IQueryFilter queryFilter = new QueryFilterClass();

            var queryFilterDef = (IQueryFilterDefinition)queryFilter;

            queryFilterDef.PostfixClause = "ORDER BY UUID";

            foreach (IRow row in GdbQueryUtils.GetRows(table, queryFilter, true))
            {
                object value = row.get_Value(1);

                Assert.False(value == DBNull.Value, "Empty UUID field");

                var currentGuid = new Guid((string)value);

                Console.WriteLine(currentGuid);
            }
        }
Ejemplo n.º 9
0
        public void CanSortOnFgdbGuids()
        {
            IFeatureWorkspace featureWs =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath());
            //IFeatureWorkspace featureWs = OpenTestWorkspace();

            ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL");
            //ITable table = DatasetUtils.OpenTable(featureWs, "TOPGIS_TLM.TLM_NUTZUNGSAREAL");

            const string uuidFieldName = "UUID";

            ICursor cursor = TableSortUtils.GetGuidFieldSortedCursor(table, uuidFieldName);

            int fieldIndex = cursor.FindField(uuidFieldName);

            Assert.True(fieldIndex >= 0, "Field not found");

            Guid lastGuid = Guid.Empty;
            IRow row;

            while ((row = cursor.NextRow()) != null)
            {
                object value = row.get_Value(fieldIndex);

                Assert.False(value == DBNull.Value, "Empty UUID field");

                var currentGuid = new Guid((string)value);
                Console.WriteLine(currentGuid);

                if (lastGuid != Guid.Empty)
                {
                    Assert.False(currentGuid.CompareTo(lastGuid) < 0, "Not sorted");
                }

                lastGuid = currentGuid;
            }
        }