Skip to content

Instantly share code, notes, and snippets.

@muety
Last active Oct 15, 2021
Embed
What would you like to do?
// https://livebook.manning.com/book/postgis-in-action-second-edition/chapter-17/242
// https://gist.github.com/muety/9e3a6d0ad2bb5890c081670e0c4fc044
<?php
define("DSN", "host=localhost dbname=postgis_in_action user=postgis_in_action port=5432 password=whatever");
$param_format = $_REQUEST['FORMAT'];
$param_width = (int) $_REQUEST['WIDTH'];
$param_height = (int) $_REQUEST['HEIGHT'];
$param_bbox = $_REQUEST['BBOX'];
$param_schema = $_REQUEST['SCHEMA'];
$param_table = $_REQUEST['LAYERS'];
if ( !empty($_REQUEST['VERSION'])
&& $_REQUEST['VERSION'] == '1.1.1' ) {
$param_srid = (int) str_replace('EPSG:', ''
, $_REQUEST['SRS']);
}
else { /** assume 1.3.0 **/
$param_srid = (int) str_replace('EPSG:', ''
, $_REQUEST['CRS']);
}
$dbconn = pg_connect(DSN);
pg_query('SET bytea_output = "escape";');
$res = pg_query_params($dbconn,
'SELECT ch17.get_rast_tile($1, $2, $3, $4,
$5, $6, $7) As result',
array($param_format, $param_width, $param_height,
$param_srid, $param_bbox, $param_schema, $param_table ));
$val = pg_fetch_result($res,0,0);
header('Content-type: ' . $param_format);
echo pg_unescape_bytea($val);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment