[mapserver-users] catching GEOS errors in PHP mapscript

Daniel Morissette dmorissette at mapgears.com
Wed Oct 14 21:30:32 EDT 2009


Joshua Hevenor wrote:
> I'm doing a fairly simple geo-processing script in PHP but I'm running 
> into some trouble.  I have two polygon layers and I'm trying to look up 
> all polygons from layer A that are not disjoint from layer B.  I'm also 
> looking at specific area so if the polygon from layer B is bigger than 
> my map extent I'm trying to clip (using shapeobj::intersection) to the 
> map extent.   On occasion I'm getting GEOS errors that show up in my PHP 
> error log and kill my script. The errors are from bad shapes (things 
> like a rectangle built wrong so that it looks more like an hour glass). 
> Is there a function to verify the shape?  I don't see one in the PHP 
> documentation. Can I catch these errors somehow? 
> 

That depends on which error you get. You can usually catch errors in PHP 
using the "@" Error Control Operator, see:
http://www.php.net/manual/en/language.operators.errorcontrol.php

Unfortunately some functions in PHP MapScript produce fatal PHP errors 
that cannot be trapped this way, and we fix them as problems are 
reported. However based on a quick browse of the PHP MapScript source 
code that doesn't seem to be the case of GEOS operators which seem to 
simply return FALSE in case of errors, so it should be possible to 
handle those errors using something like:

if (@$shape1->intersection($shape2) == FALSE)
{
   // Handle error situation
}

I didn't test this with the GEOS operators myself, but I'd suggest you 
try and see if that solves your issue. If not then we will need more 
specific error messages and some sample code in order to help you further.

Daniel
-- 
Daniel Morissette
http://www.mapgears.com/


More information about the mapserver-users mailing list