コード例 #1
0
 private void addLine(Coordinate[] pts) {
   SegmentString segStr = new BasicSegmentString(pts, null);
   List segChains = MonotoneChainBuilder.getChains(segStr.getCoordinates(), segStr);
   for (Iterator i = segChains.iterator(); i.hasNext(); ) {
     MonotoneChain mc = (MonotoneChain) i.next();
     index.insert(mc.getEnvelope(), mc);
   }
 }
コード例 #2
0
 private void init(Geometry geom) {
   List lines = LinearComponentExtracter.getLines(geom);
   for (Iterator i = lines.iterator(); i.hasNext(); ) {
     LineString line = (LineString) i.next();
     Coordinate[] pts = line.getCoordinates();
     addLine(pts);
   }
 }
コード例 #3
0
 /**
  * Tests whether any component of the test Geometry intersects the interior of the target
  * geometry. Handles test geometries with both linear and point components.
  *
  * @param geom a geometry to test
  * @return true if any component of the argument intersects the prepared area geometry interior
  */
 protected boolean isAnyTestComponentInTargetInterior(Geometry testGeom) {
   List coords = ComponentCoordinateExtracter.getCoordinates(testGeom);
   for (Iterator i = coords.iterator(); i.hasNext(); ) {
     Coordinate p = (Coordinate) i.next();
     int loc = targetPointLocator.locate(p);
     if (loc == Location.INTERIOR) return true;
   }
   return false;
 }
コード例 #4
0
 /**
  * Tests whether any component of the target geometry intersects the test geometry (which must be
  * an areal geometry)
  *
  * @param geom the test geometry
  * @param repPts the representative points of the target geometry
  * @return true if any component intersects the areal test geometry
  */
 protected boolean isAnyTargetComponentInAreaTest(Geometry testGeom, List targetRepPts) {
   PointOnGeometryLocator piaLoc = new SimplePointInAreaLocator(testGeom);
   for (Iterator i = targetRepPts.iterator(); i.hasNext(); ) {
     Coordinate p = (Coordinate) i.next();
     int loc = piaLoc.locate(p);
     if (loc != Location.EXTERIOR) return true;
   }
   return false;
 }
コード例 #5
0
 private void countSegs(
     RayCrossingCounter rcc, Envelope rayEnv, List monoChains, MCSegmentCounter mcSegCounter) {
   for (Iterator i = monoChains.iterator(); i.hasNext(); ) {
     MonotoneChain mc = (MonotoneChain) i.next();
     mc.select(rayEnv, mcSegCounter);
     // short-circuit if possible
     if (rcc.isOnSegment()) return;
   }
 }
コード例 #6
0
 /**
  * Tests whether any representative point of the test Geometry intersects the target geometry.
  * Only handles test geometries which are Puntal (dimension 0)
  *
  * @param geom a Puntal geometry to test
  * @return true if any point of the argument intersects the prepared geometry
  */
 protected boolean isAnyTestPointInTarget(Geometry testGeom) {
   /**
    * This could be optimized by using the segment index on the lineal target. However, it seems
    * like the L/P case would be pretty rare in practice.
    */
   PointLocator locator = new PointLocator();
   List coords = ComponentCoordinateExtracter.getCoordinates(testGeom);
   for (Iterator i = coords.iterator(); i.hasNext(); ) {
     Coordinate p = (Coordinate) i.next();
     if (locator.intersects(p, prepLine.getGeometry())) return true;
   }
   return false;
 }
コード例 #7
0
ファイル: GeometryFactory.java プロジェクト: Gnafu/SIIGMobile
  /**
   * Build an appropriate <code>Geometry</code>, <code>MultiGeometry</code>, or <code>
   * GeometryCollection</code> to contain the <code>Geometry</code>s in it. For example:<br>
   *
   * <ul>
   *   <li>If <code>geomList</code> contains a single <code>Polygon</code>, the <code>Polygon</code>
   *       is returned.
   *   <li>If <code>geomList</code> contains several <code>Polygon</code>s, a <code>MultiPolygon
   *       </code> is returned.
   *   <li>If <code>geomList</code> contains some <code>Polygon</code>s and some <code>LineString
   *       </code>s, a <code>GeometryCollection</code> is returned.
   *   <li>If <code>geomList</code> is empty, an empty <code>GeometryCollection</code> is returned
   * </ul>
   *
   * Note that this method does not "flatten" Geometries in the input, and hence if any
   * MultiGeometries are contained in the input a GeometryCollection containing them will be
   * returned.
   *
   * @param geomList the <code>Geometry</code>s to combine
   * @return a <code>Geometry</code> of the "smallest", "most type-specific" class that can contain
   *     the elements of <code>geomList</code> .
   */
  public Geometry buildGeometry(Collection geomList) {

    /** Determine some facts about the geometries in the list */
    Class geomClass = null;
    boolean isHeterogeneous = false;
    boolean hasGeometryCollection = false;
    for (Iterator i = geomList.iterator(); i.hasNext(); ) {
      Geometry geom = (Geometry) i.next();
      Class partClass = geom.getClass();
      if (geomClass == null) {
        geomClass = partClass;
      }
      if (partClass != geomClass) {
        isHeterogeneous = true;
      }
      if (geom instanceof GeometryCollection) hasGeometryCollection = true;
    }

    /** Now construct an appropriate geometry to return */
    // for the empty geometry, return an empty GeometryCollection
    if (geomClass == null) {
      return createGeometryCollection(null);
    }
    if (isHeterogeneous || hasGeometryCollection) {
      return createGeometryCollection(toGeometryArray(geomList));
    }
    // at this point we know the collection is hetereogenous.
    // Determine the type of the result from the first Geometry in the list
    // this should always return a geometry, since otherwise an empty collection would have already
    // been returned
    Geometry geom0 = (Geometry) geomList.iterator().next();
    boolean isCollection = geomList.size() > 1;
    if (isCollection) {
      if (geom0 instanceof Polygon) {
        return createMultiPolygon(toPolygonArray(geomList));
      } else if (geom0 instanceof LineString) {
        return createMultiLineString(toLineStringArray(geomList));
      } else if (geom0 instanceof Point) {
        return createMultiPoint(toPointArray(geomList));
      }
      Assert.shouldNeverReachHere("Unhandled class: " + geom0.getClass().getName());
    }
    return geom0;
  }