Exemple #1
0
        public void CanGetMultipointPolylineCrossesIntersection()
        {
            var matrix = new IntersectionMatrix("T*T******");

            IMultipoint g1 = GeometryFactory.CreateMultipoint(
                GeometryFactory.CreatePoint(0, 5, 0),
                GeometryFactory.CreatePoint(15, 5, 0));
            IPolyline g2 = GeometryFactory.CreatePolyline(5, 5, 1000, 15, 5, 1000);

            // TODO with the spatial reference assigned, the intersection contains only one point (0,5)
            // without spatial reference, it contains two points (0,5 and 15,5)
            //g1.SpatialReference = _spatialReference;
            //g2.SpatialReference = _spatialReference;

            IList <IGeometry> result12 = matrix.GetIntersections(g1, g2);

            Assert.AreEqual(1, result12.Count);
            Console.WriteLine(GeometryUtils.ToString(result12[0]));
            Assert.AreEqual(2, GeometryUtils.GetPointCount(result12));
            //Assert.IsTrue(SpatialReferenceUtils.AreEqual(_spatialReference,
            //                                             result12[0].SpatialReference));

            IList <IGeometry> result21 = matrix.GetIntersections(g2, g1);

            Assert.AreEqual(1, result21.Count);
            Console.WriteLine(GeometryUtils.ToString(result21[0]));
            Assert.IsTrue(
                GeometryUtils.AreEqualInXY(result21[0],
                                           g2));                 // can't subtract, same as g2
        }
Exemple #2
0
        public void CanGetMultipointPolygonCrossesIntersection()
        {
            var matrix = new IntersectionMatrix("T*T******");

            IMultipoint g1 = GeometryFactory.CreateMultipoint(
                GeometryFactory.CreatePoint(5, 5, 0),
                GeometryFactory.CreatePoint(10, 5, 0),
                GeometryFactory.CreatePoint(15, 5, 0));
            IPolygon g2 = GeometryFactory.CreatePolygon(0, 0, 10, 10, 0);

            g1.SpatialReference = _spatialReference;
            g2.SpatialReference = _spatialReference;

            IList <IGeometry> result12 = matrix.GetIntersections(g1, g2);

            Assert.AreEqual(1, result12.Count);
            Console.WriteLine(GeometryUtils.ToString(result12[0]));
            Assert.AreEqual(2, GeometryUtils.GetPointCount(result12));
            Assert.IsTrue(SpatialReferenceUtils.AreEqual(_spatialReference,
                                                         result12[0].SpatialReference));

            IList <IGeometry> result21 = matrix.GetIntersections(g2, g1);

            Assert.AreEqual(1, result21.Count);
            Console.WriteLine(GeometryUtils.ToString(result21[0]));
            Assert.IsTrue(
                GeometryUtils.AreEqualInXY(result21[0],
                                           g2));                 // can't subtract, same as g2
        }
        private static IEnumerable <IGeometry> GetCrossings([NotNull] IGeometry g1,
                                                            [NotNull] IGeometry g2)
        {
            var polyline1 = g1 as IPolyline;
            var polyline2 = g2 as IPolyline;

            if (polyline1 != null && polyline2 != null)
            {
                // TODO get intersection matrix also?
                // 0********
                // but: dimension restriction needs to be better tested first
                yield return(IntersectionUtils.GetLineCrossings(polyline1, polyline2));
            }
            else
            {
                // TODO for line/polygon it would be more useful to get the
                // locations where the line crosses the polygon boundary (and continues)
                // Probably also for polygon/polygon
                IList <IGeometry> intersections = g1.Dimension <= g2.Dimension
                                                                         ? _crossesMatrixOther.GetIntersections(g1, g2)
                                                                         : _crossesMatrixOther.GetIntersections(g2, g1);

                foreach (IGeometry geometry in intersections)
                {
                    yield return(geometry);
                }
            }
        }
Exemple #4
0
        private bool HasExpectedIntersectionDimensions([NotNull] IGeometry shape,
                                                       [NotNull] IFeature relatedFeature,
                                                       [NotNull] IntersectionMatrix matrix)
        {
            if (_requiredDimensions == null && _unallowedDimensions == null)
            {
                return(true);
            }

            List <esriGeometryDimension> dimensions =
                matrix.GetIntersections(shape, relatedFeature.Shape)
                .Select(intersection => intersection.Dimension)
                .Distinct()
                .ToList();

            // if any of the intersection dimensions is unallowed, then the relation is not valid
            if (_unallowedDimensions != null &&
                dimensions.Any(dimension => _unallowedDimensions.Contains(dimension)))
            {
                return(false);
            }

            // if any of the intersection parts has one of the required dimensions, then the relation is valid
            return(_requiredDimensions != null &&
                   dimensions.Any(dimension => _requiredDimensions.Contains(dimension)));
        }
Exemple #5
0
        public void CanGetBoundaryBoundaryIntersectionLinesAndPoints()
        {
            const string matrixString = "****T****";

            IPolygon g1 = GeometryFactory.CreatePolygon(0, 0, 10, 10, 100);
            IPolygon g2 = GeometryFactory.CreatePolygon(5, 0, 15, 15, 1000);

            g1.SpatialReference = _spatialReference;
            g2.SpatialReference = _spatialReference;

            var matrix = new IntersectionMatrix(matrixString);

            IList <IGeometry> intersections = matrix.GetIntersections(g1, g2);

            WriteGeometries(intersections);

            Assert.AreEqual(2, intersections.Count);

            var polyline = (IPolyline)intersections[0];

            Assert.AreEqual(1, GeometryUtils.GetPartCount(polyline));

            var multipoint = (IMultipoint)intersections[1];

            Assert.AreEqual(1, GeometryUtils.GetPartCount(multipoint));
            Assert.IsTrue(SpatialReferenceUtils.AreEqual(_spatialReference,
                                                         multipoint.SpatialReference));
        }
        private IEnumerable <IGeometry> GetIntersections([NotNull] IFeature feature1,
                                                         [NotNull] IFeature feature2)
        {
            IGeometry g1 = feature1.Shape;
            IGeometry g2 = feature2.Shape;

            return(_intersectionMatrix.GetIntersections(g1, g2));
        }
Exemple #7
0
        public void CanGetInteriorBoundaryIntersections()
        {
            const string matrixString = "*T*******";

            IPolygon  g1     = GeometryFactory.CreatePolygon(0, 0, 10, 10, 100);
            IPolyline g2line = GeometryFactory.CreatePolyline(
                _spatialReference,
                GeometryFactory.CreatePoint(0, 10, 100),                 // start/endpoint touches polygon
                GeometryFactory.CreatePoint(0, 20, 100),
                GeometryFactory
                .CreatePoint(10, 10, 100),                       // next segment touches the polygon
                GeometryFactory
                .CreatePoint(10, 9, 100),                        // next segment is inside the polygon
                GeometryFactory
                .CreatePoint(6, 9, 100),                         // next segment is partly inside the polygon
                GeometryFactory.CreatePoint(6, 11, 100),
                GeometryFactory.CreatePoint(4, 11, 100),
                GeometryFactory.CreatePoint(4, 10, 100),                 // next segment touches polygon
                GeometryFactory.CreatePoint(2, 10, 100),
                GeometryFactory.CreatePoint(2, 11, 100),
                GeometryFactory.CreatePoint(1, 11, 100),
                GeometryFactory
                .CreatePoint(0, 10, 100));                         // start/endpoint touches polygon

            GeometryUtils.MakeZAware(g2line);

            IPolygon g2 = GeometryFactory.CreatePolygon(g2line);

            GeometryUtils.Simplify(g2);

            g1.SpatialReference = _spatialReference;
            g2.SpatialReference = _spatialReference;

            var matrix = new IntersectionMatrix(matrixString);

            IList <IGeometry> intersections = matrix.GetIntersections(g1, g2);

            WriteGeometries(intersections);

            Assert.AreEqual(1, intersections.Count);

            var polyline = (IPolyline)intersections[0];

            Assert.AreEqual(1, GeometryUtils.GetPartCount(polyline));
            Assert.AreEqual(3, GeometryUtils.GetPointCount(polyline));
            Assert.IsTrue(SpatialReferenceUtils.AreEqual(_spatialReference,
                                                         polyline.SpatialReference));
        }
Exemple #8
0
        public void CanGetPolylinePointIntersections()
        {
            const string matrixString = "T********";

            IPoint    g1 = GeometryFactory.CreatePoint(10, 5, 1000);
            IPolyline g2 = GeometryFactory.CreatePolyline(5, 5, 1000, 15, 5, 1000);

            g1.SpatialReference = _spatialReference;
            g2.SpatialReference = _spatialReference;

            var matrix = new IntersectionMatrix(matrixString);

            IList <IGeometry> intersections = matrix.GetIntersections(g1, g2);

            WriteGeometries(intersections);

            Assert.AreEqual(1, intersections.Count);
            Assert.IsTrue(SpatialReferenceUtils.AreEqual(_spatialReference,
                                                         intersections[0]
                                                         .SpatialReference));
        }
Exemple #9
0
        public void CanGetInteriorInteriorPolygon()
        {
            const string matrixString = "T********";

            IPolygon g1 = GeometryFactory.CreatePolygon(0, 0, 10, 10, 100);
            IPolygon g2 = GeometryFactory.CreatePolygon(5, 0, 15, 15, 1000);

            g1.SpatialReference = _spatialReference;
            g2.SpatialReference = _spatialReference;

            var matrix = new IntersectionMatrix(matrixString);

            IList <IGeometry> intersections = matrix.GetIntersections(g1, g2);

            WriteGeometries(intersections);

            Assert.AreEqual(1, intersections.Count);

            var polygon = (IPolygon)intersections[0];

            Assert.AreEqual(1, GeometryUtils.GetPartCount(polygon));
            Assert.IsTrue(SpatialReferenceUtils.AreEqual(_spatialReference,
                                                         polygon.SpatialReference));
        }