DBIO::PostgreSQL::PostGIS

PostGIS spatial extension support for DBIO::PostgreSQL.

Supports

Usage

package MyApp::Schema::Result::Place;
use base 'DBIO::Core';
__PACKAGE__->load_components('PostgreSQL::PostGIS');
__PACKAGE__->table('place');
__PACKAGE__->add_columns(
  id   => { data_type => 'integer', is_auto_increment => 1 },
  name => { data_type => 'text' },
  geom => {
    data_type     => 'geometry',
    geometry_type => 'POINT',
    srid          => 4326,
  },
);

# Inflated reads - returns DBIO::PostgreSQL::PostGIS::Geometry
my $place = $schema->resultset('Place')->find(1);
$place->geom->x;        # longitude
$place->geom->y;        # latitude
$place->geom->wkt;      # 'POINT(13.4 52.5)'

# Deflated writes - pass a Geometry object
$place->geom(
  DBIO::PostgreSQL::PostGIS::Geometry->point(13.4, 52.5, srid => 4326),
);
$place->update;

DBIO core autodetects dbi:Pg: DSNs and DBIO::PostgreSQL::PostGIS is loaded via C<load_components> on Result classes.

PostGIS Features

Geometry Types

Coordinates & SRID

Spatial Queries (ResultSet helpers)

Geometry Construction

Geometry Methods

Integration

Testing

Requires a running PostgreSQL instance with PostGIS extension:

export DBIO_TEST_PG_DSN="dbi:Pg:database=myapp"
export DBIO_TEST_PG_USER=postgres
export DBIO_TEST_PG_PASS=secret
prove -l t/

The live test (C<t/30-spatial-live.t>) creates an actual geometry table and runs spatial queries. Skips if no PostGIS extension is available.

Requirements

See Also

DBIO::PostgreSQL, DBIO::PostgreSQL::PostGIS::Geometry, PostGIS

Repository

https://codeberg.org/dbio/dbio-postgresql-postgis