Package com.spatial4j.core.shape.jts

Examples of com.spatial4j.core.shape.jts.JtsGeometry


  @Override
  public String toString(Shape shape) {
    //Note: this logic is from the defunct JtsShapeReadWriter
    if (shape instanceof JtsGeometry) {
      JtsGeometry jtsGeom = (JtsGeometry) shape;
      return jtsGeom.getGeom().toText();
    }
    //Note: doesn't handle ShapeCollection or BufferedLineString
    return super.toString(shape);
  }
View Full Code Here


   *                         it will do tricks to make that line segment (and the shape as a whole)
   *                         cross the dateline even though JTS doesn't have geodetic support.
   * @param allowMultiOverlap See {@link #isAllowMultiOverlap()}.
   */
  public JtsGeometry makeShape(Geometry geom, boolean dateline180Check, boolean allowMultiOverlap) {
    return new JtsGeometry(geom, this, dateline180Check, allowMultiOverlap);
  }
View Full Code Here

  }

  /** Creates the JtsGeometry, potentially validating, repairing, and preparing. */
  protected JtsGeometry makeShapeFromGeometry(Geometry geometry) {
    final boolean dateline180Check = getDatelineRule() != DatelineRule.none;
    JtsGeometry jtsGeom;
    try {
      jtsGeom = ctx.makeShape(geometry, dateline180Check, ctx.isAllowMultiOverlap());
      if (isAutoValidate())
        jtsGeom.validate();
    } catch (RuntimeException e) {
      //repair:
      if (validationRule == ValidationRule.repairConvexHull) {
        jtsGeom = ctx.makeShape(geometry.convexHull(), dateline180Check, ctx.isAllowMultiOverlap());
      } else if (validationRule == ValidationRule.repairBuffer0) {
        jtsGeom = ctx.makeShape(geometry.buffer(0), dateline180Check, ctx.isAllowMultiOverlap());
      } else {
        //TODO there are other smarter things we could do like repairing inner holes and subtracting
        //  from outer repaired shell; but we needn't try too hard.
        throw e;
      }
    }
    if (isAutoIndex())
      jtsGeom.index();
    return jtsGeom;
  }
View Full Code Here

   * Builds a {@link com.spatial4j.core.shape.Shape} instance representing the polygon
   *
   * @return Built polygon
   */
  public Shape build() {
    return new JtsGeometry(toPolygon(), ctx, true, true);
  }
View Full Code Here

    testRelations(true);
  }
  public void testRelations(boolean prepare) throws ParseException {
    assert !((JtsWktShapeParser)ctx.getWktShapeParser()).isAutoIndex();
    //base polygon
    JtsGeometry base = (JtsGeometry) ctx.readShapeFromWkt("POLYGON((0 0, 10 0, 5 5, 0 0))");
    //shares only "10 0" with base
    JtsGeometry polyI = (JtsGeometry) ctx.readShapeFromWkt("POLYGON((10 0, 20 0, 15 5, 10 0))");
    //within base: differs from base by one point is within
    JtsGeometry polyW = (JtsGeometry) ctx.readShapeFromWkt("POLYGON((0 0, 9 0, 5 5, 0 0))");
    //a boundary point of base
    Point pointB = ctx.makePoint(0, 0);
    //a shared boundary line of base
    JtsGeometry lineB = (JtsGeometry) ctx.readShapeFromWkt("LINESTRING(0 0, 10 0)");
    //a line sharing only one point with base
    JtsGeometry lineI = (JtsGeometry) ctx.readShapeFromWkt("LINESTRING(10 0, 20 0)");

    if (prepare) base.index();
    assertRelation(CONTAINS, base, base);//preferred result as there is no EQUALS
    assertRelation(INTERSECTS, base, polyI);
    assertRelation(CONTAINS, base, polyW);
View Full Code Here

  @Test
  public void testArea() {
    //simple bbox
    Rectangle r = randomRectangle(20);
    JtsSpatialContext ctxJts = (JtsSpatialContext) ctx;
    JtsGeometry rPoly = ctxJts.makeShape(ctxJts.getGeometryFrom(r), false, false);
    assertEquals(r.getArea(null), rPoly.getArea(null), 0.0);
    assertEquals(r.getArea(ctx), rPoly.getArea(ctx), 0.000001);//same since fills 100%

    assertEquals(1300, POLY_SHAPE.getArea(null), 0.0);

    //fills 27%
    assertEquals(0.27, POLY_SHAPE.getArea(ctx) / POLY_SHAPE.getBoundingBox().getArea(ctx), 0.009);
View Full Code Here

  }

  @Test
  public void testWidthGreaterThan180() throws ParseException {
    //does NOT cross the dateline but is a wide shape >180
    JtsGeometry jtsGeo = (JtsGeometry) ctx.readShapeFromWkt("POLYGON((-161 49, 0 49, 20 49, 20 89.1, 0 89.1, -161 89.2, -161 49))");
    assertEquals(161+20,jtsGeo.getBoundingBox().getWidth(), 0.001);

    //shift it to cross the dateline and check that it's still good
    jtsGeo = shiftPoly(jtsGeo, 180);
    assertEquals(161+20,jtsGeo.getBoundingBox().getWidth(), 0.001);
  }
View Full Code Here

        return new Coordinate(longitude, latitude);
    }

    protected JtsGeometry jtsGeometry(Geometry geom) {
        //dateline180Check is false because ElasticSearch does it's own dateline wrapping
        JtsGeometry jtsGeometry = new JtsGeometry(geom, SPATIAL_CONTEXT, false, multiPolygonMayOverlap);
        if (autoValidateJtsGeometry)
            jtsGeometry.validate();
        if (autoIndexJtsGeometry)
            jtsGeometry.index();
        return jtsGeometry;
    }
View Full Code Here

        }
        return new ShapeCollection<>(shapes, SPATIAL_CONTEXT);
    }

    private JtsGeometry jtsGeom(Geometry geom) {
        return new JtsGeometry(geom, SPATIAL_CONTEXT, false, false);
    }
View Full Code Here

TOP

Related Classes of com.spatial4j.core.shape.jts.JtsGeometry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.