private static bool HasFulfilledConstraint( [NotNull] IRow row1, int tableIndex1, [NotNull] IRow row2, int tableIndex2, [CanBeNull] IValidRelationConstraint validRelationConstraint, [NotNull] string message, [NotNull] out string formattedMessage) { Assert.ArgumentNotNull(row1, nameof(row1)); Assert.ArgumentNotNull(row2, nameof(row2)); Assert.ArgumentNotNullOrEmpty(message, nameof(message)); if (validRelationConstraint == null || !validRelationConstraint.HasConstraint) { formattedMessage = message; return(false); } string conditionMessage; if (validRelationConstraint.IsFulfilled(row1, tableIndex1, row2, tableIndex2, out conditionMessage)) { formattedMessage = string.Empty; return(true); } formattedMessage = $"{message} and constraint is not fulfilled: {conditionMessage}"; return(false); }
protected override int FindErrors(IRow row1, int tableIndex1, IRow row2, int tableIndex2) { var feature1 = row1 as IFeature; var feature2 = row2 as IFeature; if (feature1 == null || feature2 == null) { return(NoError); } if (!_vertexCoincidenceChecker.VerifyWithinFeature && (feature1 == feature2)) { return(NoError); } if (_allowedNonCoincidenceConditionSql != null && (feature1 != feature2)) { if (_allowedNonCoincidenceCondition == null) { const bool constraintIsDirected = false; _allowedNonCoincidenceCondition = new ValidRelationConstraint( _allowedNonCoincidenceConditionSql, constraintIsDirected, GetSqlCaseSensitivity()); } string conditionMessage; if (_allowedNonCoincidenceCondition.IsFulfilled(row1, tableIndex1, row2, tableIndex2, out conditionMessage)) { // non-coincidence is allowed between these two features return(NoError); } } if (_pointsEnumerator == null || _pointsEnumerator.Feature != feature1) { _pointsEnumerator = PointsEnumeratorFactory.Create(feature1, _pointSearchEnvelope); } return(_vertexCoincidenceChecker.CheckCoincidence(_pointsEnumerator, feature2)); }
private bool HasFulfilledConstraint([NotNull] IRow row1, int tableIndex1, [NotNull] IRow row2, int tableIndex2, [NotNull] string description, [NotNull] out string formattedMessage) { // TODO consider consolidating with QaSpatialRelationUtils.HasFulfilledConstraint() if (_validRelationConstraintSql == null) { formattedMessage = description; return(false); } if (_validRelationConstraint == null) { const bool constraintIsDirected = false; _validRelationConstraint = new ValidRelationConstraint(_validRelationConstraintSql, constraintIsDirected, GetSqlCaseSensitivity()); } string conditionMessage; if (_validRelationConstraint.IsFulfilled(row1, tableIndex1, row2, tableIndex2, out conditionMessage)) { formattedMessage = string.Empty; return(true); } formattedMessage = string.Format("{0} and constraint is not fulfilled: {1}", description, conditionMessage); return(false); }
private int CheckTable([NotNull] IFeature feature, [NotNull] IFeatureClass referenceClass, int referenceClassIndex) { GeometryComponent geometryComponent = GetGeometryComponent(referenceClassIndex); IValidRelationConstraint validConstraint = GetValidRelationConstraint(referenceClassIndex); if (_pointTemplate == null) { _pointTemplate = new PointClass(); } var errorCount = 0; foreach (IPoint point in GetNodes(feature.Shape, _pointTemplate)) { ISpatialFilter filter = PrepareSpatialFilter(point, referenceClassIndex); QueryFilterHelper helper = _helper[referenceClassIndex]; const int pointClassIndex = 0; foreach (IRow referenceRow in Search((ITable)referenceClass, filter, helper, point)) { if (TestUtils.IsSameRow(feature, referenceRow)) { continue; } var referenceFeature = (IFeature)referenceRow; string conditionMessage; if (validConstraint != null && validConstraint.HasConstraint && validConstraint.IsFulfilled(feature, pointClassIndex, referenceFeature, referenceClassIndex, out conditionMessage)) { continue; } double standardDistance; double?rightSideDistance; double maxNeededDistance = GetMaxNeededDistance( feature, referenceFeature, referenceClassIndex, out standardDistance, out rightSideDistance); maxNeededDistance = Math.Max(maxNeededDistance, _pointClassXyTolerance); bool isWithinPolygon; bool onRightSide; double distance = GetDistance(point, referenceFeature, _nearPoint, geometryComponent, maxNeededDistance, out isWithinPolygon, out onRightSide); if (AllowCoincidentPoints && IsSmallerThanXyTolerance(distance, referenceClassIndex)) { continue; } if (distance > maxNeededDistance) { continue; } double minimumDistance = maxNeededDistance; if (rightSideDistance.HasValue) { if (_referenceFlipConditions == null) { _referenceFlipConditions = CreateFlipConditions(_referenceFlipExpressions); } bool flip = _referenceFlipConditions.Count > 0 ? _referenceFlipConditions[ referenceClassIndex - _firstReferenceClassIndex].IsFulfilled( referenceFeature) : false; double useDistance = (onRightSide == flip) ? standardDistance : rightSideDistance.Value; if (distance > useDistance) { continue; } minimumDistance = useDistance; } errorCount += ReportError(feature, referenceFeature, point, _nearPoint, distance, minimumDistance, isWithinPolygon, geometryComponent, validConstraint); } } return(errorCount); }