NAME
DBIO::PostgreSQL::PostGIS::Geometry - Lightweight PostGIS geometry/geography value object
VERSION
version 0.900000
SYNOPSIS
use DBIO::PostgreSQL::PostGIS::Geometry;
# From WKT
my $point = DBIO::PostgreSQL::PostGIS::Geometry->from_wkt(
'POINT(13.4 52.5)', srid => 4326,
);
# From WKB hex (what PostGIS returns by default)
my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_ewkb_hex($hex);
$point->srid; # 4326
$point->geometry_type; # 'POINT'
$point->wkt; # 'POINT(13.4 52.5)'
$point->ewkt; # 'SRID=4326;POINT(13.4 52.5)'
$point->coordinates; # [13.4, 52.5]
$point->x; $point->y;
$point->is_empty;
# Helpers
$point->to_geojson; # { type => 'Point', coordinates => [...] }
$point->bbox; # [xmin, ymin, xmax, ymax]
DESCRIPTION
A lightweight Perl-side representation of a PostGIS geometry or geography value. Stores SRID + WKT (lazily parsed). Optional inflate path through Geo::OGR when installed for heavy spatial operations.
This object is what DBIO::PostgreSQL::PostGIS inflates geometry and geography column values to. On the way out (deflate) it serializes back to EWKT for the database.
METHODS
from_wkt
my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_wkt($wkt, srid => 4326);
Constructs from a Well-Known Text representation.
from_ewkt
my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_ewkt('SRID=4326;POINT(0 0)');
Parses an Extended WKT string (PostGIS's SRID=N;WKT form).
from_ewkb_hex
my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_ewkb_hex($hex);
Constructs from PostGIS's default hex-encoded EWKB output. Stores the hex unparsed; geometry_type/coordinates are decoded lazily on demand.
point
my $p = DBIO::PostgreSQL::PostGIS::Geometry->point($x, $y, srid => 4326);
my $p = DBIO::PostgreSQL::PostGIS::Geometry->point($x, $y, $z, srid => 4326);
Constructs a POINT geometry. Accepts 2 or 3 numeric coords followed by named options (currently just srid).
from_lat_lon
my $p = DBIO::PostgreSQL::PostGIS::Geometry->from_lat_lon($lat, $lon);
Convenience for building a 4326 POINT from latitude/longitude. Note the order: lat first (the human convention), but the WKT/PostGIS axis order is POINT(lon lat) — this method swaps for you.
linestring
my $l = DBIO::PostgreSQL::PostGIS::Geometry->linestring(
[[0,0],[1,1],[2,0]], srid => 4326,
);
polygon
my $p = DBIO::PostgreSQL::PostGIS::Geometry->polygon(
[ [[0,0],[10,0],[10,10],[0,10],[0,0]] ], # outer ring + optional holes
srid => 4326,
);
bbox_polygon
my $b = DBIO::PostgreSQL::PostGIS::Geometry->bbox_polygon(
$xmin, $ymin, $xmax, $ymax, srid => 4326,
);
Convenience for an axis-aligned rectangle as a closed POLYGON ring.
from_geojson
my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_geojson(\%geojson);
my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_geojson(\%geojson, srid => 4326);
Builds from a GeoJSON-shaped hashref. SRID defaults to 4326 (per the GeoJSON spec) unless overridden.
srid
wkt
ewkb_hex
geometry_type
The geometry type as an upper-case string: POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION. Lazily derived from WKT or EWKB.
ewkt
Returns SRID=N;WKT if SRID is set, otherwise the bare WKT.
to_wkt
Returns the WKT string. Uses stored wkt if available; otherwise builds from coordinates using DBIO::PostgreSQL::PostGIS::Codec::WKT::Builder.
coordinates
Returns the parsed coordinate structure for simple geometry types (POINT → [x,y], LINESTRING → [[x,y],...], POLYGON → [[[x,y],...],...]). Returns undef when the geometry is too complex to parse from WKT alone (use "to_geojson" via Geo::OGR for those).
x
y
z
Convenience accessors for POINT geometries.
is_empty
True if this represents an empty geometry (e.g. POINT EMPTY).
bbox
Returns the bounding box as [xmin, ymin, xmax, ymax]. Requires coordinate parsing or a Geo::OGR fallback.
to_geojson
Returns a GeoJSON-shaped hashref for the simple geometry types.
to_ogr
Returns a Geo::OGR::Geometry object if Geo::OGR is installed; dies otherwise.
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.