Skip to content

Commit

Permalink
Add raster zxy function doc and test
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkAndshark committed Oct 23, 2023
1 parent 3c24ae2 commit 5774b36
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/fixtures/functions/function_zxy_raster.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
DROP FUNCTION IF EXISTS public.function_zxy_raster;

CREATE OR REPLACE FUNCTION public.function_zxy_raster(z integer, x integer, y integer) RETURNS bytea AS $$
DECLARE
mvt bytea;
BEGIN
with rast as (
SELECT
st_clip(
st_transform(st_union(rast),3857),
st_tileenvelope(z,x,y)
)
as bands
from public.landcover where ST_ConvexHull(rast) && st_transform( st_tileenvelope(z,x,y),4326)
)
SELECT into mvt ST_AsJPEG(st_tile(bands,256,256)) from rast;
return mvt;
END
$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE;
5 changes: 5 additions & 0 deletions tests/fixtures/initdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ for sql_file in "$FIXTURES_DIR"/tables/*.sql; do
psql -e -P pager=off -v ON_ERROR_STOP=1 -f "$sql_file"
done

echo "Importing raster tables from $FIXTURES_DIR/raster"
echo "################################################################################################"
psql -e -P pager=off -v ON_ERROR_STOP=1 -f "$FIXTURES_DIR"/raster/init_raster_support.sql
raster2pgsql -s 4326 -I -C -F -t 100x100 "$FIXTURES_DIR"/raster/raster.tif public.landcover | psql -e -P pager=off -v ON_ERROR_STOP=1

echo -e "\n\n\n"
echo "################################################################################################"
echo "Importing functions from $FIXTURES_DIR/functions"
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/raster/init_raster_support.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
create extension postgis_raster;
alter DATABASE db SET postgis.enable_outdb_rasters = true;
alter DATABASE db set postgis.gdal_enabled_drivers To 'GTiff PNG JPEG';
SELECT pg_reload_conf();
Binary file added tests/fixtures/raster/raster.tif
Binary file not shown.

0 comments on commit 5774b36

Please sign in to comment.