/// <summary>
 /// Update the IM with the contribution for the EdgeStubs around the node.
 /// </summary>
 /// <param name="im"></param>
 public void UpdateIM(IntersectionMatrix im)
 {
     for (IEnumerator it = GetEnumerator(); it.MoveNext(); ) 
     {
         EdgeEndBundle esb = (EdgeEndBundle) it.Current;
         esb.UpdateIM(im);
     }
 }
        public void TestToString()
        {
            IntersectionMatrix i = new IntersectionMatrix();
            i.Set("012*TF012");
            Assert.AreEqual("012*TF012", i.ToString());

            IntersectionMatrix c = new IntersectionMatrix(i);
            Assert.AreEqual("012*TF012", c.ToString());
        }
Beispiel #3
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), Dimensions.Curve);
     if (label.IsArea())
     {
         im.SetAtLeastIfValid(label.GetLocation(0, Positions.Left), label.GetLocation(1, Positions.Left), Dimensions.Surface);
         im.SetAtLeastIfValid(label.GetLocation(0, Positions.Right), label.GetLocation(1, Positions.Right), Dimensions.Surface);
     }
 }
 /// <summary>
 /// Adds one matrix to another.
 /// Addition is defined by taking the maximum dimension value of each position
 /// in the summand matrices.
 /// </summary>
 /// <param name="im">The matrix to add.</param>
 public void Add(IntersectionMatrix im)
 {
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 3; j++)
         {
             SetAtLeast((Location)i, (Location)j, im.Get((Location)i, (Location)j));
         }
     }
 }
Beispiel #5
0
 /// <summary>
 /// Creates an <see cref="IntersectionMatrix" /> with the same elements as
 /// <c>other</c>.
 /// </summary>
 /// <param name="other">An <see cref="IntersectionMatrix" /> to copy.</param>
 public IntersectionMatrix(IntersectionMatrix other) : this()
 {
     matrix[(int)Locations.Interior, (int)Locations.Interior] = other.matrix[(int)Locations.Interior, (int)Locations.Interior];
     matrix[(int)Locations.Interior, (int)Locations.Boundary] = other.matrix[(int)Locations.Interior, (int)Locations.Boundary];
     matrix[(int)Locations.Interior, (int)Locations.Exterior] = other.matrix[(int)Locations.Interior, (int)Locations.Exterior];
     matrix[(int)Locations.Boundary, (int)Locations.Interior] = other.matrix[(int)Locations.Boundary, (int)Locations.Interior];
     matrix[(int)Locations.Boundary, (int)Locations.Boundary] = other.matrix[(int)Locations.Boundary, (int)Locations.Boundary];
     matrix[(int)Locations.Boundary, (int)Locations.Exterior] = other.matrix[(int)Locations.Boundary, (int)Locations.Exterior];
     matrix[(int)Locations.Exterior, (int)Locations.Interior] = other.matrix[(int)Locations.Exterior, (int)Locations.Interior];
     matrix[(int)Locations.Exterior, (int)Locations.Boundary] = other.matrix[(int)Locations.Exterior, (int)Locations.Boundary];
     matrix[(int)Locations.Exterior, (int)Locations.Exterior] = other.matrix[(int)Locations.Exterior, (int)Locations.Exterior];
 }
        public void TestTranspose()
        {
            IntersectionMatrix x = new IntersectionMatrix("012*TF012");

            IntersectionMatrix i = new IntersectionMatrix(x);
            IntersectionMatrix j = i.Transpose();
            Assert.AreSame(i, j);

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

            Assert.AreEqual("012*TF012", x.ToString());
        }
Beispiel #7
0
 /// <summary> 
 /// Creates an <see cref="IntersectionMatrix" /> with the same elements as
 /// <c>other</c>.
 /// </summary>
 /// <param name="other">An <see cref="IntersectionMatrix" /> to copy.</param>         
 public IntersectionMatrix(IntersectionMatrix other) : this()
 {
     matrix[(int) Locations.Interior, (int)Locations.Interior] = other.matrix[(int) Locations.Interior, (int) Locations.Interior];
     matrix[(int) Locations.Interior, (int)Locations.Boundary] = other.matrix[(int) Locations.Interior, (int) Locations.Boundary];
     matrix[(int) Locations.Interior, (int)Locations.Exterior] = other.matrix[(int) Locations.Interior, (int) Locations.Exterior];
     matrix[(int) Locations.Boundary, (int)Locations.Interior] = other.matrix[(int) Locations.Boundary, (int) Locations.Interior];
     matrix[(int) Locations.Boundary, (int)Locations.Boundary] = other.matrix[(int) Locations.Boundary, (int) Locations.Boundary];
     matrix[(int) Locations.Boundary, (int)Locations.Exterior] = other.matrix[(int) Locations.Boundary, (int) Locations.Exterior];
     matrix[(int) Locations.Exterior, (int)Locations.Interior] = other.matrix[(int) Locations.Exterior, (int) Locations.Interior];
     matrix[(int) Locations.Exterior, (int)Locations.Boundary] = other.matrix[(int) Locations.Exterior, (int) Locations.Boundary];
     matrix[(int) Locations.Exterior, (int)Locations.Exterior] = other.matrix[(int) Locations.Exterior, (int) Locations.Exterior];
 }
 /// <summary>
 /// Creates an <see cref="IntersectionMatrix" /> with the same elements as
 /// <c>other</c>.
 /// </summary>
 /// <param name="other">An <see cref="IntersectionMatrix" /> to copy.</param>
 public IntersectionMatrix(IntersectionMatrix other)
     : this()
 {
     _matrix[(int)Location.Interior, (int)Location.Interior] = other._matrix[(int)Location.Interior, (int)Location.Interior];
     _matrix[(int)Location.Interior, (int)Location.Boundary] = other._matrix[(int)Location.Interior, (int)Location.Boundary];
     _matrix[(int)Location.Interior, (int)Location.Exterior] = other._matrix[(int)Location.Interior, (int)Location.Exterior];
     _matrix[(int)Location.Boundary, (int)Location.Interior] = other._matrix[(int)Location.Boundary, (int)Location.Interior];
     _matrix[(int)Location.Boundary, (int)Location.Boundary] = other._matrix[(int)Location.Boundary, (int)Location.Boundary];
     _matrix[(int)Location.Boundary, (int)Location.Exterior] = other._matrix[(int)Location.Boundary, (int)Location.Exterior];
     _matrix[(int)Location.Exterior, (int)Location.Interior] = other._matrix[(int)Location.Exterior, (int)Location.Interior];
     _matrix[(int)Location.Exterior, (int)Location.Boundary] = other._matrix[(int)Location.Exterior, (int)Location.Boundary];
     _matrix[(int)Location.Exterior, (int)Location.Exterior] = other._matrix[(int)Location.Exterior, (int)Location.Exterior];
 }
Beispiel #9
0
 /// <summary> 
 /// Creates an <see cref="IntersectionMatrix" /> with the same elements as
 /// <c>other</c>.
 /// </summary>
 /// <param name="other">An <see cref="IntersectionMatrix" /> to copy.</param>         
 public IntersectionMatrix(IntersectionMatrix other)
     : this()
 {
     _matrix[(int)Location.Interior, (int)Location.Interior] = other._matrix[(int)Location.Interior, (int)Location.Interior];
     _matrix[(int)Location.Interior, (int)Location.Boundary] = other._matrix[(int)Location.Interior, (int)Location.Boundary];
     _matrix[(int)Location.Interior, (int)Location.Exterior] = other._matrix[(int)Location.Interior, (int)Location.Exterior];
     _matrix[(int)Location.Boundary, (int)Location.Interior] = other._matrix[(int)Location.Boundary, (int)Location.Interior];
     _matrix[(int)Location.Boundary, (int)Location.Boundary] = other._matrix[(int)Location.Boundary, (int)Location.Boundary];
     _matrix[(int)Location.Boundary, (int)Location.Exterior] = other._matrix[(int)Location.Boundary, (int)Location.Exterior];
     _matrix[(int)Location.Exterior, (int)Location.Interior] = other._matrix[(int)Location.Exterior, (int)Location.Interior];
     _matrix[(int)Location.Exterior, (int)Location.Boundary] = other._matrix[(int)Location.Exterior, (int)Location.Boundary];
     _matrix[(int)Location.Exterior, (int)Location.Exterior] = other._matrix[(int)Location.Exterior, (int)Location.Exterior];
 }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public 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(Location.Exterior, Location.Exterior, Dimension.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<EdgeEnd> ee0 = eeBuilder.ComputeEdgeEnds(_arg[0].Edges);
            InsertEdgeEnds(ee0);
            IList<EdgeEnd> ee1 = eeBuilder.ComputeEdgeEnds(_arg[1].Edges);
            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;
        }
 /// <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);
     }
 }
 /// <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(Location.Interior, Location.Exterior, ga.Dimension);
         im.Set(Location.Boundary, Location.Exterior, ga.BoundaryDimension);
     }
     IGeometry gb = _arg[1].Geometry;
     if (!gb.IsEmpty)
     {
         im.Set(Location.Exterior, Location.Interior, gb.Dimension);
         im.Set(Location.Exterior, Location.Boundary, gb.BoundaryDimension);    
     }
 }
        /// <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.
            Dimension dimA = _arg[0].Geometry.Dimension;
            Dimension 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 == Dimension.Surface && dimB == Dimension.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 == Dimension.Surface && dimB == Dimension.Curve)
            {
                if (hasProper) 
                    im.SetAtLeast("FFF0FFFF2");
                if (hasProperInterior) 
                    im.SetAtLeast("1FFFFF1FF");
            }

            else if (dimA == Dimension.Curve && dimB == Dimension.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 == Dimension.Curve && dimB == Dimension.Curve)
            {
                if (hasProperInterior)
                    im.SetAtLeast("0FFFFFFFF");
            }
        }
Beispiel #14
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;
 }
Beispiel #15
0
 /// <summary>
 /// Update the IM with the contribution for the computed label for the EdgeStubs.
 /// </summary>
 /// <param name="im"></param>
 public void UpdateIM(IntersectionMatrix im)
 {
     Edge.UpdateIM(label, im);
 }
Beispiel #16
0
 /// <summary>
 /// Tests if each of the actual dimension symbols in a matrix string satisfies the
 /// corresponding required dimension symbol in a pattern string.
 /// </summary>
 /// <param name="actualDimensionSymbols">
 /// Nine dimension symbols to validate.
 /// Possible values are <c>T, F, * , 0, 1, 2</c>.
 /// </param>
 /// <param name="requiredDimensionSymbols">
 /// Nine dimension symbols to validate
 /// against. Possible values are <c>T, F, * , 0, 1, 2</c>.
 /// </param>
 /// <returns>
 /// <c>true</c> if each of the required dimension
 /// symbols encompass the corresponding actual dimension symbol.
 /// </returns>
 public static bool Matches(string actualDimensionSymbols, string requiredDimensionSymbols)
 {
     IntersectionMatrix m = new IntersectionMatrix(actualDimensionSymbols);
     return m.Matches(requiredDimensionSymbols);
 }
Beispiel #17
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);
 }
 /// <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), Dimension.Point);
 }
 /// <summary>
 /// Update the IM with the contribution for the EdgeEnds incident on this node.
 /// </summary>
 /// <param name="im"></param>
 public void UpdateIMFromEdges(IntersectionMatrix im)
 {
     ((EdgeEndBundleStar) Edges).UpdateIM(im);
 }
 /// <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);
 }
Beispiel #21
0
        /// <summary>
        /// Tests if each of the actual dimension symbols in a matrix string satisfies the
        /// corresponding required dimension symbol in a pattern string.
        /// </summary>
        /// <param name="actualDimensionSymbols">
        /// Nine dimension symbols to validate.
        /// Possible values are <c>T, F, * , 0, 1, 2</c>.
        /// </param>
        /// <param name="requiredDimensionSymbols">
        /// Nine dimension symbols to validate
        /// against. Possible values are <c>T, F, * , 0, 1, 2</c>.
        /// </param>
        /// <returns>
        /// <c>true</c> if each of the required dimension
        /// symbols encompass the corresponding actual dimension symbol.
        /// </returns>
        public static bool Matches(string actualDimensionSymbols, string requiredDimensionSymbols)
        {
            IntersectionMatrix m = new IntersectionMatrix(actualDimensionSymbols);

            return(m.Matches(requiredDimensionSymbols));
        }
Beispiel #22
0
 /// <summary> 
 /// Adds one matrix to another.
 /// Addition is defined by taking the maximum dimension value of each position
 /// in the summand matrices.
 /// </summary>
 /// <param name="im">The matrix to add.</param>        
 public void Add(IntersectionMatrix im)
 {
     for (int i = 0; i < 3; i++)
         for (int j = 0; j < 3; j++)
             SetAtLeast((Location)i, (Location)j, im.Get((Location)i, (Location)j));
 }
Beispiel #23
0
 /// <summary>
 /// Compute the contribution to an IM for this component.
 /// </summary>
 abstract public void ComputeIM(IntersectionMatrix im);
Beispiel #24
0
 /// <summary>
 /// Basic nodes do not compute IMs.
 /// </summary>
 /// <param name="im"></param>
 public override void ComputeIM(IntersectionMatrix im)
 {
 }
Beispiel #25
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 void UpdateIM(IntersectionMatrix im)
 {
     Assert.IsTrue(label.GeometryCount >= 2, "found partial label");
     ComputeIM(im);
 }
Beispiel #26
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);
     }
 }