Created
August 24, 2023 12:56
-
-
Save maxcollombin/cf7a54a13dea99df5e8e55a35b835da4 to your computer and use it in GitHub Desktop.
This script allows to convert a WKT geometry to a BBOX string with WIDTH and HEIGHT to be used in a WMS request.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- WKT TO BBOX | |
-- This script allows to convert a WKT geometry to a BBOX string with WIDTH and HEIGHT to be used in a WMS request. | |
WITH input_geom AS ( | |
SELECT ST_SetSRID('POLYGON((7.210196256637572 46.079631239023286,7.2218477725982675 46.07266495408345,7.22425103187561 46.07465966398232,7.212899923324584 46.08162569712192,7.210196256637572 46.079631239023286))'::geometry, 4326) AS geom | |
) | |
SELECT | |
'BBOX='|| | |
ST_XMin(ST_Transform(geom, 2056)) ||','|| | |
ST_YMin(ST_Transform(geom, 2056)) ||','|| | |
ST_XMax(ST_Transform(geom, 2056)) ||','|| | |
ST_YMax(ST_Transform(geom, 2056)) ||'&WIDTH='|| | |
ROUND(ST_XMax(ST_Transform(geom, 2056))-ST_XMin(ST_Transform(geom, 2056)))||'&HEIGHT='|| | |
ROUND(ST_YMax(ST_Transform(geom, 2056))-ST_YMin(ST_Transform(geom, 2056))) AS BBOX_W_H | |
FROM input_geom; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment