NAME
DBIO::PostgreSQL::PostGIS::Codec::WKT::Parser - WKT/EWKT parser for PostGIS geometry values
VERSION
version 0.900007
METHODS
parse
my $result = DBIO::PostgreSQL::PostGIS::Codec::WKT::Parser->parse($wkt);
Parses a WKT string and returns a hashref:
{
type => 'point',
coords => [...],
has_z => 0,
has_m => 0,
is_empty => 0,
}
Returns undef for unsupported types and for text it cannot read. The structure is that of DBIO::PostgreSQL::PostGIS::Codec::WKB::Decoder for the same geometry, so a geometry read from the server's text and from its EWKB is the same hash.
The dimension is read in every form PostGIS prints or reads:
ST_AsEWKTgluesMto the type,POINTM(1 2 9),MULTIPOINTM(...),GEOMETRYCOLLECTIONM(...). It prints no marker for Z and ZM:POINT(1 2 3)is Z,POINT(1 2 3 4)is ZM, as PostGIS reads them. Without a marker the number of ordinates of the first point says it: three are Z, four are ZM. (An empty geometry has no ordinates;ST_AsEWKTprintsPOINT EMPTYfor a Z one, and that is what is read.)ST_AsTextand this distribution's builder write the marker as a word of its own, with or without a space before the parenthesis:POINT M (1 2 9),POINT ZM(1 2 3 4),POINT Z EMPTY.POINTZ(1 2 3)andPOINTZM(...), glued, which PostGIS reads too.
An explicit marker wins over the ordinates. Type and marker are not case sensitive. The returned type is the plain type, point, never pointm.
A MULTIPOINT is read in both of its forms, with and without parentheses around each point: MULTIPOINT((1 2),(3 4)) and MULTIPOINT(1 2,3 4).
Empty parts of a MULTI* -- MULTIPOINT(EMPTY,(1 2)), MULTILINESTRING(EMPTY,(0 0,1 1)), MULTIPOLYGON(EMPTY,((0 0,1 0,1 1,0 0))) -- stay where they are as an empty list: [[],[1,2]]. is_empty of the whole is true if all its parts are.
GEOMETRYCOLLECTION: coords is the list of its members, each a hashref { type, coords, is_empty } with the plain, lower-case type of the member and the coords it would have on its own (for a collection in a collection, again such a list). The members may be empty (POINT EMPTY) and may carry their own marker. The collection's has_z and has_m are its own marker or, without one, those of its members. undef if one member is of a type that is not read.
Ordinates are numbers as WKT writes them: an optional minus sign, digits with an optional fraction (3., -.5) and an optional exponent (1e5, 1E-3). A point has two to four of them; text with another count or with a token that is no number is text the parser cannot read, and the result is undef. A number must be finite: one that is too large for a double (1e9999) is no number the parser reads, and the result is undef.
Nesting of collections is limited to 32 levels; deeper input throws a DBIO::Exception (WKT nesting too deep). The outermost GEOMETRYCOLLECTION is level 1. The text is read once, from start to end, so the time it takes is in proportion to its length.
AUTHOR
DBIO Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.