Beispiel #1
0
        /// <summary>
        /// returns -1 if neighbourFeature is polygon, geometryComponent is entireGeometry and point lies within neighbourFeature.
        /// otherwise returns distance.
        /// </summary>
        private static double GetDistance([NotNull] IPoint point,
                                          [NotNull] IFeature neighbourFeature,
                                          [NotNull] IPoint nearestPoint,
                                          GeometryComponent geometryComponent,
                                          double maxNeededDistance,
                                          out bool isWithinPolygon,
                                          out bool onRightSide)
        {
            isWithinPolygon = false;
            if (geometryComponent == GeometryComponent.Boundary &&
                neighbourFeature.Shape is IPolygon)
            {
                return(GetDistanceToCurve(point, neighbourFeature, nearestPoint,
                                          maxNeededDistance, out onRightSide));
            }

            if (geometryComponent == GeometryComponent.Vertices)
            {
                onRightSide = false;
                return(GetDistanceToVertices(point, neighbourFeature, nearestPoint,
                                             maxNeededDistance));
            }

            // other cases: create component geometry explicitly
            IGeometry neighbourGeometry =
                Assert.NotNull(GeometryComponentUtils.GetGeometryComponent(
                                   neighbourFeature, geometryComponent));

            if (geometryComponent == GeometryComponent.EntireGeometry &&
                neighbourGeometry is IPolygon)
            {
                if (((IRelationalOperator)neighbourGeometry).Disjoint(point))
                {
                    // the point is outside the polygon - get the distance to the boundary
                    // (faster than getting the distance to the entire polygon)
                    return(GetDistanceToCurve(point, neighbourFeature, nearestPoint,
                                              maxNeededDistance, out onRightSide));
                }

                // the point is inside the polygon or exactly on the boundary
                isWithinPolygon = true;
                onRightSide     = false;             // polygons borders are defined counter clock wise
                return(-1);
            }

            if (geometryComponent == GeometryComponent.EntireGeometry &&
                neighbourGeometry is IPolyline)
            {
                return(GetDistanceToCurve(point, neighbourFeature, nearestPoint,
                                          maxNeededDistance, out onRightSide));
            }

            // Use IProximityOperator.QueryNearestPoint so that the error geometry can be constructed
            ((IProximityOperator)neighbourGeometry).QueryNearestPoint(
                point, esriSegmentExtension.esriNoExtension, nearestPoint);
            onRightSide = false;
            return(((IProximityOperator)point).ReturnDistance(nearestPoint));
        }
Beispiel #2
0
        private int ReportError([NotNull] IFeature pointFeature,
                                [NotNull] IFeature referenceFeature,
                                [NotNull] IPoint point,
                                [NotNull] IPoint nearPoint,
                                double distance,
                                double minimumDistance, bool isWithinPolygon,
                                GeometryComponent geometryComponent,
                                [CanBeNull] IValidRelationConstraint validConstraint)
        {
            IssueCode issueCode;
            string    description;
            IGeometry errorGeometry;

            if (isWithinPolygon)
            {
                description   = "Point lies within polygon";
                errorGeometry = GeometryFactory.Clone(point);

                issueCode = validConstraint == null
                                                    ? Codes[Code.PointWithin]
                                                    : Codes[Code.PointWithin_ConstraintNotFulfilled];
            }
            else
            {
                if (geometryComponent == GeometryComponent.EntireGeometry)
                {
                    description =
                        string.Format(
                            "Point is too close to reference feature: {0}",
                            FormatLengthComparison(distance, "<", minimumDistance,
                                                   _spatialReference));
                }
                else
                {
                    description =
                        string.Format(
                            "Point is too close to {0} of reference feature: {1}",
                            GeometryComponentUtils.GetDisplayText(geometryComponent),
                            FormatLengthComparison(distance, "<", minimumDistance,
                                                   _spatialReference));
                }

                bool reportAsConnectionLine = MinimumErrorLineLength >= 0 &&
                                              distance >= MinimumErrorLineLength;

                errorGeometry =
                    GetErrorGeometry(point, nearPoint, reportAsConnectionLine);

                issueCode = validConstraint == null
                                                    ? Codes[Code.PointTooClose]
                                                    : Codes[Code.PointTooClose_ConstraintNotFulfilled];
            }

            return(ReportError(description, errorGeometry,
                               issueCode, _shapeFieldName,
                               pointFeature, referenceFeature));
        }