[postgis-devel] PostGIS 1.4 SVN geometry parser hints

Mark Cave-Ayland mark.cave-ayland at siriusit.co.uk
Wed Oct 15 08:42:50 PDT 2008


Hi everyone,

Just so that it doesn't come as too much of a surprise, I remembered 
that with the new parser API in place within SVN trunk, we can now 
return extra information from the parse phase, including the position of 
any errors. Since we are now using a minimum of PostgreSQL 8.1, it means 
we can use the HINT functionality to tag this additional information to 
the original ERROR message.

So as of SVN trunk, you now see an extract of the input geometry up to 
the point where the parse failed (marked with an arrow), followed by the 
absolute position of the error like this:


postgis=# select 'test1', astext(geomfromtext('LINESTRINGA(0 0)'));
ERROR:  parse error - invalid geometry
HINT:  "LINESTRING" <-- parse error at position 10 within geometry
CONTEXT:  SQL function "geomfromtext" statement 1

postgis=# select 'test2', astext(geomfromtext('LINESTRING(0 0)'));
ERROR:  geometry requires more points
HINT:  "LINESTRING(0 0)" <-- parse error at position 15 within geometry
CONTEXT:  SQL function "geomfromtext" statement 1

postgis=# select 'test3', astext(geosnoop('POLYGON((0 0, 0 1, 1 1, 2 1, 
3 1, 4 1, 5 1, 6 1, 7 1, 8 1))'));
ERROR:  geometry contains non-closed rings
HINT:  "... 1 1, 2 1, 3 1, 4 1, 5 1, 6 1, 7 1, 8 1)" <-- parse error at 
position 58 within geometry


Nice :)  I'm not 100% set upon the HINT output format (it was the 
clearest I could come up with to fit on one line after a bit of playing 
around), so if anyone can think of anything better, please shout.

ATB,

Mark.

-- 
Mark Cave-Ayland
Sirius Corporation - The Open Source Experts
http://www.siriusit.co.uk
T: +44 870 608 0063



More information about the postgis-devel mailing list