Exemple #1
0
 private string GetNonEqualValueMessage([NotNull] CoordinateField coordinateField,
                                        double fieldValue, double shapeValue)
 {
     return(string.Format("Field {0}: {1}",
                          coordinateField.FieldName,
                          FormatLengthComparison(fieldValue, "<>", shapeValue,
                                                 _spatialReference).Trim()));
 }
Exemple #2
0
        private bool TryReadValue([NotNull] IRow row,
                                  [NotNull] CoordinateField coordinateField,
                                  out double?value,
                                  [NotNull] out string message,
                                  [CanBeNull] out IssueCode issueCode)
        {
            object rawValue = row.Value[coordinateField.FieldIndex];

            if (rawValue == null || rawValue is DBNull)
            {
                value     = null;
                message   = string.Empty;
                issueCode = null;
                return(true);
            }

            if (coordinateField.IsText)
            {
                var text = (string)rawValue;

                double doubleValue;
                if (!double.TryParse(text, NumberStyles.Number, _cultureInfo,
                                     out doubleValue))
                {
                    message = string.Format(
                        "Unable to read coordinate value from text field '{0}'; text value: '{1}'",
                        coordinateField.FieldName, text);
                    issueCode = Codes[Code.TextFieldValueIsNotNumeric];
                    value     = null;
                    return(false);
                }

                message   = string.Empty;
                issueCode = null;
                value     = doubleValue;
                return(true);
            }

            try
            {
                message   = string.Empty;
                issueCode = null;
                value     = Convert.ToDouble(rawValue);
                return(true);
            }
            catch (Exception e)
            {
                message = string.Format(
                    "Error reading coordinate value from field '{0}' (value: {1}): {2}",
                    coordinateField.FieldName, rawValue, e.Message);
                issueCode = Codes[Code.ErrorReadingFieldValue];
                value     = null;
                return(false);
            }
        }
Exemple #3
0
        private int CheckZValue([NotNull] IFeature feature,
                                [CanBeNull] IPoint point,
                                [NotNull] CoordinateField zCoordinateField)
        {
            int    errorCount = 0;
            double?zFieldValue;
            bool   errorReadingValue;

            errorCount += TryReadValue(feature, zCoordinateField, point, out zFieldValue,
                                       out errorReadingValue);

            if (point == null)
            {
                if (!AllowZFieldValueForUndefinedShape && zFieldValue != null)
                {
                    errorCount += ReportFieldValueForUndefinedShape(feature,
                                                                    zCoordinateField,
                                                                    zFieldValue.Value);
                }
            }
            else
            {
                if (zFieldValue != null)
                {
                    double shapeZ = point.Z;

                    double zDistance = Math.Abs(zFieldValue.Value - shapeZ);

                    if (zDistance > _zTolerance)
                    {
                        errorCount += ReportZFieldCoordinateTooFarFromShape(
                            feature, point,
                            zCoordinateField,
                            zFieldValue.Value,
                            shapeZ, zDistance);
                    }
                }
                else if (!errorReadingValue)
                {
                    // the field value is null, but the shape has a Z value

                    if (!AllowMissingZFieldValueForDefinedShape)
                    {
                        errorCount += ReportMissingFieldValueForDefinedShape(feature,
                                                                             point,
                                                                             zCoordinateField);
                    }
                }
            }

            return(errorCount);
        }
Exemple #4
0
        private int ReportXYFieldCoordinatesTooFarFromShape(
            [NotNull] IFeature feature, [NotNull] IPoint point, double xyDistance,
            [NotNull] CoordinateField xCoordinateField, double xFieldValue, double shapeX,
            [NotNull] CoordinateField yCoordinateField, double yFieldValue, double shapeY)
        {
            bool xDifferent = Math.Abs(xFieldValue - shapeX) > _xyTolerance;
            bool yDifferent = Math.Abs(yFieldValue - shapeY) > _xyTolerance;

            if (xDifferent && !yDifferent)
            {
                return(ReportSingleXYFieldCoordinateTooFarFromShape(
                           feature, point, xyDistance,
                           xCoordinateField, xFieldValue,
                           shapeX, 'X'));
            }

            if (!xDifferent && yDifferent)
            {
                return(ReportSingleXYFieldCoordinateTooFarFromShape(
                           feature, point, xyDistance,
                           yCoordinateField, yFieldValue,
                           shapeY, 'Y'));
            }

            // either both differences are individually larger than the tolerance,
            // OR the 2D distance is larger than the tolerance but the individual distances are not
            // (in this case BOTH distances must be just below tolerance)
            string comparisonMessage = string.Format(" {0}; {1}",
                                                     GetNonEqualValueMessage(
                                                         xCoordinateField,
                                                         xFieldValue,
                                                         shapeX),
                                                     GetNonEqualValueMessage(
                                                         yCoordinateField,
                                                         yFieldValue,
                                                         shapeY));
            string affectedComponent = string.Format("{0},{1}",
                                                     xCoordinateField.FieldName,
                                                     yCoordinateField.FieldName);

            string description =
                string.Format(
                    "The distance between the XY field coordinates and the shape is larger than the tolerance ({0}).{1}",
                    FormatLengthComparison(xyDistance, ">", _xyTolerance,
                                           _spatialReference).Trim(),
                    comparisonMessage);

            return(ReportError(description, GetErrorGeometry(point),
                               Codes[Code.XYFieldCoordinatesTooFarFromShape],
                               affectedComponent, feature));
        }
Exemple #5
0
        private int ReportFieldValueForUndefinedShape(
            [NotNull] IFeature feature,
            [NotNull] CoordinateField coordinateField,
            double value)
        {
            string description =
                string.Format(
                    "The shape is not defined, but the field '{0}' has a value ({1})",
                    coordinateField.FieldName, value);

            return(ReportError(description, null,
                               Codes[Code.ShapeIsUndefinedButCoordinateFieldHasValue],
                               coordinateField.FieldName, feature));
        }
Exemple #6
0
        private int ReportMissingFieldValueForDefinedShape(
            [NotNull] IFeature feature,
            [NotNull] IPoint point,
            [NotNull] CoordinateField coordinateField)
        {
            string description =
                string.Format(
                    "The shape is defined, but the field '{0}' does not contain a value",
                    coordinateField.FieldName);

            return(ReportError(description,
                               GetErrorGeometry(point),
                               Codes[Code.ShapeIsDefinedButCoordinateFieldHasNoValue],
                               coordinateField.FieldName, feature));
        }
Exemple #7
0
        private int CheckSingleXYFieldCoordinate([NotNull] IFeature feature,
                                                 [NotNull] IPoint point,
                                                 [NotNull] CoordinateField coordinateField,
                                                 double fieldValue,
                                                 double shapeValue,
                                                 char coordinateAxis)
        {
            double distance = Math.Abs(fieldValue - shapeValue);

            if (distance <= _xyTolerance)
            {
                return(NoError);
            }

            return(ReportSingleXYFieldCoordinateTooFarFromShape(
                       feature, point, distance, coordinateField,
                       fieldValue, shapeValue, coordinateAxis));
        }
Exemple #8
0
        private int ReportZFieldCoordinateTooFarFromShape(
            [NotNull] IFeature feature,
            [NotNull] IPoint point,
            [NotNull] CoordinateField zCoordinateField,
            double zFieldValue,
            double shapeZ,
            double zDistance)
        {
            string description =
                string.Format(
                    "The distance between value {0:N3} in field '{1}' and the shape Z value {2:N3} is larger than the tolerance ({3})",
                    zFieldValue, zCoordinateField.FieldName, shapeZ,
                    FormatLengthComparison(zDistance, ">", _zTolerance,
                                           _spatialReference).Trim());

            return(ReportError(description, GetErrorGeometry(point),
                               Codes[Code.ZFieldCoordinateTooFarFromShape],
                               zCoordinateField.FieldName, feature));
        }
Exemple #9
0
        private int TryReadValue([NotNull] IFeature feature,
                                 [NotNull] CoordinateField coordinateField,
                                 [CanBeNull] IPoint point,
                                 out double?value,
                                 out bool errorReadingValue)
        {
            string    message;
            IssueCode issueCode;

            if (!TryReadValue(feature, coordinateField,
                              out value, out message, out issueCode))
            {
                errorReadingValue = true;
                return(ReportError(message, GetErrorGeometry(point),
                                   issueCode, coordinateField.FieldName, feature));
            }

            errorReadingValue = false;
            return(NoError);
        }
Exemple #10
0
        private int ReportSingleXYFieldCoordinateTooFarFromShape(
            [NotNull] IFeature feature,
            [NotNull] IPoint point,
            double distance,
            [NotNull] CoordinateField coordinateField,
            double fieldValue,
            double shapeValue,
            char coordinateAxis)
        {
            string description =
                string.Format(
                    "The distance between the value {0} in field '{1}' and " +
                    "the shape {2} value {3} is larger than the tolerance ({4})",
                    fieldValue, coordinateField.FieldName,
                    coordinateAxis, shapeValue,
                    FormatLengthComparison(distance, ">", _xyTolerance,
                                           _spatialReference).Trim());

            return(ReportError(description, GetErrorGeometry(point),
                               Codes[Code.XYFieldCoordinateValueTooFarFromShape],
                               coordinateField.FieldName, feature));
        }
Exemple #11
0
        public QaValidCoordinateFields(
            [Doc(nameof(DocStrings.QaValidCoordinateFields_featureClass))][NotNull]
            IFeatureClass featureClass,
            [Doc(nameof(DocStrings.QaValidCoordinateFields_xCoordinateFieldName))][CanBeNull]
            string
            xCoordinateFieldName,
            [Doc(nameof(DocStrings.QaValidCoordinateFields_yCoordinateFieldName))][CanBeNull]
            string
            yCoordinateFieldName,
            [Doc(nameof(DocStrings.QaValidCoordinateFields_zCoordinateFieldName))][CanBeNull]
            string
            zCoordinateFieldName,
            [Doc(nameof(DocStrings.QaValidCoordinateFields_xyTolerance))]
            double xyTolerance,
            [Doc(nameof(DocStrings.QaValidCoordinateFields_zTolerance))]
            double zTolerance,
            [Doc(nameof(DocStrings.QaValidCoordinateFields_culture))][CanBeNull]
            string culture)
            : base((ITable)featureClass)
        {
            Assert.ArgumentNotNull(featureClass, nameof(featureClass));
            Assert.ArgumentCondition(
                featureClass.ShapeType == esriGeometryType.esriGeometryPoint,
                "Only point feature classes are supported");

            if (xCoordinateFieldName != null &&
                StringUtils.IsNotEmpty(xCoordinateFieldName))
            {
                _xCoordinateField =
                    GetCoordinateField(featureClass, xCoordinateFieldName);
            }

            if (yCoordinateFieldName != null &&
                StringUtils.IsNotEmpty(yCoordinateFieldName))
            {
                _yCoordinateField =
                    GetCoordinateField(featureClass, yCoordinateFieldName);
            }

            if (zCoordinateFieldName != null &&
                StringUtils.IsNotEmpty(zCoordinateFieldName))
            {
                _zCoordinateField =
                    GetCoordinateField(featureClass, zCoordinateFieldName);
            }

            if (_xCoordinateField != null || _yCoordinateField != null)
            {
                _xyTolerance = xyTolerance;

                if (Math.Abs(_xyTolerance) < double.Epsilon)
                {
                    double srefXyTolerance;
                    if (DatasetUtils.TryGetXyTolerance(featureClass, out srefXyTolerance))
                    {
                        _xyTolerance = srefXyTolerance;
                    }
                }
            }

            if (_zCoordinateField != null)
            {
                _zTolerance = zTolerance;

                if (Math.Abs(_zTolerance) < double.Epsilon)
                {
                    double srefZTolerance;
                    if (DatasetUtils.TryGetZTolerance(featureClass, out srefZTolerance))
                    {
                        _zTolerance = srefZTolerance;
                    }
                }

                if (!DatasetUtils.HasZ(featureClass))
                {
                    throw new InvalidConfigurationException(
                              string.Format(
                                  "Feature class '{0}' does not have Z values, unable to verify Z coordinate field",
                                  DatasetUtils.GetName(featureClass)));
                }
            }

            _xyToleranceSquared = _xyTolerance * _xyTolerance;

            _cultureInfo = culture == null || StringUtils.IsNullOrEmptyOrBlank(culture)
                                               ? CultureInfo.InvariantCulture
                                               : CultureInfo.GetCultureInfo(culture);
            _spatialReference = ((IGeoDataset)featureClass).SpatialReference;
        }
Exemple #12
0
        private int CheckXYValues([NotNull] IFeature feature,
                                  [CanBeNull] IPoint point,
                                  [CanBeNull] CoordinateField xCoordinateField,
                                  [CanBeNull] CoordinateField yCoordinateField)
        {
            if (xCoordinateField == null && yCoordinateField == null)
            {
                return(NoError);
            }

            int    errorCount         = 0;
            bool   errorReadingXValue = false;
            bool   errorReadingYValue = false;
            double?xFieldValue        = null;

            if (xCoordinateField != null)
            {
                errorCount += TryReadValue(feature, xCoordinateField, point,
                                           out xFieldValue, out errorReadingXValue);
            }

            double?yFieldValue = null;

            if (yCoordinateField != null)
            {
                errorCount += TryReadValue(feature, yCoordinateField, point,
                                           out yFieldValue, out errorReadingYValue);
            }

            if (point == null)
            {
                if (!AllowXYFieldValuesForUndefinedShape)
                {
                    if (xFieldValue != null)
                    {
                        errorCount += ReportFieldValueForUndefinedShape(feature,
                                                                        xCoordinateField,
                                                                        xFieldValue
                                                                        .Value);
                    }

                    if (yFieldValue != null)
                    {
                        errorCount += ReportFieldValueForUndefinedShape(feature,
                                                                        yCoordinateField,
                                                                        yFieldValue
                                                                        .Value);
                    }
                }
            }
            else
            {
                // the shape is defined
                if (xCoordinateField != null && xFieldValue == null &&
                    !errorReadingXValue)
                {
                    // ... but the x field is NULL/empty text
                    if (!AllowMissingXYFieldValueForDefinedShape)
                    {
                        errorCount += ReportMissingFieldValueForDefinedShape(feature,
                                                                             point,
                                                                             xCoordinateField);
                    }
                }

                if (yCoordinateField != null && yFieldValue == null &&
                    !errorReadingYValue)
                {
                    // ... but the y field is NULL/empty text
                    if (!AllowMissingXYFieldValueForDefinedShape)
                    {
                        errorCount += ReportMissingFieldValueForDefinedShape(feature,
                                                                             point,
                                                                             yCoordinateField);
                    }
                }

                double shapeX;
                double shapeY;
                point.QueryCoords(out shapeX, out shapeY);

                if (xFieldValue != null && yFieldValue != null)
                {
                    double xyDistanceSquared = GetDistanceSquared(
                        shapeX, shapeY, xFieldValue.Value, yFieldValue.Value);

                    if (xyDistanceSquared > _xyToleranceSquared)
                    {
                        double xyDistance = Math.Sqrt(xyDistanceSquared);
                        errorCount += ReportXYFieldCoordinatesTooFarFromShape(
                            feature, point, xyDistance,
                            xCoordinateField, xFieldValue.Value, shapeX,
                            yCoordinateField, yFieldValue.Value, shapeY);
                    }
                }
                else if (xFieldValue != null)
                {
                    // y field value is null
                    if (yCoordinateField == null)
                    {
                        // only the x field is specified for the test
                        errorCount += CheckSingleXYFieldCoordinate(
                            feature, point, xCoordinateField, xFieldValue.Value, shapeX,
                            'X');
                    }
                    else if (!errorReadingYValue)
                    {
                        // the y field is defined, but it contains NULL/empty text
                        if (!AllowMissingXYFieldValueForDefinedShape)
                        {
                            errorCount += ReportMissingFieldValueForDefinedShape(
                                feature, point, yCoordinateField);
                        }
                        else
                        {
                            // missing field values are ok, compare what is there
                            errorCount += CheckSingleXYFieldCoordinate(
                                feature, point, xCoordinateField, xFieldValue.Value,
                                shapeX, 'X');
                        }
                    }
                }
                else if (yFieldValue != null)
                {
                    // x field value is null
                    if (xCoordinateField == null)
                    {
                        // only the y field is specified for the test
                        errorCount += CheckSingleXYFieldCoordinate(
                            feature, point, yCoordinateField, yFieldValue.Value, shapeY,
                            'Y');
                    }
                    else if (!errorReadingXValue)
                    {
                        // the x field is defined, but it contains NULL/empty text
                        if (!AllowMissingXYFieldValueForDefinedShape)
                        {
                            errorCount += ReportMissingFieldValueForDefinedShape(
                                feature, point, xCoordinateField);
                        }
                        else
                        {
                            // missing field values are ok, compare what is there
                            errorCount += CheckSingleXYFieldCoordinate(
                                feature, point, yCoordinateField, yFieldValue.Value,
                                shapeY, 'Y');
                        }
                    }
                }
            }

            return(errorCount);
        }