Exemplo n.º 1
0
        public bool Contains(InvolvedRow involvedRow, QualityCondition qualityCondition,
                             out bool unknownTable)
        {
            if (involvedRow.RepresentsEntireTable)
            {
                unknownTable = false;                 // does not matter
                return(false);
            }

            IObjectDataset dataset = _datasetResolver.GetDatasetByInvolvedRowTableName(
                involvedRow.TableName, qualityCondition);

            if (dataset == null)
            {
                // unable to resolve the dataset
                unknownTable = true;
                return(false);
            }

            unknownTable = false;
            HashSet <int> objectIds;

            return(_objectsByDataset.TryGetValue(dataset, out objectIds) &&
                   objectIds.Contains(involvedRow.OID));
        }
Exemplo n.º 2
0
        private static IObject GetInvolvedObject(
            [NotNull] InvolvedRow involvedRow,
            [NotNull] QualityCondition qualityCondition,
            [NotNull] IDatasetContext datasetContext,
            [NotNull] IQualityConditionObjectDatasetResolver datasetResolver,
            [NotNull] out IObjectDataset objectDataset)
        {
            Assert.ArgumentNotNull(involvedRow, nameof(involvedRow));
            Assert.ArgumentNotNull(qualityCondition, nameof(qualityCondition));
            Assert.ArgumentCondition(!involvedRow.RepresentsEntireTable,
                                     "involved row represents entire table");
            Assert.ArgumentNotNull(datasetContext, nameof(datasetContext));

            //string gdbTableName = involvedRow.TableName;
            //objectDataset = Assert.NotNull(
            //    QualityVerificationUtils.GetInvolvedObjectDataset(gdbTableName,
            //                                                      qualityCondition,
            //                                                      datasetResolver),
            //    "object dataset not found for {0}", involvedRow.TableName);
            string gdbTableName = involvedRow.TableName;

            objectDataset = Assert.NotNull(
                datasetResolver.GetDatasetByGdbTableName(gdbTableName, qualityCondition),
                "object dataset not found for {0}", involvedRow.TableName);

            ITable table = datasetContext.OpenTable(objectDataset);

            // TODO REFACTORMODEL revise null handling
            Assert.NotNull(table, "Dataset not found in workspace: {0}", objectDataset.Name);

            // TODO batch!
            return((IObject)table.GetRow(involvedRow.OID));
        }
Exemplo n.º 3
0
            public bool TryLookupKey([NotNull] InvolvedRow involvedRow,
                                     [CanBeNull] out object keyValue)
            {
                if (involvedRow.RepresentsEntireTable)
                {
                    keyValue = null;
                    return(false);
                }

                if (_oidsRequiringLookup.Count > 0)
                {
                    foreach (KeyValuePair <int, object> pair in LookupKeys(_oidsRequiringLookup))
                    {
                        object value = Assert.NotNull(pair.Value,
                                                      "key is <null> for oid={0}, table={1}",
                                                      pair.Key,
                                                      DatasetUtils.GetName(_table));
                        _keyMap[pair.Key] = value;
                    }

                    _oidsRequiringLookup.Clear();
                }

                return(_keyMap.TryGetValue(involvedRow.OID, out keyValue));
            }
Exemplo n.º 4
0
        protected override int CompleteTileCore(TileInfo args)
        {
            if (args.State == TileState.Initial)
            {
                return(NoError);
            }

            int errorCount = base.CompleteTileCore(args);

            if (ConnectedLinesList == null)
            {
                return(errorCount);
            }

            errorCount += ConnectedLinesList.Sum(connectedRows => ResolveRows(connectedRows));

            foreach (LineList <DirectedRow> list in
                     _grower.GetAndRemoveCollectionsInside(args.ProcessedEnvelope))
            {
                // these are all not closed polygons and hence errors
                const string description = "Incomplete line";

                errorCount += ReportError(description,
                                          CreateUnclosedErrorGeometry(list),
                                          Codes[Code.IncompleteLine],
                                          TestUtils.GetShapeFieldName(
                                              (IFeature)list.DirectedRows.First.Value.Row.Row),
                                          InvolvedRow.CreateList(
                                              list.GetUniqueRows(InvolvedTables)));
            }

            return(errorCount);
        }
Exemplo n.º 5
0
        private static IEnumerable <IGeometry> GetReferenceGeometries(
            [NotNull] InvolvedRow involvedRow,
            [NotNull] QualityCondition qualityCondition,
            [NotNull] IVerificationContext verificationContext,
            [NotNull] IQualityConditionObjectDatasetResolver datasetResolver,
            [CanBeNull] Predicate <VectorDataset> isRelevantVectorDataset)
        {
            Assert.ArgumentNotNull(involvedRow, nameof(involvedRow));
            Assert.ArgumentNotNull(qualityCondition, nameof(qualityCondition));
            Assert.ArgumentNotNull(verificationContext, nameof(involvedRow));

            if (involvedRow.RepresentsEntireTable)
            {
                yield break;
            }

            IObjectDataset objectDataset;
            IObject        obj = GetInvolvedObject(involvedRow, qualityCondition, verificationContext,
                                                   datasetResolver, out objectDataset);

            var feature = obj as IFeature;

            if (feature != null)
            {
                IGeometry shape = feature.Shape;
                if (shape != null && !shape.IsEmpty)
                {
                    yield return(shape);
                }
            }
            else
            {
                bool hasAnyAssociationsToFeatureClasses;
                foreach (IList <IRelationshipClass> relClassChain
                         in GetRelationshipClassChainsToVerifiedFeatureClasses(
                             objectDataset,
                             verificationContext,
                             isRelevantVectorDataset,
                             out hasAnyAssociationsToFeatureClasses))
                {
                    foreach (IGeometry shape in
                             GetReferenceGeometries(obj, relClassChain))
                    {
                        if (shape != null && !shape.IsEmpty)
                        {
                            yield return(shape);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private TableKeyLookup GetTableRequiringIdLookup(
            [NotNull] InvolvedRow involvedRow,
            [NotNull] QualitySpecificationElement element)
        {
            if (involvedRow.RepresentsEntireTable)
            {
                return(null);
            }

            IObjectDataset objectDataset = _datasetResolver.GetDatasetByInvolvedRowTableName(
                involvedRow.TableName, element.QualityCondition);

            Assert.NotNull(objectDataset,
                           "Unable to resolve object dataset for table name {0} and quality condition {1}",
                           involvedRow.TableName, element.QualityCondition.Name);

            return(GetTableRequiringIdLookup(objectDataset));
        }
Exemplo n.º 7
0
        private int CheckPolygon([NotNull] LineList <DirectedRow> polygonLineList)
        {
            int errorCount = CheckConsistentOrientation(polygonLineList);

            if (errorCount > 0)
            {
                // inconsistent orientation found, report no other errors
                return(errorCount);
            }

            int clockwise = polygonLineList.Orientation();

            if (clockwise == 0)
            {
                const string description = "Empty polygon created";

                return(ReportError(description, polygonLineList.GetBorder(),
                                   Codes[Code.EmptyPolygonCreated], null,
                                   InvolvedRow.CreateList(
                                       polygonLineList.GetUniqueRows(InvolvedTables))));
            }

            if (polygonLineList.DirectedRows.Count > 1 || !FirstReversed(polygonLineList))
            {
                bool polyOrientation = clockwise > 0;

                if ((polyOrientation == _orientation) == FirstReversed(polygonLineList))
                {
                    const string description = "Inverted orientation";

                    return(ReportError(description, polygonLineList.GetPolygon(),
                                       Codes[Code.InvertedOrientation], null,
                                       InvolvedRow.CreateList(
                                           polygonLineList.GetUniqueRows(InvolvedTables))));
                }
            }

            return(NoError);
        }
Exemplo n.º 8
0
        private int CheckCentroids(
            [NotNull] IEnumerable <LineListPolygon <DirectedRow> >
            polyList)
        {
            var errorCount = 0;

            foreach (LineListPolygon <DirectedRow> poly in polyList)
            {
                int pointsWithin = GetReducedCount(poly.Centroids);
                if (pointsWithin == 1)
                {
                    continue;
                }

                IPolygon            errorGeometry = poly.GetPolygon();
                IList <InvolvedRow> involved      =
                    InvolvedRow.CreateList(poly.OuterRing.GetUniqueRows(InvolvedTables));

                string description =
                    $"Constructed polygon contains {pointsWithin} centroids.";
                errorCount += ReportError(description, errorGeometry,
                                          pointsWithin > 1
                                                                  ? Codes[Code.MultipleCentroids]
                                                                  : Codes[Code.NoCentroid],
                                          null, involved);

                if (pointsWithin <= 1)
                {
                    continue;
                }

                description = "Multiple centroids of constructed polygon";
                errorCount += ReportError(description, GetErrorGeometry(poly),
                                          Codes[Code.MultipleCentroids], null,
                                          involved);
            }

            return(errorCount);
        }
Exemplo n.º 9
0
        public bool Contains(InvolvedRow involvedRow, QualityCondition qualityCondition)
        {
            bool unknownTable;

            return(Contains(involvedRow, qualityCondition, out unknownTable));
        }
Exemplo n.º 10
0
        private void Verify([NotNull] TestContainer container,
                            [CanBeNull] AreaOfInterest areaOfInterest)
        {
            Assert.ArgumentNotNull(container, nameof(container));

            ClearCurrentRow();

            // add handlers
            container.TestingRow      += container_TestingRow;
            container.QaError         += HandleError;
            container.ProgressChanged += container_OnProgressChanged;

            try
            {
                _executeContainer = container;

                // TODO let the container know about the selected features
                // (filter TestRows by inclusion in selection list)

                TestExecutionUtils.Execute(container, areaOfInterest);
            }
            catch (TestContainerException e)
            {
                QualityCondition qualityCondition = GetQualityCondition(e.Test);

                string description = string.Format("Error testing {0}: {1}",
                                                   qualityCondition.Name,
                                                   e.Message);

                var       involvedRows           = new InvolvedRow[] { };
                IGeometry exceptionErrorGeometry = null;

                if (_currentRow != null)
                {
                    if (_currentRow.HasOID && _currentRow.Table.HasOID)
                    // ie TerrainRow (wrapper around terrain tile)
                    {
                        // second part: ESRI Bug for IQueryDefTables
                        // which returns row.HasOID = true
                        involvedRows = new[] { new InvolvedRow(_currentRow) };
                    }

                    try
                    {
                        var feature = _currentRow as IFeature;

                        IGeometry shape = feature?.Shape;
                        if (shape != null && !shape.IsEmpty)
                        {
                            exceptionErrorGeometry = feature.ShapeCopy;
                        }
                    }
                    catch (Exception exception)
                    {
                        _msg.Error(
                            "Error trying to get geometry from feature involved in failed test",
                            exception);
                    }
                }

                if (exceptionErrorGeometry == null)
                {
                    exceptionErrorGeometry = e.Box;
                }

                var qaError = new QaError(e.Test, description, involvedRows,
                                          exceptionErrorGeometry, null, null);

                ProcessQaError(qaError);

                CancellationTokenSource.Cancel();
                CancellationMessage = description;
                _msg.Error(description, e);
            }
            finally
            {
                // remove handlers
                container.ProgressChanged -= container_OnProgressChanged;
                container.QaError         -= HandleError;
                container.TestingRow      -= container_TestingRow;
            }
        }