Example #1
0
        /// <summary>
        /// Static method used to calculate the intersection matrix.  This is the same as instantiating the RelateOp object and calling the
        /// GetIntersectionMatrix method.
        /// </summary>
        /// <param name="a">Geometry a to be used in the relation computation.</param>
        /// <param name="b">Geometry b to be used in the relation computation.</param>
        /// <returns>Returns the Intersection Matrix.</returns>
        public static IntersectionMatrix Relate(Geometry a, Geometry b)
        {
            RelateOp           relOp = new RelateOp(a, b);
            IntersectionMatrix im    = relOp.GetIntersectionMatrix();

            return(im);
        }
Example #2
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)));
        }
Example #3
0
 /// <summary>
 /// Update the IM with the contribution for the EdgeStubs around the node.
 /// </summary>
 /// <param name="im"></param>
 public void UpdateIM(IntersectionMatrix im)
 {
     foreach (EdgeEndBundle esb in Edges)
     {
         esb.UpdateIM(im);
     }
 }
Example #4
0
        /// <summary>
        /// Computes the <see cref="IntersectionMatrix"/> for the spatial relationship
        ///  between two <see cref="IGeometry"/>s, using the specified Boundary Node Rule
        /// </summary>
        /// <param name="a">A geometry to test</param>
        /// <param name="b">A geometry to test</param>
        /// <param name="boundaryNodeRule">The Boundary Node Rule to use</param>
        /// <returns>The <c>IntersectionMatrix</c> for the spatial relationship between the geometries</returns>
        public static IntersectionMatrix Relate(IGeometry a, IGeometry b, IBoundaryNodeRule boundaryNodeRule)
        {
            RelateOp           relOp = new RelateOp(a, b, boundaryNodeRule);
            IntersectionMatrix im    = relOp.IntersectionMatrix;

            return(im);
        }
Example #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));
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static IntersectionMatrix Relate(IGeometry a, IGeometry b)
        {
            RelateOp           relOp = new RelateOp(a, b);
            IntersectionMatrix im    = relOp.IntersectionMatrix;

            return(im);
        }
Example #7
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
        }
Example #8
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
        }
Example #9
0
        public void CanGetCellConstraints()
        {
            const string matrixString = "T012F*21T";

            var matrix = new IntersectionMatrix(matrixString);

            Assert.AreEqual(IntersectionConstraint.MustIntersect,
                            matrix.GetConstraint(PointSet.Interior, PointSet.Interior));
            Assert.AreEqual(IntersectionConstraint.MustIntersectWithMaxDimension0,
                            matrix.GetConstraint(PointSet.Interior, PointSet.Boundary));
            Assert.AreEqual(IntersectionConstraint.MustIntersectWithMaxDimension1,
                            matrix.GetConstraint(PointSet.Interior, PointSet.Exterior));

            Assert.AreEqual(IntersectionConstraint.MustIntersectWithMaxDimension2,
                            matrix.GetConstraint(PointSet.Boundary, PointSet.Interior));
            Assert.AreEqual(IntersectionConstraint.MustNotIntersect,
                            matrix.GetConstraint(PointSet.Boundary, PointSet.Boundary));
            Assert.AreEqual(IntersectionConstraint.NotChecked,
                            matrix.GetConstraint(PointSet.Boundary, PointSet.Exterior));

            Assert.AreEqual(IntersectionConstraint.MustIntersectWithMaxDimension2,
                            matrix.GetConstraint(PointSet.Exterior, PointSet.Interior));
            Assert.AreEqual(IntersectionConstraint.MustIntersectWithMaxDimension1,
                            matrix.GetConstraint(PointSet.Exterior, PointSet.Boundary));
            Assert.AreEqual(IntersectionConstraint.MustIntersect,
                            matrix.GetConstraint(PointSet.Exterior, PointSet.Exterior));
        }
Example #10
0
        private void AssertNtsConsistentRelate(IShape shape)
        {
            IntersectionMatrix expectedM  = POLY_SHAPE.Geometry.Relate(((NtsSpatialContext)ctx).GetGeometryFrom(shape));
            SpatialRelation    expectedSR = NtsGeometry.IntersectionMatrixToSpatialRelation(expectedM);

            //NTS considers a point on a boundary INTERSECTS, not CONTAINS
            if (expectedSR == SpatialRelation.INTERSECTS && shape is Core.Shapes.IPoint)
            {
                expectedSR = SpatialRelation.CONTAINS;
            }
            AssertRelation(null, expectedSR, POLY_SHAPE, shape);

            if (ctx.IsGeo)
            {
                //shift shape, set to shape2
                IShape shape2;
                if (shape is IRectangle)
                {
                    IRectangle r = (IRectangle)shape;
                    shape2 = MakeNormRect(r.MinX + DL_SHIFT, r.MaxX + DL_SHIFT, r.MinY, r.MaxY);
                }
                else if (shape is Core.Shapes.IPoint)
                {
                    Core.Shapes.IPoint p = (Core.Shapes.IPoint)shape;
                    shape2 = ctx.MakePoint(base.NormX(p.X + DL_SHIFT), p.Y);
                }
                else
                {
                    throw new Exception("" + shape);
                }

                AssertRelation(null, expectedSR, POLY_SHAPE_DL, shape2);
            }
        }
Example #11
0
 /// <summary>
 /// Update the IM with the contribution for the EdgeStubs around the node.
 /// </summary>
 /// <param name="im"></param>
 public virtual void UpdateIm(IntersectionMatrix im)
 {
     for (IEnumerator it = GetEnumerator(); it.MoveNext();)
     {
         EdgeEndBundle esb = (EdgeEndBundle)it.Current;
         esb.UpdateIm(im);
     }
 }
Example #12
0
 /// <summary>
 /// Update the IM with the contribution for this component.  A component only contributes
 /// if it has a labeling for both parent geometries.
 /// </summary>
 /// <param name="im"></param>
 public void UpdateIM(IntersectionMatrix im)
 {
     if (_label.GetGeometryCount() < 2)
     {
         throw new InvalidOperationException("Found partial label.");
     }
     ComputeIM(im);
 }
 /// <summary>
 /// Update the IM with the contribution for the EdgeStubs around the node.
 /// </summary>
 /// <param name="im"></param>
 public virtual void UpdateIm(IntersectionMatrix im)
 {
     for (IEnumerator it = GetEnumerator(); it.MoveNext(); )
     {
         EdgeEndBundle esb = (EdgeEndBundle)it.Current;
         esb.UpdateIm(im);
     }
 }
Example #14
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="intersector"></param>
        /// <param name="im"></param>
        private void ComputeProperIntersectionIM(SegmentIntersector intersector, IntersectionMatrix im)
        {
            // If a proper intersection is found, we can set a lower bound on the IM.
            Dimensions dimA = arg[0].Geometry.Dimension;
            Dimensions dimB = arg[1].Geometry.Dimension;
            bool hasProper = intersector.HasProperIntersection;
            bool hasProperInterior = intersector.HasProperInteriorIntersection;

            // For Geometry's of dim 0 there can never be proper intersections.
            /*
             * If edge segments of Areas properly intersect, the areas must properly overlap.
             */
            if (dimA == Dimensions.Surface && dimB == Dimensions.Surface)
            {
                if (hasProper) 
                    im.SetAtLeast("212101212");
            }

            /*
             * If an Line segment properly intersects an edge segment of an Area,
             * it follows that the Interior of the Line intersects the Boundary of the Area.
             * If the intersection is a proper <i>interior</i> intersection, then
             * there is an Interior-Interior intersection too.
             * Note that it does not follow that the Interior of the Line intersects the Exterior
             * of the Area, since there may be another Area component which contains the rest of the Line.
             */
            else if (dimA == Dimensions.Surface && dimB == Dimensions.Curve)
            {
                if (hasProper) 
                    im.SetAtLeast("FFF0FFFF2");
                if (hasProperInterior) 
                    im.SetAtLeast("1FFFFF1FF");
            }

            else if (dimA == Dimensions.Curve && dimB == Dimensions.Surface)
            {
                if (hasProper) 
                    im.SetAtLeast("F0FFFFFF2");
                if (hasProperInterior)
                    im.SetAtLeast("1F1FFFFFF");
            }

            /* If edges of LineStrings properly intersect *in an interior point*, all
               we can deduce is that
               the interiors intersect.  (We can NOT deduce that the exteriors intersect,
               since some other segments in the geometries might cover the points in the
               neighbourhood of the intersection.)
               It is important that the point be known to be an interior point of
               both Geometries, since it is possible in a self-intersecting point to
               have a proper intersection on one segment that is also a boundary point of another segment.
            */
            else if (dimA == Dimensions.Curve && dimB == Dimensions.Curve)
            {
                if (hasProperInterior)
                    im.SetAtLeast("0FFFFFFFF");
            }
        }
Example #15
0
 /// <summary>
 /// Updates an IM from the label for an edge.
 /// Handles edges from both L and A geometries.
 /// </summary>
 /// <param name="im"></param>
 /// <param name="label"></param>
 public static void UpdateIM(Label label, IntersectionMatrix im)
 {
     im.SetAtLeastIfValid(label.GetLocation(0, Positions.On), label.GetLocation(1, Positions.On), Dimension.Curve);
     if (label.IsArea())
     {
         im.SetAtLeastIfValid(label.GetLocation(0, Positions.Left), label.GetLocation(1, Positions.Left), Dimension.Surface);
         im.SetAtLeastIfValid(label.GetLocation(0, Positions.Right), label.GetLocation(1, Positions.Right), Dimension.Surface);
     }
 }
Example #16
0
 /// <summary>
 /// Updates an IM from the label for an edge. Handles edges from both L and A geometrys.
 /// </summary>
 /// <param name="label"></param>
 /// <param name="im"></param>
 public static void UpdateIM(Label label, IntersectionMatrix im)
 {
     im.SetAtLeastIfValid(label.GetLocation(0, Position.On), label.GetLocation(1, Position.On), 1);
     if (label.IsArea())
     {
         im.SetAtLeastIfValid(label.GetLocation(0, Position.Left), label.GetLocation(1, Position.Left), 2);
         im.SetAtLeastIfValid(label.GetLocation(0, Position.Right), label.GetLocation(1, Position.Right), 2);
     }
 }         // public static void UpdateIM(Label label, IntersectionMatrix im)
Example #17
0
        }         // public override void Insert( EdgeEnd e )

        /// <summary>
        /// Update the IM with the contribution for the EdgeStubs around the node.
        /// </summary>
        /// <param name="im"></param>
        public void UpdateIM(IntersectionMatrix im)
        {
            ArrayList edges = Edges();

            foreach (object obj in edges)
            {
                EdgeEndBundle esb = (EdgeEndBundle)obj;
                esb.UpdateIM(im);
            }
        }         // void UpdateIM( IntersectionMatrix im )
        void RunRelateTest(String wkt1, String wkt2, IBoundaryNodeRule bnRule, String expectedIM)
        {
            IGeometry          g1    = rdr.Read(wkt1);
            IGeometry          g2    = rdr.Read(wkt2);
            IntersectionMatrix im    = RelateOp.Relate(g1, g2, bnRule);
            String             imStr = im.ToString();

            Console.WriteLine(imStr);
            Assert.IsTrue(im.Matches(expectedIM));
        }
Example #19
0
 /// <summary>
 /// Updates an IM from the label for an edge.
 /// Handles edges from both L and A geometries.
 /// </summary>
 /// <param name="label"></param>
 /// <param name="im"></param>
 public static void UpdateIm(Label label, IntersectionMatrix im)
 {
     im.SetAtLeastIfValid(label.GetLocation(0, PositionType.On), label.GetLocation(1, PositionType.On), DimensionType.Curve);
     if (!label.IsArea())
     {
         return;
     }
     im.SetAtLeastIfValid(label.GetLocation(0, PositionType.Left), label.GetLocation(1, PositionType.Left), DimensionType.Surface);
     im.SetAtLeastIfValid(label.GetLocation(0, PositionType.Right), label.GetLocation(1, PositionType.Right), DimensionType.Surface);
 }
        public void TestToString()
        {
            var i = new IntersectionMatrix();

            i.Set("012*TF012");
            Assert.AreEqual("012*TF012", i.ToString());

            var c = new IntersectionMatrix(i);

            Assert.AreEqual("012*TF012", c.ToString());
        }
Example #21
0
 /// <summary>
 /// Update the IM with the sum of the IMs for each component.
 /// </summary>
 /// <param name="im"></param>
 private void UpdateIM(IntersectionMatrix im)
 {
     foreach (Edge e in _isolatedEdges)
     {
         e.UpdateIM(im);
     }
     foreach (RelateNode node in _nodes)
     {
         node.UpdateIM(im);
         node.UpdateIMFromEdges(im);
     }
 }
        protected QaSpatialRelationBase([NotNull] IList <IFeatureClass> featureClasses,
                                        [NotNull] string intersectionMatrix)
            : this(featureClasses, esriSpatialRelEnum.esriSpatialRelRelation)
        {
            Assert.ArgumentNotNullOrEmpty(intersectionMatrix, nameof(intersectionMatrix));

            IntersectionMatrix    = new IntersectionMatrix(intersectionMatrix);
            UsesSymmetricRelation = IntersectionMatrix.Symmetric;

            _disjointIsError = !IntersectionMatrix.Intersects &&
                               IntersectionMatrix.IntersectsExterior;
        }
        public void TestTranspose()
        {
            var x = new IntersectionMatrix("012*TF012");

            var i = new IntersectionMatrix(x);
            var j = i.Transpose();

            Assert.AreSame(i, j);

            Assert.AreEqual("0*01T12F2", i.ToString());

            Assert.AreEqual("012*TF012", x.ToString());
        }
Example #24
0
 /// <summary>
 /// Update the IM with the sum of the IMs for each component.
 /// </summary>
 /// <param name="im"></param>
 private void UpdateIM(IntersectionMatrix im)
 {
     for (IEnumerator ei = isolatedEdges.GetEnumerator(); ei.MoveNext();)
     {
         Edge e = (Edge)ei.Current;
         e.UpdateIM(im);
     }
     for (IEnumerator ni = nodes.GetEnumerator(); ni.MoveNext();)
     {
         RelateNode node = (RelateNode)ni.Current;
         node.UpdateIM(im);
         node.UpdateIMFromEdges(im);
     }
 }
Example #25
0
 /// <summary>
 /// If the Geometries are disjoint, we need to enter their dimension and
 /// boundary dimension in the Ext rows in the IM
 /// </summary>
 /// <param name="im"></param>
 private void ComputeDisjointIM(IntersectionMatrix im)
 {
     IGeometry ga = arg[0].Geometry;
     if (!ga.IsEmpty)
     {
         im.Set(Locations.Interior, Locations.Exterior, ga.Dimension);
         im.Set(Locations.Boundary, Locations.Exterior, ga.BoundaryDimension);
     }
     IGeometry gb = arg[1].Geometry;
     if (!gb.IsEmpty)
     {
         im.Set(Locations.Exterior, Locations.Interior, gb.Dimension);
         im.Set(Locations.Exterior, Locations.Boundary, gb.BoundaryDimension);    
     }
 }
Example #26
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));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="IntersectionMatrixHelper" /> class.
        /// </summary>
        /// <param name="intersectionMatrix">The intersection matrix.</param>
        /// <param name="validRelationConstraint">The match constraint. If the constraint is defined and fulfilled
        /// for a given row pair that matches the intersection matrix, then no error is reported.</param>
        /// <param name="constraintIsDirected">if set to <c>true</c> the constraint is directed,
        /// i.e. row1/row2 only maps to G1/G2 and not also to G2/G1.</param>
        /// <param name="validIntersectionDimensions">The valid intersection dimensions.</param>
        /// <param name="constraintIsCaseSensitive">Indicates if the constraint is case sensitive</param>
        /// <param name="intersectionGeometryConstraint">The intersection geometry constraint.</param>
        public IntersectionMatrixHelper(
            [NotNull] IntersectionMatrix intersectionMatrix,
            [CanBeNull] string validRelationConstraint = null,
            bool constraintIsDirected = false,
            [CanBeNull] ICollection <esriGeometryDimension> validIntersectionDimensions = null,
            bool constraintIsCaseSensitive = false,
            GeometryConstraint intersectionGeometryConstraint = null)
            : base(validRelationConstraint, constraintIsDirected, false,
                   constraintIsCaseSensitive)
        {
            Assert.ArgumentNotNull(intersectionMatrix, nameof(intersectionMatrix));

            _intersectionMatrix             = intersectionMatrix;
            _validIntersectionDimensions    = validIntersectionDimensions;
            _intersectionGeometryConstraint = intersectionGeometryConstraint;
        }
Example #28
0
 public static SpatialRelation IntersectionMatrixToSpatialRelation(IntersectionMatrix matrix)
 {
     if (matrix.IsContains())
     {
         return(SpatialRelation.CONTAINS);
     }
     else if (matrix.IsWithin() /* TODO needs to be matrix.IsCoveredBy()*/)
     {
         return(SpatialRelation.WITHIN);
     }
     else if (matrix.IsDisjoint())
     {
         return(SpatialRelation.DISJOINT);
     }
     return(SpatialRelation.INTERSECTS);
 }
Example #29
0
        }         // private void LabelIntersectionNodes( int argIndex )

        /// <summary>
        /// If the Geometries are disjoint, we need to enter their dimension and
        /// boundary dimension in the Ext rows in the IM.
        /// </summary>
        /// <param name="im"></param>
        private void ComputeDisjointIM(IntersectionMatrix im)
        {
            Geometry ga = _arg[0].Geometry;

            if (!ga.IsEmpty())
            {
                im.Set(Location.Interior, Location.Exterior, ga.GetDimension());
                im.Set(Location.Boundary, Location.Exterior, ga.GetBoundaryDimension());
            }
            Geometry gb = _arg[1].Geometry;

            if (!gb.IsEmpty())
            {
                im.Set(Location.Exterior, Location.Interior, gb.GetDimension());
                im.Set(Location.Exterior, Location.Boundary, gb.GetBoundaryDimension());
            }
        }         // private void ComputeDisjointIM( IntersectionMatrix im )
Example #30
0
 public static SpatialRelation IntersectionMatrixToSpatialRelation(IntersectionMatrix matrix)
 {
     //As indicated in SpatialRelation javadocs, Spatial4j CONTAINS & WITHIN are
     // OGC's COVERS & COVEREDBY
     if (matrix.IsCovers())
     {
         return(SpatialRelation.CONTAINS);
     }
     else if (matrix.IsCoveredBy())
     {
         return(SpatialRelation.WITHIN);
     }
     else if (matrix.IsDisjoint())
     {
         return(SpatialRelation.DISJOINT);
     }
     return(SpatialRelation.INTERSECTS);
 }
Example #31
0
        }         // private void LabelNodeEdges()

        /// <summary>
        /// Update the IM with the sum of the IMs for each component.
        /// </summary>
        /// <param name="im"></param>
        private void UpdateIM(IntersectionMatrix im)
        {
            //Trace.WriteLine( im.ToString() );
            foreach (object obj in _isolatedEdges)
            {
                Edge e = (Edge)obj;
                e.UpdateIM(im);
                //Trace.WriteLine( im.ToString() );
            }             // foreach ( object obj in _isolatedEdges )

            foreach (DictionaryEntry entry in _nodes)
            {
                RelateNode node = (RelateNode)entry.Value;
                node.UpdateIM(im);
                //Trace.WriteLine( im.ToString() );
                node.UpdateIMFromEdges(im);
                //Trace.WriteLine( im.ToString() );
                //Trace.WriteLine( node.ToString() );
            }     // foreach ( object obj in _nodes )
        }         // private void UpdateIM( IntersectionMatrix im )
Example #32
0
 /// <summary>
 /// Update the IM with the contribution for the computed label for the EdgeStubs.
 /// </summary>
 /// <param name="im"></param>
 public virtual void UpdateIm(IntersectionMatrix im)
 {
     Edge.UpdateIm(Label, im);
 }
Example #33
0
 /// <summary>
 /// Basic nodes do not compute IMs.
 /// </summary>
 /// <param name="im"></param>
 public override void ComputeIm(IntersectionMatrix im) { }
Example #34
0
 /// <summary>
 /// Update the IM with the sum of the IMs for each component.
 /// </summary>
 /// <param name="im"></param>
 private void UpdateIm(IntersectionMatrix im)
 {
     for (IEnumerator ei = _isolatedEdges.GetEnumerator(); ei.MoveNext(); )
     {
         Edge e = (Edge)ei.Current;
         e.UpdateIm(im);
     }
     for (IEnumerator ni = _nodes.GetEnumerator(); ni.MoveNext(); )
     {
         RelateNode node = (RelateNode)ni.Current;
         node.UpdateIm(im);
         node.UpdateImFromEdges(im);
     }
 }
Example #35
0
 /// <summary>
 /// Updates an IM from the label for an edge.
 /// Handles edges from both L and A geometries.
 /// </summary>
 /// <param name="label"></param>
 /// <param name="im"></param>
 public static void UpdateIm(Label label, IntersectionMatrix im)
 {
     im.SetAtLeastIfValid(label.GetLocation(0, PositionType.On), label.GetLocation(1, PositionType.On), DimensionType.Curve);
     if (!label.IsArea()) return;
     im.SetAtLeastIfValid(label.GetLocation(0, PositionType.Left), label.GetLocation(1, PositionType.Left), DimensionType.Surface);
     im.SetAtLeastIfValid(label.GetLocation(0, PositionType.Right), label.GetLocation(1, PositionType.Right), DimensionType.Surface);
 }
Example #36
0
 /// <summary>
 /// Update the IM with the contribution for this component.
 /// A component only contributes if it has a labelling for both parent geometries.
 /// </summary>
 /// <param name="im"></param>
 public override void ComputeIm(IntersectionMatrix im)
 {
     UpdateIm(Label, im);
 }
Example #37
0
 /// <summary>
 /// Update the IM with the contribution for this component.
 /// A component only contributes if it has a labelling for both parent geometries.
 /// </summary>
 /// <param name="im"></param>
 public virtual void UpdateIm(IntersectionMatrix im)
 {
     Assert.IsTrue(Label.GeometryCount >= 2, "found partial label");
     ComputeIm(im);
 }
Example #38
0
 /// <summary>
 /// Compute the contribution to an IM for this component.
 /// </summary>
 public abstract void ComputeIm(IntersectionMatrix im);
Example #39
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public virtual IntersectionMatrix ComputeIm()
        {
            IntersectionMatrix im = new IntersectionMatrix();
            // since Geometries are finite and embedded in a 2-D space, the EE element must always be 2
            im.Set(LocationType.Exterior, LocationType.Exterior, DimensionType.Surface);

            // if the Geometries don't overlap there is nothing to do
            if (!_arg[0].Geometry.EnvelopeInternal.Intersects(_arg[1].Geometry.EnvelopeInternal))
            {
                ComputeDisjointIm(im);
                return im;
            }
            _arg[0].ComputeSelfNodes(_li, false);
            _arg[1].ComputeSelfNodes(_li, false);

            // compute intersections between edges of the two input geometries
            SegmentIntersector intersector = _arg[0].ComputeEdgeIntersections(_arg[1], _li, false);
            ComputeIntersectionNodes(0);
            ComputeIntersectionNodes(1);

            /*
             * Copy the labelling for the nodes in the parent Geometries.  These override
             * any labels determined by intersections between the geometries.
             */
            CopyNodesAndLabels(0);
            CopyNodesAndLabels(1);

            // complete the labelling for any nodes which only have a label for a single point
            LabelIsolatedNodes();

            // If a proper intersection was found, we can set a lower bound on the IM.
            ComputeProperIntersectionIm(intersector, im);

            /*
             * Now process improper intersections
             * (eg where one or other of the geometries has a vertex at the intersection point)
             * We need to compute the edge graph at all nodes to determine the IM.
             */

            // build EdgeEnds for all intersections
            EdgeEndBuilder eeBuilder = new EdgeEndBuilder();
            IList ee0 = eeBuilder.ComputeEdgeEnds(_arg[0].GetEdgeEnumerator());
            InsertEdgeEnds(ee0);
            IList ee1 = eeBuilder.ComputeEdgeEnds(_arg[1].GetEdgeEnumerator());
            InsertEdgeEnds(ee1);

            LabelNodeEdges();

            /*
             * Compute the labeling for isolated components
             * <br>
             * Isolated components are components that do not touch any other components in the graph.
             * They can be identified by the fact that they will
             * contain labels containing ONLY a single element, the one for their parent point.
             * We only need to check components contained in the input graphs, since
             * isolated components will not have been replaced by new components formed by intersections.
             */
            LabelIsolatedEdges(0, 1);
            LabelIsolatedEdges(1, 0);

            // update the IM from all components
            UpdateIm(im);
            return im;
        }
Example #40
0
 /// <summary>
 /// Update the IM with the contribution for the EdgeEnds incident on this node.
 /// </summary>
 /// <param name="im"></param>
 public virtual void UpdateImFromEdges(IntersectionMatrix im)
 {
     ((EdgeEndBundleStar)Edges).UpdateIm(im);
 }
Example #41
0
 /// <summary>
 /// Update the IM with the contribution for this component.
 /// A component only contributes if it has a labelling for both parent geometries.
 /// </summary>
 public override void ComputeIm(IntersectionMatrix im)
 {
     im.SetAtLeastIfValid(Label.GetLocation(0), Label.GetLocation(1), DimensionType.Point);
 }