Exemplo n.º 1
0
        private IEnumerable <IFeature> GetConnectedBorderFeatures(
            [NotNull] IGeometry geometry,
            [NotNull] IFeature geometryFeature, int geometryClassIndex,
            int borderClassIndex,
            [NotNull] Func <ITable, IQueryFilter, QueryFilterHelper, IEnumerable <IRow> > search,
            ITable borderClass,
            ISpatialFilter spatialFilter,
            QueryFilterHelper filterHelper,
            RowPairCondition borderMatchCondition)
        {
            spatialFilter.Geometry = geometry;

            var result = new List <IFeature>(5);

            foreach (IRow borderRow in search(borderClass,
                                              spatialFilter,
                                              filterHelper))
            {
                if (!borderMatchCondition.IsFulfilled(geometryFeature, geometryClassIndex,
                                                      borderRow, borderClassIndex))
                {
                    continue;
                }

                result.Add((IFeature)borderRow);
            }

            return(result);
        }
Exemplo n.º 2
0
        GetAttributeConstraintViolations(
            [NotNull] IFeature feature, int classIndex,
            [NotNull] IFeature neighborFeature, int neighborClassIndex,
            [NotNull] RowPairCondition rowPairCondition,
            [NotNull] EqualFieldValuesCondition equalFieldValuesCondition,
            bool reportIndividually = false)
        {
            if (reportIndividually)
            {
                string       message;
                IColumnNames errorColumnNames;
                if (!rowPairCondition.IsFulfilled(feature, classIndex,
                                                  neighborFeature,
                                                  neighborClassIndex,
                                                  out message,
                                                  out errorColumnNames))
                {
                    var affectedFields = new HashSet <string>(
                        errorColumnNames.GetInvolvedColumnNames(),
                        StringComparer.OrdinalIgnoreCase);

                    yield return(new AttributeConstraintViolation(
                                     string.Format(
                                         LocalizableStrings
                                         .EdgeMatchUtils_AttributeConstraints_ConstraintNotFulfilled,
                                         message), affectedFields, message));
                }

                IEnumerable <UnequalField> unequalFields =
                    equalFieldValuesCondition.GetNonEqualFields(feature, classIndex,
                                                                neighborFeature,
                                                                neighborClassIndex);
                foreach (UnequalField unequalField in unequalFields)
                {
                    yield return(new AttributeConstraintViolation(
                                     string.Format(
                                         LocalizableStrings.EdgeMatchUtils_AttributeConstraints_ValuesNotEqual,
                                         unequalField.Message), unequalField.FieldName, unequalField.Message));
                }
            }
            else
            {
                string description;
                string affectedComponents;
                string textValue;
                bool   areConstraintsFulfilled = AreAttributeConstraintsFulfilled(
                    feature, classIndex,
                    neighborFeature, neighborClassIndex,
                    rowPairCondition,
                    equalFieldValuesCondition,
                    out description, out affectedComponents, out textValue);

                if (!areConstraintsFulfilled)
                {
                    yield return(new AttributeConstraintViolation(description,
                                                                  affectedComponents,
                                                                  textValue));
                }
            }
        }
Exemplo n.º 3
0
        public IEnumerable <T> GetBorderConnections <TG>(
            [NotNull] TG geometry,
            [NotNull] IFeature geometryFeature,
            int geometryClassIndex,
            int borderClassIndex,
            ITable borderClass,
            ISpatialFilter spatialFilter,
            QueryFilterHelper filterHelper,
            Func <ITable, IQueryFilter, QueryFilterHelper, IEnumerable <IRow> > search,
            RowPairCondition borderMatchCondition)
            where TG : IGeometry
        {
            var geometryKey = new FeatureKey(geometryFeature.OID, geometryClassIndex);

            Dictionary <FeatureKey, T> borderConnections;

            if (!_cache.TryGetValue(geometryKey, out borderConnections))
            {
                borderConnections = new Dictionary <FeatureKey, T>(new FeatureKeyComparer());

                _cache.Add(geometryKey, borderConnections);
            }

            IPolyline geometryLine = geometry is IPolyline
                                                         ? (IPolyline)geometry
                                                         : (IPolyline)((ITopologicalOperator)geometry).Boundary;

            IEnumerable <IFeature> borderFeatures =
                GetConnectedBorderFeatures(geometry, geometryFeature, geometryClassIndex,
                                           borderClassIndex, search, borderClass, spatialFilter,
                                           filterHelper, borderMatchCondition);

            foreach (IFeature borderFeature in borderFeatures)
            {
                var borderKey = new FeatureKey(borderFeature.OID, borderClassIndex);

                T borderConnection;
                if (!borderConnections.TryGetValue(borderKey, out borderConnection))
                {
                    IPolyline geometryAlongBorder = GetGeometryAlongBorder(borderFeature,
                                                                           geometryLine);

                    borderConnection = CreateBorderConnection(geometryFeature, geometryClassIndex,
                                                              borderFeature,
                                                              borderClassIndex,
                                                              geometryAlongBorder,
                                                              geometryAlongBorder);

                    borderConnections.Add(borderKey, borderConnection);
                }
            }

            return(new List <T>(borderConnections.Values));
        }
Exemplo n.º 4
0
        private static bool AreAttributeConstraintsFulfilled(
            [NotNull] IFeature feature, int classIndex,
            [NotNull] IFeature neighborFeature, int neighborClassIndex,
            [NotNull] RowPairCondition rowPairCondition,
            [NotNull] EqualFieldValuesCondition equalFieldValuesCondition,
            [NotNull] out string errorDescription,
            [CanBeNull] out string affectedComponents,
            [NotNull] out string textValue)
        {
            var affectedFields = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            // compare attributes that are required to match
            var          descriptionBuilder = new StringBuilder();
            var          textValueBuilder   = new StringBuilder();
            string       message;
            IColumnNames errorColumnNames;

            if (!rowPairCondition.IsFulfilled(feature, classIndex,
                                              neighborFeature,
                                              neighborClassIndex,
                                              out message,
                                              out errorColumnNames))
            {
                descriptionBuilder.AppendFormat(
                    LocalizableStrings.EdgeMatchUtils_AttributeConstraints_ConstraintNotFulfilled,
                    message);

                foreach (string affectedColumn in errorColumnNames.GetInvolvedColumnNames())
                {
                    affectedFields.Add(affectedColumn);
                }

                textValueBuilder.Append(message);
            }

            IEnumerable <UnequalField> unequalFields =
                equalFieldValuesCondition.GetNonEqualFields(feature, classIndex,
                                                            neighborFeature, neighborClassIndex);

            if (HasUnequalFields(unequalFields, out message, affectedFields))
            {
                if (descriptionBuilder.Length > 0)
                {
                    descriptionBuilder.Append(". ");
                }

                descriptionBuilder.AppendFormat(
                    LocalizableStrings.EdgeMatchUtils_AttributeConstraints_ValuesNotEqual,
                    message);

                if (textValueBuilder.Length > 0)
                {
                    textValueBuilder.Append("|");
                }

                textValueBuilder.Append(message);
            }

            errorDescription   = descriptionBuilder.ToString();
            affectedComponents = FormatAffectedComponents(affectedFields);
            textValue          = textValueBuilder.ToString();

            return(errorDescription.Length == 0);
        }