private double GetMaxNeededDistance([NotNull] IFeature pointFeature, [NotNull] IFeature referenceFeature, int referenceClassIndex, out double standardDistance, out double?rightSideDistance) { if (_referenceRightSideDistanceExpressions == null) { _referenceRightSideDistanceExpressions = GetReferenceDistanceExpressions(_referenceRightSideDistanceSqls); } double?referenceRightSideDistance = _referenceRightSideDistanceExpressions.Count > 0 ? _referenceRightSideDistanceExpressions[ referenceClassIndex - _firstReferenceClassIndex].GetDouble( referenceFeature) : null; if (!_useDistanceExpressions) { standardDistance = SearchDistance; rightSideDistance = referenceRightSideDistance; return(SearchDistance); } // lazy initialization if (_pointDistanceExpression == null && StringUtils.IsNotEmpty(_pointDistanceExpressionSql)) { _pointDistanceExpression = new DoubleFieldExpression( InvolvedTables[0], _pointDistanceExpressionSql, caseSensitive: GetSqlCaseSensitivity(0)); } double?pointDistance = _pointDistanceExpression?.GetDouble(pointFeature); if (_referenceDistanceExpressions == null) { _referenceDistanceExpressions = GetReferenceDistanceExpressions(_referenceDistanceExpressionsSql); } // get distances from expressions double?referenceDistance = _referenceDistanceExpressions.Count > 0 ? _referenceDistanceExpressions[ referenceClassIndex - _firstReferenceClassIndex] .GetDouble(referenceFeature) : null; standardDistance = (pointDistance ?? 0) + (referenceDistance ?? 0); rightSideDistance = referenceRightSideDistance.HasValue ? (pointDistance ?? 0) + referenceRightSideDistance : null; return(Math.Max(standardDistance, rightSideDistance ?? 0)); }
protected override int ExecuteCore(IRow row, int tableIndex) { // preparing if (_filter == null) { Init(); } const int pointTableIndex = 0; if (tableIndex != pointTableIndex) { return(NoError); } var pointFeature = row as IFeature; if (pointFeature == null) { return(NoError); } if (!_expressionHelpersInitialized) { _matchExpressionHelper = GetMatchExpressionHelper(_matchExpression); _mExpressionHelper = GetMExpression(_pointClass, _expectedMValueExpression); _expressionHelpersInitialized = true; } var point = (IPoint)pointFeature.Shape; point.QueryEnvelope(_box); _box.Expand(SearchDistance, SearchDistance, false); double?expectedMValue; if (_mExpressionHelper != null) { try { expectedMValue = _mExpressionHelper.GetDouble(pointFeature); } catch (Exception e) { string description = string.Format( "Invalid value from expected M expression '{0}'. Numeric value expected ({1})", _expectedMValueExpression, e.Message); return(ReportError(description, pointFeature.ShapeCopy, Codes[Code.ExpressionResultNotNumeric], null, pointFeature)); } } else { expectedMValue = point.M; } if (expectedMValue == null || double.IsNaN(expectedMValue.Value)) { if (_ignoreUndefinedExpectedMValue) { // expected value is undefined; just ignore (don't require NaN M values on line) return(NoError); } string description; if (string.IsNullOrEmpty(_expectedMValueExpression)) { description = "Undefined M value on point feature"; return(ReportError(description, pointFeature.ShapeCopy, Codes[Code.UndefinedMValue_FromPointFeature], TestUtils.GetShapeFieldName(pointFeature), pointFeature)); } description = string.Format( "Undefined expected M value from expression '{0}'", _expectedMValueExpression); return(ReportError(description, pointFeature.ShapeCopy, Codes[Code.UndefinedMValue_FromExpression], null, pointFeature)); } int errorCount = 0; bool hasNeighborFeature = false; for (int neighborTableIndex = 1; neighborTableIndex < _tableCount; neighborTableIndex++) { var neighborClass = (IFeatureClass)InvolvedTables[neighborTableIndex]; _helper[neighborTableIndex].MinimumOID = -1; int neighborFeatureCount; errorCount += CheckTable(pointFeature, tableIndex, point, expectedMValue.Value, neighborClass, neighborTableIndex, out neighborFeatureCount); if (neighborFeatureCount > 0) { hasNeighborFeature = true; } } if (_requireLine && !hasNeighborFeature) { var error = (IPoint)pointFeature.ShapeCopy; string description = string.Format( "Point does not lie closer than {0} to any line", FormatLength(SearchDistance, _spatialReference)); errorCount += ReportError(description, error, Codes[Code.PointNotNearLine], TestUtils.GetShapeFieldName(pointFeature), pointFeature); } return(errorCount); }