Bbox implements Serializable { public static Polygon envelopeToPolygon(Envelope e) { GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING_SINGLE), SRID); Coordinate coordA = new Coordinate(e.getMinX(), e.getMinY()); Coordinate coordB = new Coordinate(e.getMinX(), e.getMaxY()); Coordinate coordC = new Coordinate(e.getMaxX(), e.getMaxY()); Coordinate coordD = new Coordinate(e.getMaxX(), e.getMinY()); Coordinate coordE = coordA; Polygon bboxPoly = factory.createPolygon(new Coordinate[]{coordA, coordB, coordC, coordD, coordE}); return bboxPoly; }  @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") int getId(); void setId(int id); @Column(name = "bbox", columnDefinition = "box2d") String getBbox(); void setBbox(String bbox); void setBbox(double minX, double minY, double maxX, double maxY); Envelope makeEnvelope(); static Pair<Pair<Double,Double>,Pair<Double,Double>> getPoints(Bbox source); static Bbox copyValues(Bbox from, Bbox to); static Polygon envelopeToPolygon(Envelope e); static Bbox copyToSquareBox(Bbox source); static Bbox copyToCRS(Bbox source, String targetCRS); static final int SRID; static final String BOX_FORMAT; }
@Test public void testEnvelopeToPolygon() { Envelope e = new Envelope(1.0, 2.0, 3.0, 4.0); Polygon result = Bbox.envelopeToPolygon(e); assertThat(result.getArea(), is(equalTo(1.0))); }