Examples of JtsSpatialContext


Examples of com.spatial4j.core.context.jts.JtsSpatialContext

    writeJtsGeom(dataOutput, s);
    return true;
  }

  public Shape readJtsGeom(final DataInput dataInput) throws IOException {
    JtsSpatialContext ctx = (JtsSpatialContext)super.ctx;
    WKBReader reader = new WKBReader(ctx.getGeometryFactory());
    try {
      InStream inStream = new InStream() {//a strange JTS abstraction
        boolean first = true;
        @Override
        public void read(byte[] buf) throws IOException {
          if (first) {//we don't write JTS's leading BOM so synthesize reading it
            if (buf.length != 1)
              throw new IllegalStateException("Expected initial read of one byte, not: " + buf.length);
            buf[0] = WKBConstants.wkbXDR;//0
            first = false;
          } else {
            //TODO for performance, specialize for common array lengths: 1, 4, 8
            dataInput.readFully(buf);
          }
        }
      };
      Geometry geom = reader.read(inStream);
      //false: don't check for dateline-180 cross or multi-polygon overlaps; this won't happen
      // once it gets written, and we're reading it now
      return ctx.makeShape(geom, false, false);
    } catch (ParseException ex) {
      throw new InvalidShapeException("error reading WKT", ex);
    }
  }
View Full Code Here

Examples of com.spatial4j.core.context.jts.JtsSpatialContext

      throw new InvalidShapeException("error reading WKT", ex);
    }
  }

  public void writeJtsGeom(final DataOutput dataOutput, Shape s) throws IOException {
    JtsSpatialContext ctx = (JtsSpatialContext)super.ctx;
    Geometry geom = ctx.getGeometryFrom(s);//might even translate it
    new WKBWriter().write(geom, new OutStream() {//a strange JTS abstraction
      boolean first = true;
      @Override
      public void write(byte[] buf, int len) throws IOException {
        if (first) {
View Full Code Here

Examples of com.spatial4j.core.context.jts.JtsSpatialContext

    super(ctx);
  }

  @Test
  public void testPoly() {
    JtsSpatialContext ctx = (JtsSpatialContext)super.ctx;
    ctx.makeShape(randomGeometry(randomIntBetween(3, 20)), false, false);
  }
View Full Code Here

Examples of com.spatial4j.core.context.jts.JtsSpatialContext

  }

  @Override
  protected Shape randomShape() {
    if (randomInt(3) == 0) {
      JtsSpatialContext ctx = (JtsSpatialContext)super.ctx;
      return ctx.makeShape(randomGeometry(randomIntBetween(3, 20)), false, false);
    } else {
      return super.randomShape();
    }
  }
View Full Code Here

Examples of com.spatial4j.core.context.jts.JtsSpatialContext

    }
  }

  Geometry randomGeometry(int points) {
    //a circle
    JtsSpatialContext ctx = (JtsSpatialContext)super.ctx;
    GeometricShapeFactory gsf = new GeometricShapeFactory(ctx.getGeometryFactory());
    gsf.setCentre(new Coordinate(0, 0));
    gsf.setSize(180);//diameter
    gsf.setNumPoints(points);
    return gsf.createCircle();
  }
View Full Code Here

Examples of com.spatial4j.core.context.jts.JtsSpatialContext

    assertParses("POLYGON((160 10, -170 10, -170 0, 160 0, 160 10))", expected);
  }

  @Test
  public void polyToRectCcwRule() throws ParseException {
    JtsSpatialContext ctx = new JtsSpatialContextFactory() { { datelineRule = JtsWktShapeParser.DatelineRule.ccwRect;} }.newSpatialContext();
    //counter-clockwise
    assertEquals(ctx.readShapeFromWkt("POLYGON((160 0, -170 0, -170 10, 160 10, 160 0))"),
        ctx.makeRectangle(160, -170, 0, 10));
    //clockwise
    assertEquals(ctx.readShapeFromWkt("POLYGON((160 10, -170 10, -170 0, 160 0, 160 10))"),
        ctx.makeRectangle(-170, 160, 0, 10));
  }
View Full Code Here

Examples of com.spatial4j.core.context.jts.JtsSpatialContext

    //ctx.readShapeFromWkt("POLYGON((0 0, 10 0, 10 20))");//doesn't connect around
    String wkt = "POLYGON((0 0, 10 0, 10 20, 5 -5, 0 20, 0 0))";//Topology self-intersect

    JtsSpatialContextFactory factory = new JtsSpatialContextFactory();
    factory.validationRule = JtsWktShapeParser.ValidationRule.repairBuffer0;
    JtsSpatialContext ctx = factory.newSpatialContext();
    Shape buffer0 = ctx.readShapeFromWkt(wkt);
    assertTrue(buffer0.getArea(ctx) > 0);

    factory = new JtsSpatialContextFactory();
    factory.validationRule = JtsWktShapeParser.ValidationRule.repairConvexHull;
    ctx = factory.newSpatialContext();
    Shape cvxHull = ctx.readShapeFromWkt(wkt);
    assertTrue(cvxHull.getArea(ctx) > 0);

    assertEquals(SpatialRelation.CONTAINS, cvxHull.relate(buffer0));

    factory = new JtsSpatialContextFactory();
    factory.validationRule = JtsWktShapeParser.ValidationRule.none;
    ctx = factory.newSpatialContext();
    ctx.readShapeFromWkt(wkt);//doesn't throw
  }
View Full Code Here

Examples of com.spatial4j.core.context.jts.JtsSpatialContext

        ctx.getDistCalc());
  }

  @Test
  public void testJtsContextFactory() {
    JtsSpatialContext ctx = (JtsSpatialContext) call(
        "spatialContextFactory", JtsSpatialContextFactory.class.getName(),
        "geo", "true",
        "normWrapLongitude", "true",
        "precisionScale", "2.0",
        "wktShapeParserClass", CustomWktShapeParser.class.getName(),
        "datelineRule", "ccwRect",
        "validationRule", "repairConvexHull",
        "autoIndex", "true");
    assertTrue(ctx.isNormWrapLongitude());
    assertEquals(2.0, ctx.getGeometryFactory().getPrecisionModel().getScale(), 0.0);
    assertTrue(CustomWktShapeParser.once);//cheap way to test it was created
    assertEquals(JtsWktShapeParser.DatelineRule.ccwRect,
        ((JtsWktShapeParser)ctx.getWktShapeParser()).getDatelineRule());
    assertEquals(JtsWktShapeParser.ValidationRule.repairConvexHull,
        ((JtsWktShapeParser)ctx.getWktShapeParser()).getValidationRule());

    //ensure geo=false with worldbounds works -- fixes #72
    ctx = (JtsSpatialContext) call(
        "spatialContextFactory", JtsSpatialContextFactory.class.getName(),
        "geo", "false",//set to false
        "worldBounds", "ENVELOPE(-500,500,300,-300)",
        "normWrapLongitude", "true",
        "precisionScale", "2.0",
        "wktShapeParserClass", CustomWktShapeParser.class.getName(),
        "datelineRule", "ccwRect",
        "validationRule", "repairConvexHull",
        "autoIndex", "true");
    assertEquals(300, ctx.getWorldBounds().getMaxY(), 0.0);
  }
View Full Code Here

Examples of com.spatial4j.core.context.jts.JtsSpatialContext

  @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);
View Full Code Here

Examples of com.spatial4j.core.context.jts.JtsSpatialContext

    //assertRelation(null,SpatialRelation.CONTAINS, shape, ctx.makePoint(61.48, 64.21));

    JtsSpatialContextFactory factory = new JtsSpatialContextFactory();
    factory.normWrapLongitude = true;

    JtsSpatialContext ctx = factory.newSpatialContext();

    Shape shape = ctx.readShapeFromWkt(wktStr);
    //System.out.println("Russia Area: "+shape.getArea(ctx));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.