[mapserver-users] php/mapscipt getExtent

Armin Burger armin.burger at gmx.net
Wed Apr 23 14:07:05 EDT 2008


Alim

The extent returned for a layer seems to be working only for 'standard' 
layers (e.g. based on shapefiles), but neither for Postgis nor raster 
layers, god knows why.... I use the code below for zooming to the extent 
of a Postgis layer:

$data = trim($layer->data);
$dataList1 = preg_split("/\s/", $data);
$dataList2 = preg_split("/using/i", $data);
$geomFld = array_shift($dataList1);
$sql = "select xmin(extent) as minx, ymin(extent) as miny, xmax(extent)
         as maxx, ymax(extent) as maxy
         from (SELECT extent($geomFld) "
         . substr($dataList2[0], strlen($geomFld)) . ") as bar";

// load DLL on Win if required
if (PHP_OS == "WINNT" || PHP_OS == "WIN32") {
     if (! extension_loaded('pgsql')) {
         dl('php_pgsql.dll');
     }
}

$connString = $layer->connection;
if (!($connection = pg_Connect($connString))){
    error_log ("Could not connect to database");
    error_log ("PG Connection error: " . pg_last_error($connection));
    exit();
}

$qresult = pg_query ($connection, $sql);
if (!$qresult) error_log("PG Query error for : $query" . 
pg_result_error($qresult));

$pgE = pg_fetch_object($qresult);
$layerExt = ms_newRectObj();
$layerExt->setextent($pgE->minx, $pgE->miny, $pgE->maxx, $pgE->maxy);


There might be easier solutions but this worked for me.

armin

On 22/04/2008 23:52, alim karim wrote:
> hello all.
> 
> i have a PostGIS layer (without its extents specified) in a mapfile.
> 
> i am trying to use getExtent on this layer, but the coordinates i get 
> back 
> (["minx":-25000000,"miny":-25000000,"maxx":25000000,"maxy":25000000]) 
> are not the correct extents([1180204.375000, 
> 809428.750000,1222443.000000, 857276.187500)]).
> 
> is there a way to get the proper extents of a layer even though they 
> might not be specified in the mapfile?
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users


More information about the mapserver-users mailing list