[mapserver-users] php/mapscipt getExtent

alim karim alim.karim at gmail.com
Wed Apr 23 14:15:50 EDT 2008


thanks armin.

it seems that what you suggested is the only way to get the correct extents
for non-standard layers. i suppose one could add an if statement to check
the layer type i.e. use the canned getExtent if we are dealing with
shapefiles, otherwise if it is postgis, then use your code and if it is
anything else that is non-standard ... well ... tough luck.

On Wed, Apr 23, 2008 at 11:07 AM, Armin Burger <armin.burger at gmx.net> wrote:

> 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
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20080423/7f78c5ab/attachment.html


More information about the mapserver-users mailing list