Search code examples
postgisdatastoregeotools

How to convert x y z tile to a geotools bbox or ReferenceEnvelope


i am using a lefleat tile layer with xyz system to query a list of postgis layers,i use a geotools jdbc datastore to fetch layers from database ,but i have to work with bbox or a geotools refernce envelope,how i can transform xyz coordinate to a bbox or a refernce envelope,so i can pass it later to my datastore feature source so i can find geometries or elements in a given bbox ,my coordinate system is EPSG:4326.


Solution

  • You can use the code in gt-tile-client to work with XYZ services.

    I think the following should work for you.

    String ref = "7/61/53";
    
    String[] parts = ref.split("/");
    int z = Integer.valueOf(parts[0]);
    int x = Integer.valueOf(parts[1]);
    int y = Integer.valueOf(parts[2]);
    
    OSMTile tile = new OSMTile(x, y, new WebMercatorZoomLevel(z), new OSMService("name", "url"));
    System.out.println(tile.getExtent());
    

    which gives

    ReferencedEnvelope[-8.4375 : -5.625, 27.05912578437406 : 29.535229562948455]