Class RelateOp

  1  
  2  
  3  
  4 /*
  5  * Copyright (c) 2016 Vivid Solutions.
  6  *
  7  * All rights reserved. This program and the accompanying materials
  8  * are made available under the terms of the Eclipse Public License 2.0
  9  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 10  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 11  * and the Eclipse Distribution License is available at
 12  *
 13  * http://www.eclipse.org/org/documents/edl-v10.php.
 14  */
 15 package org.locationtech.jts.operation.relate;
 16  
 17 import org.locationtech.jts.algorithm.BoundaryNodeRule;
 18 import org.locationtech.jts.geom.Geometry;
 19 import org.locationtech.jts.geom.IntersectionMatrix;
 20 import org.locationtech.jts.operation.GeometryGraphOperation;
 21  
 22 /**
 23  * Implements the SFS <tt>relate()</tt> generalized spatial predicate on two {@link Geometry}s.
 24  * <p>
 25  * The class supports specifying a custom {@link BoundaryNodeRule}
 26  * to be used during the relate computation.
 27  * <p>
 28  * If named spatial predicates are used on the result {@link IntersectionMatrix}
 29  * of the RelateOp, the result may or not be affected by the 
 30  * choice of <tt>BoundaryNodeRule</tt>, depending on the exact nature of the pattern.
 31  * For instance, {@link IntersectionMatrix#isIntersects()} is insensitive 
 32  * to the choice of <tt>BoundaryNodeRule</tt>, 
 33  * whereas {@link IntersectionMatrix#isTouches(int, int)} is affected by the rule chosen.
 34  * <p>
 35  * <b>Note:</b> custom Boundary Node Rules do not (currently)
 36  * affect the results of other {@link Geometry} methods (such
 37  * as {@link Geometry#getBoundary}.  The results of
 38  * these methods may not be consistent with the relationship computed by
 39  * a custom Boundary Node Rule.
 40  *
 41  * @version 1.7
 42  */
 43 public class RelateOp
 44   extends GeometryGraphOperation
 45 {
 46   /**
 47    * Computes the {@link IntersectionMatrix} for the spatial relationship
 48    * between two {@link Geometry}s, using the default (OGC SFS) Boundary Node Rule
 49    *
 50    * @param a a Geometry to test
 51    * @param b a Geometry to test
 52    * @return the IntersectionMatrix for the spatial relationship between the geometries
 53    */
 54   public static IntersectionMatrix relate(Geometry a, Geometry b)
 55   {
 56     RelateOp relOp = new RelateOp(a, b);
 57     IntersectionMatrix im = relOp.getIntersectionMatrix();
 58     return im;
 59   }
 60  
 61   /**
 62    * Computes the {@link IntersectionMatrix} for the spatial relationship
 63    * between two {@link Geometry}s using a specified Boundary Node Rule.
 64    *
 65    * @param a a Geometry to test
 66    * @param b a Geometry to test
 67    * @param boundaryNodeRule the Boundary Node Rule to use
 68    * @return the IntersectionMatrix for the spatial relationship between the input geometries
 69    */
 70   public static IntersectionMatrix relate(Geometry a, Geometry b, BoundaryNodeRule boundaryNodeRule)
 71   {
 72     RelateOp relOp = new RelateOp(a, b, boundaryNodeRule);
 73     IntersectionMatrix im = relOp.getIntersectionMatrix();
 74     return im;
 75   }
 76  
 77   private RelateComputer relate;
 78  
 79   /**
 80    * Creates a new Relate operation, using the default (OGC SFS) Boundary Node Rule.
 81    *
 82    * @param g0 a Geometry to relate
 83    * @param g1 another Geometry to relate
 84    */
 85   public RelateOp(Geometry g0, Geometry g1)
 86   {
 87     super(g0, g1);
 88     relate = new RelateComputer(arg);
 89   }
 90  
 91   /**
 92    * Creates a new Relate operation with a specified Boundary Node Rule.
 93    *
 94    * @param g0 a Geometry to relate
 95    * @param g1 another Geometry to relate
 96    * @param boundaryNodeRule the Boundary Node Rule to use
 97    */
 98   public RelateOp(Geometry g0, Geometry g1, BoundaryNodeRule boundaryNodeRule)
 99   {
100     super(g0, g1, boundaryNodeRule);
101     relate = new RelateComputer(arg);
102   }
103  
104   /**
105    * Gets the IntersectionMatrix for the spatial relationship
106    * between the input geometries.
107    *
108    * @return the IntersectionMatrix for the spatial relationship between the input geometries
109    */
110   public IntersectionMatrix getIntersectionMatrix()
111   {
112     return relate.computeIM();
113   }
114  
115 }
116