DBIO-PostgreSQL-PostGIS
view release on metacpan or search on metacpan
lib/DBIO/PostgreSQL/PostGIS/Geometry.pm view on Meta::CPAN
DBIO::Exception->throw("from_ewkt requires an EWKT string") unless defined $ewkt;
if ($ewkt =~ /\ASRID=(\d+);(.+)\z/s) {
return $class->new(srid => $1, wkt => $2);
}
return $class->new(wkt => $ewkt);
}
sub from_ewkb_hex {
my ($class, $hex) = @_;
my $decoded = eval {
DBIO::PostgreSQL::PostGIS::Codec::WKB::Decoder->decode_hex($hex);
};
return undef unless $decoded && $decoded->{type} ne 'unknown';
return $class->new(
ewkb_hex => $hex,
srid => $decoded->{srid},
geometry_type => $decoded->{type},
coordinates => $decoded->{coords},
);
}
sub point {
my $class = shift;
my @coords;
push @coords, shift while @_ && !ref $_[0] && $_[0] =~ /\A-?[0-9.eE+\-]+\z/;
my %args = @_;
my $wkt = 'POINT(' . join(' ', @coords) . ')';
lib/DBIO/PostgreSQL/PostGIS/Geometry.pm view on Meta::CPAN
my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_ewkt('SRID=4326;POINT(0 0)');
Parses an Extended WKT string (PostGIS's C<SRID=N;WKT> form).
=head2 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.
=head2 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 C<srid>).
=head2 from_lat_lon
( run in 1.236 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )