Jesus Loves GRASS

Technical blog about GRASS/GIS,open source geoinformatics and MAPSERVER.

Tuesday, February 26, 2008

$oMap->setExtent problems and general data gathering

I made some PHP programming/MapScript for rendering a GeoTiff created by an interpolation service (WPS) as a PNG. The Geotiff is stored in the server's temporary folder and all the mapserver parameters are set by PHP programing.

The fist part of the posted code gets the image info using GdalInfo and regular expressions to obtain the extent value of the image, I haven't managed to do this properly using the PHP's Exif lib....

The major problem was the SetExtent of the Map object it was always complaining that the values had some problem, the problem was that the parameters were being passed as a string, and they needed to be as double, even if they are passed as float (or int?) the SetExtent will complain

//Some code before

$FileName=/usr/local/apache2/htdocs/tmp/interpolation3454.tiff;
$CmdStr="/usr/local/bin/gdalinfo ".$FileName;
//General string for getting float numbers
$StrPattern='/[-+]?\b[0-9]*\.?[0-9]+\b/';
exec($CmdStr,$ResultArray);

//Upper left point info
$UpperLeftPoint=$ResultArray[6];
preg_match_all($StrPattern,$UpperLeftPoint,$TmpArray);
$MinX=$TmpArray[0][0];
$MaxY=$TmpArray[0][1];

//Lower right point info
$LowerRightPoint=$ResultArray[9];
preg_match_all($StrPattern,$LowerRightPoint,$TmpArray);
$MaxX=$TmpArray[0][0];
$MinY=$TmpArray[0][1];

//Passing to Map object
//double minx, double miny, double maxx, double maxy
$oMap->setExtent((double)$MinY,(double)$MinY,(double)$MaxX,(double)$MaxY);

//Same code after

Labels: , , , , , ,

0 Comments:

Post a Comment

<< Home