Exemplo n.º 1
0
        public void CanThrowNotNull()
        {
            const object dummy = null;

            NUnit.Framework.Assert.Throws <AssertionException>(
                () => Assert.NotNull(dummy));
        }
Exemplo n.º 2
0
        public void CanThrowNotNullMsg()
        {
            const object dummy = null;

            NUnit.Framework.Assert.Throws <AssertionException>(
                () => Assert.NotNull(dummy, "{0} {1}", "arg1", "arg"));
        }
Exemplo n.º 3
0
        public void CanThrowNotNullForNullable()
        {
            int?dummy = null;

            NUnit.Framework.Assert.Throws <AssertionException>(
                () => Assert.NotNull(dummy));
        }
Exemplo n.º 4
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");
        }
Exemplo n.º 5
0
        public void CanGetExistingRowsFastEnough()
        {
            IFeatureWorkspace ws = OpenTestWorkspace();
            ITable            fc = ws.OpenTable("TOPGIS_TLM.TLM_WANDERWEG");

            const int max = 100;
            IDictionary <int, IRow> rows = GetFirstNRows(fc, max);

            var watch = new Stopwatch();

            watch.Start();

            foreach (int oid in rows.Keys)
            {
                Assert.NotNull(GdbQueryUtils.GetRow(fc, oid));
                _msg.Info($"Oid {oid} time: {watch.ElapsedMilliseconds}");
            }

            watch.Stop();

            double msPerIteration = watch.ElapsedMilliseconds / (double)rows.Count;

            _msg.InfoFormat(@"GetRow() per iteration: {0} ms", msPerIteration);

            Assert.True(msPerIteration < 50,
                        "GetFeature with existing feature takes too long ({0} ms, {1} rows)",
                        msPerIteration, rows.Count);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void CanResolvePartialTemplate()
        {
            const string templatePath =
                "C:\\Program Files (x86)\\ProSuite\\bin\\config\\template.html.tpl";
            const string partialName = "partial_name";

            string templateDirectory =
                Assert.NotNull(Path.GetDirectoryName(Path.GetFullPath(templatePath)));

            var fileSystem = new LocalFileSystem(templateDirectory);

            string result = fileSystem.FullPath(partialName);

            Console.WriteLine(result);
            NUnit.Framework.Assert.AreEqual(Path.Combine(templateDirectory,
                                                         $"_{partialName}.liquid"),
                                            result);
        }
Exemplo n.º 8
0
        public void CanCreateSpatialFilterWithMultipatch()
        {
            IFeatureWorkspace ws = OpenTestWorkspace();
            IFeatureClass     fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE");

            ISpatialReference spatialReference = DatasetUtils.GetSpatialReference(fc);

            IEnvelope largeEnvelope = GeometryFactory.CreateEnvelope(2600000, 1200000,
                                                                     2601000, 1201000,
                                                                     445, spatialReference);

            IMultiPatch multiPatch =
                GeometryFactory.CreateMultiPatch(GeometryFactory.CreatePolygon(largeEnvelope));

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

            // NOTE: Multipatch implements IRelationalOperator since a while!
            IGeometry validGeometry;
            string    message;

            Assert.True(GdbQueryUtils.IsValidFilterGeometry(
                            multiPatch, xyResolution, out validGeometry, out message),
                        "Multipatch should be valid");
            Assert.NotNull(validGeometry);
            Assert.True(multiPatch == validGeometry,
                        "Multipatch should be valid");

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

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

            Assert.True(GdbQueryUtils.GetFeatures(fc, filter, true).Any(), "No features found.");
        }
Exemplo n.º 9
0
 public void CanAssertNotNullMsg()
 {
     Assert.NotNull("not null", "{0} {1}", "arg1", "arg");
 }
Exemplo n.º 10
0
 public void CanAssertNotNull()
 {
     Assert.NotNull("not null");
 }
Exemplo n.º 11
0
        public void CanCreateSpatialFilterWithSubResolutionPolyline()
        {
            IFeatureWorkspace ws = OpenTestWorkspace();
            IFeatureClass     fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE");

            IPolyline subResolutionPolyline = GeometryFactory.CreatePolyline(2600000, 1200000,
                                                                             2600000.0001,
                                                                             1200000.0001);

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

            Exception expectedEx = null;

            try
            {
                ISpatialFilter standardFilter = new SpatialFilterClass();
                standardFilter.Geometry   = subResolutionPolyline;
                standardFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIndexIntersects;
                // ReSharper disable once UnusedVariable
                IFeatureCursor failingCursor = fc.Search(standardFilter, true);
            }
            catch (Exception ex)
            {
                expectedEx = ex;
            }

            if (RuntimeUtils.Is10_2 || RuntimeUtils.Is10_3 || RuntimeUtils.Is10_4orHigher)
            {
                Assert.Null(expectedEx);
            }
            else
            {
                Assert.NotNull(expectedEx);
            }

            IQueryFilter filter = GdbQueryUtils.CreateSpatialFilter(
                fc, subResolutionPolyline, esriSpatialRelEnum.esriSpatialRelIntersects, false,
                null);

            Assert.True(((ISpatialFilter)filter).FilterOwnsGeometry,
                        "Filter should own geometry due to cloned geometry in GetValidSearchGeometry.");
            Assert.AreEqual(((ISpatialFilter)filter).SearchOrder,
                            esriSearchOrder.esriSearchOrderSpatial,
                            "Default should be spatial.");
            Assert.AreEqual(((ISpatialFilter)filter).SpatialRel,
                            esriSpatialRelEnum.esriSpatialRelIntersects,
                            "Default should be spatial.");

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

            Marshal.ReleaseComObject(cursor);

            // test the exact half of the resolution - which is the limit
            double resolution = GeometryUtils.GetXyResolution(fc);

            subResolutionPolyline = GeometryFactory.CreatePolyline(2600000 - 0.00001,
                                                                   1200000 - 0.00001,
                                                                   2600000 + resolution -
                                                                   0.00001,
                                                                   1200000 + resolution -
                                                                   0.00001);

            filter = GdbQueryUtils.CreateSpatialFilter(
                fc, subResolutionPolyline, esriSpatialRelEnum.esriSpatialRelIntersects, false,
                null);

            cursor = fc.Search(filter, true);
            Marshal.ReleaseComObject(cursor);
        }
Exemplo n.º 12
0
        public void Learning_CanFindFeaturesWithSubResolutionEnvelope()
        {
            // TODO: This used to fail (in 2011) ("The number of points is less than required")
            // TEST if it now works on all supported versions!

            // 10.2.1: Test passes, Features are found
            // 10.4.1: Test passes, Features are found
            // 10.6.1: Test passes, Features are found

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

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

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

            subResolutionEnv.SpatialReference = spatialReference;

            IPoint point = null;

            foreach (var feature in GdbQueryUtils.GetFeatures(fc, true))
            {
                point = ((IPolyline)feature.Shape).FromPoint;
                break;
            }

            Assert.NotNull(point);
            IEnvelope envelope = point.Envelope;

            ISpatialFilter spatialFilter = new SpatialFilterClass();

            spatialFilter.GeometryField = fc.ShapeFieldName;

            spatialFilter.set_GeometryEx(envelope, true);

            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            var srClone =
                (ISpatialReferenceResolution)((IClone)spatialReference).Clone();

            srClone.set_XYResolution(true, 0.00001);

            spatialFilter.set_OutputSpatialReference(fc.ShapeFieldName,
                                                     (ISpatialReference)srClone);

            int found = GdbQueryUtils.GetFeatures(fc, spatialFilter, true).Count();

            Assert.True(found > 0, "No features found with mini-envelope");

            envelope.Expand(0.0001, 0.0001, false);
            IPolygon miniPoly = GeometryFactory.CreatePolygon(envelope);

            spatialFilter.set_GeometryEx(miniPoly, true);

            found = GdbQueryUtils.GetFeatures(fc, spatialFilter, true).Count();

            Assert.True(found > 0, "No features found with mini-polygon");
        }
Exemplo n.º 13
0
        public void TestExpression()
        {
            const string intField    = "Int";
            const string doubleField = "Dbl";
            IFieldsEdit  fields      = new FieldsClass();

            fields.AddField(FieldUtils.CreateOIDField());
            fields.AddField(FieldUtils.CreateIntegerField(intField));
            fields.AddField(FieldUtils.CreateDoubleField(doubleField, doubleField));

            ITable tbl = DatasetUtils.CreateTable(_testWs, "TestExpression", null, fields);

            const int n = 10;

            for (var i = 0; i < n; i++)
            {
                IRow row = tbl.CreateRow();
                row.set_Value(1, i);
                row.set_Value(2, i);
                row.Store();
            }

            const double x               = 2;
            string       expression      = string.Format("{0}, {1}, {2}", x, intField, doubleField);
            const bool   useAsConstraint = false;
            TableView    view            = TableViewFactory.Create(tbl, expression, useAsConstraint);

            DataColumn constColumn = view.AddColumn("constValue", typeof(double));

            constColumn.Expression = x.ToString(CultureInfo.InvariantCulture);

            DataColumn intColumn = view.AddColumn("intValue", typeof(double));

            intColumn.Expression = intField;

            DataColumn exprColumn = view.AddColumn("exprValue", typeof(double));

            exprColumn.Expression = string.Format("2.3 * {0} + 1.2 * {1}", doubleField,
                                                  intField);

            DataColumn doubleColumn = view.AddColumn("doubleValue", typeof(double));

            doubleColumn.Expression = doubleField;

            foreach (IRow row in new EnumCursor(tbl, null, false))
            {
                view.ClearRows();
                var i = (int)row.Value[1];
                var d = (double)row.Value[2];

                DataRow expressionRow = Assert.NotNull(view.Add(row));

                var constVal = (double)expressionRow[constColumn.ColumnName];
                NUnit.Framework.Assert.AreEqual(x, constVal);

                var intVal = (double)expressionRow[intColumn.ColumnName];
                NUnit.Framework.Assert.AreEqual(i, intVal);

                var doubleVal = (double)expressionRow[doubleColumn.ColumnName];
                NUnit.Framework.Assert.AreEqual(d, doubleVal);

                var exprVal = (double)expressionRow[exprColumn.ColumnName];
                NUnit.Framework.Assert.AreEqual(2.3 * d + 1.2 * i, exprVal);
            }
        }