Search in sources :

Example 1 with Tile

use of com.baremaps.tile.Tile in project baremaps by baremaps.

the class TilesetsResource method getTile.

@Override
public Response getTile(UUID tilesetId, String tileMatrixSetId, Integer tileMatrix, Integer tileRow, Integer tileCol) {
    Tile tile = new Tile(tileCol, tileRow, tileMatrix);
    TileStore tileStore = tileStores.get(tilesetId);
    try {
        return Response.ok(tileStore.read(tile)).header(CONTENT_ENCODING, "gzip").build();
    } catch (TileStoreException e) {
        return Response.serverError().build();
    }
}
Also used : PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) TileStore(com.baremaps.tile.TileStore) Tile(com.baremaps.tile.Tile) TileStoreException(com.baremaps.tile.TileStoreException)

Example 2 with Tile

use of com.baremaps.tile.Tile in project baremaps by baremaps.

the class EditorResources method getTile.

@GET
@javax.ws.rs.Path("/tiles/{z}/{x}/{y}.mvt")
public Response getTile(@PathParam("z") int z, @PathParam("x") int x, @PathParam("y") int y) {
    try {
        List<PostgresQuery> queries = asPostgresQuery(getTileset());
        TileStore tileStore = new PostgresTileStore(dataSource, queries);
        Tile tile = new Tile(x, y, z);
        Blob blob = tileStore.read(tile);
        if (blob != null) {
            return Response.status(200).header(CONTENT_TYPE, blob.getContentType()).header(CONTENT_ENCODING, blob.getContentEncoding()).entity(blob.getInputStream()).build();
        } else {
            return Response.status(204).build();
        }
    } catch (Exception ex) {
        logger.error("Tile error", ex);
        return Response.status(404).build();
    }
}
Also used : TileStore(com.baremaps.tile.TileStore) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) Blob(com.baremaps.blob.Blob) Conversions.asPostgresQuery(com.baremaps.server.ogcapi.Conversions.asPostgresQuery) PostgresQuery(com.baremaps.tile.postgres.PostgresQuery) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) Tile(com.baremaps.tile.Tile) BlobStoreException(com.baremaps.blob.BlobStoreException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) GET(javax.ws.rs.GET)

Example 3 with Tile

use of com.baremaps.tile.Tile in project baremaps by baremaps.

the class TileStoreTest method readWriteDeleteTile.

@Test
@Tag("integration")
void readWriteDeleteTile() throws Exception {
    TileStore tileStore = createTileStore();
    Tile tile = new Tile(1, 2, 3);
    byte[] bytes = "tile_content".getBytes();
    Blob blob = Blob.builder().withByteArray(bytes).build();
    // Write data
    tileStore.write(tile, blob);
    // Read the data
    try (InputStream inputStream = tileStore.read(tile).getInputStream()) {
        assertArrayEquals(bytes, inputStream.readAllBytes());
    }
    // Delete the data
    tileStore.delete(tile);
    assertThrows(TileStoreException.class, () -> tileStore.read(tile));
}
Also used : TileStore(com.baremaps.tile.TileStore) Blob(com.baremaps.blob.Blob) InputStream(java.io.InputStream) Tile(com.baremaps.tile.Tile) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 4 with Tile

use of com.baremaps.tile.Tile in project baremaps by baremaps.

the class PostgresTileStoreTest method differentConditions2.

@Test
void differentConditions2() {
    List<PostgresQuery> queries = Arrays.asList(new PostgresQuery("a", 0, 20, "SELECT id, tags, geom FROM table WHERE condition = 1"), new PostgresQuery("b", 0, 20, "SELECT id, tags, geom FROM table WHERE condition = 2"));
    PostgresTileStore tileStore = new PostgresTileStore(null, queries);
    String query = tileStore.withQuery(new Tile(0, 0, 10));
    assertEquals("with ha14cb45b as (select * from table where ((condition = 1) OR (condition = 2)) and st_intersects(geom, st_tileenvelope(10, 0, 0))) select st_asmvt(target, 'a', 4096, 'geom', 'id') from (select id as id, (tags ||  jsonb_build_object('geometry', lower(replace(st_geometrytype(geom), 'ST_', '')))) as tags, st_asmvtgeom(geom, st_tileenvelope(10, 0, 0), 4096, 256, true) as geom from ha14cb45b where condition = 1) as target union all select st_asmvt(target, 'b', 4096, 'geom', 'id') from (select id as id, (tags ||  jsonb_build_object('geometry', lower(replace(st_geometrytype(geom), 'ST_', '')))) as tags, st_asmvtgeom(geom, st_tileenvelope(10, 0, 0), 4096, 256, true) as geom from ha14cb45b where condition = 2) as target", query);
}
Also used : Tile(com.baremaps.tile.Tile) Test(org.junit.jupiter.api.Test)

Example 5 with Tile

use of com.baremaps.tile.Tile in project baremaps by baremaps.

the class PostgresTileStoreTest method differentConditions1.

@Test
void differentConditions1() {
    List<PostgresQuery> queries = Arrays.asList(new PostgresQuery("a", 0, 20, "SELECT id, tags, geom FROM table"), new PostgresQuery("b", 0, 20, "SELECT id, tags, geom FROM table WHERE condition = 1"));
    PostgresTileStore tileStore = new PostgresTileStore(null, queries);
    String query = tileStore.withQuery(new Tile(0, 0, 10));
    assertEquals("with ha14cb45b as (select * from table where ((true) OR (condition = 1)) and st_intersects(geom, st_tileenvelope(10, 0, 0))) select st_asmvt(target, 'a', 4096, 'geom', 'id') from (select id as id, (tags ||  jsonb_build_object('geometry', lower(replace(st_geometrytype(geom), 'ST_', '')))) as tags, st_asmvtgeom(geom, st_tileenvelope(10, 0, 0), 4096, 256, true) as geom from ha14cb45b ) as target union all select st_asmvt(target, 'b', 4096, 'geom', 'id') from (select id as id, (tags ||  jsonb_build_object('geometry', lower(replace(st_geometrytype(geom), 'ST_', '')))) as tags, st_asmvtgeom(geom, st_tileenvelope(10, 0, 0), 4096, 256, true) as geom from ha14cb45b where condition = 1) as target", query);
}
Also used : Tile(com.baremaps.tile.Tile) Test(org.junit.jupiter.api.Test)

Aggregations

Tile (com.baremaps.tile.Tile)7 TileStore (com.baremaps.tile.TileStore)4 Test (org.junit.jupiter.api.Test)4 PostgresTileStore (com.baremaps.tile.postgres.PostgresTileStore)3 Blob (com.baremaps.blob.Blob)2 BlobStoreException (com.baremaps.blob.BlobStoreException)2 Conversions.asPostgresQuery (com.baremaps.server.ogcapi.Conversions.asPostgresQuery)2 TileStoreException (com.baremaps.tile.TileStoreException)2 PostgresQuery (com.baremaps.tile.postgres.PostgresQuery)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 IOException (java.io.IOException)2 BlobStore (com.baremaps.blob.BlobStore)1 Query (com.baremaps.model.Query)1 TileJSON (com.baremaps.model.TileJSON)1 StreamProgress (com.baremaps.osm.progress.StreamProgress)1 PostgresUtils (com.baremaps.postgres.jdbc.PostgresUtils)1 DefaultObjectMapper.defaultObjectMapper (com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper)1 StreamUtils (com.baremaps.stream.StreamUtils)1 TileBatchPredicate (com.baremaps.tile.TileBatchPredicate)1 TileBlobStore (com.baremaps.tile.TileBlobStore)1