Search code examples
javapolygonbounding-box

converting Polygon to array of bounding box


I'm looking for an algorithm that converts polygon (i.e. array of points) into an array of bounding boxes (with given tolerance).

See the following (incomplete) example: enter image description here


Solution

  • After additional investigation, I figure that I can use jillesvangurp excellent library in order to get a Set of geo-hashes, and then decode them to list of bounding boxes.

    sample code:

    Set<String> geoHashesForPolygon = GeoHashUtils.geoHashesForPolygon(points);
    List<BoundingBox> bboxes = new ArrayList<>(geoHashesForPolygon.size());
    for (String geoHash : geoHashesForPolygon) {
        double[] bbox = GeoHashUtils.decode_bbox(geoHash);
        bboxes.add(new BoundingBox(bbox));
    }