| 1 | package DBIO::PostgreSQL::PostGIS::Geometry; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Lightweight PostGIS geometry/geography value object | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use DBIO::Exception (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use DBIO::PostgreSQL::PostGIS::Codec::WKT::Parser (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use DBIO::PostgreSQL::PostGIS::Codec::WKT::Builder (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use DBIO::PostgreSQL::PostGIS::Codec::WKB::Decoder (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 17 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||
| 16 | srid => $args{srid}, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | wkt => $args{wkt}, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | ewkb_hex => $args{ewkb_hex}, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | geometry_type => $args{geometry_type}, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | coordinates => $args{coordinates}, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 17 | }; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 17 | return bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | sub from_wkt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_wkt: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | my ($class, $wkt, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | DBIO::Exception->throw("from_wkt requires a WKT string") unless defined $wkt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | my $parsed = DBIO::PostgreSQL::PostGIS::Codec::WKT::Parser->parse($wkt); | |||||||||||||||||||||||||||||||||||||||||
| 30 | return $class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 31 | wkt => $wkt, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | srid => $args{srid}, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | geometry_type => $parsed ? $parsed->{type} : undef, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | coordinates => $parsed ? $parsed->{coords} : undef, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | ▶ | sub from_ewkt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_ewkt: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | my ($class, $ewkt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | DBIO::Exception->throw("from_ewkt requires an EWKT string") unless defined $ewkt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | if ($ewkt =~ /\ASRID=(\d+);(.+)\z/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | return $class->new(srid => $1, wkt => $2); | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return $class->new(wkt => $ewkt); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | sub from_ewkb_hex { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_ewkb_hex: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | my ($class, $hex) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | my $decoded = eval { | |||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | DBIO::PostgreSQL::PostGIS::Codec::WKB::Decoder->decode_hex($hex); | |||||||||||||||||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | return undef unless $decoded && $decoded->{type} ne 'unknown'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$decoded and $decoded->{"type"} ne "unknown"
MC/DC0%0/2
$decoded and $decoded->{"type"} ne "unknown"
$decoded
$decoded->{"type"} ne "unknown"
Truth table33%1/3
A and B
A= $decodedB= $decoded->{"type"} ne "unknown"
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | return $class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ewkb_hex => $hex, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | srid => $decoded->{srid}, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | geometry_type => $decoded->{type}, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | coordinates => $decoded->{coords}, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | ▶ | sub point { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
point: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | my @coords; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | ▶ | push @coords, shift while @_ && !ref $_[0] && $_[0] =~ /\A-?[0-9.eE+\-]+\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
@_ and not ref $_[0] and $_[0] =~ /\A-?[0-9.eE+\-]+\z/
@_ and not ref $_[0]
MC/DC33%1/3
@_ and not ref $_[0] and $_[0] =~ /\A-?[0-9.eE+\-]+\z/
@_
not ref $_[0]
$_[0] =~ /\A-?[0-9.eE+\-]+\z/
Truth table50%2/4
A and not(B) and C
A= @_B= not ref $_[0]C= $_[0] =~ /\A-?[0-9.eE+\-]+\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | my $wkt = 'POINT(' . join(' ', @coords) . ')'; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | return $class->new(wkt => $wkt, srid => $args{srid}, geometry_type => 'POINT'); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | sub from_lat_lon { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_lat_lon: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | my ($class, $lat, $lon) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | return $class->point($lon, $lat, srid => 4326); | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | sub linestring { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
linestring: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | my ($class, $coords, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | my $wkt = 'LINESTRING(' . join(',', map { join ' ', @$_ } @$coords) . ')'; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | return $class->new(wkt => $wkt, srid => $args{srid}, geometry_type => 'LINESTRING'); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | ▶ | sub polygon { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
polygon: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | my ($class, $rings, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | my $wkt = 'POLYGON(' | ||||||||||||||||||||||||||||||||||||||||||
| 90 | . join(',', map { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | '(' . join(',', map { join ' ', @$_ } @$_) . ')' | |||||||||||||||||||||||||||||||||||||||||
| 92 | } @$rings) | ||||||||||||||||||||||||||||||||||||||||||
| 93 | . ')'; | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | return $class->new(wkt => $wkt, srid => $args{srid}, geometry_type => 'POLYGON'); | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | sub bbox_polygon { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bbox_polygon: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | my ($class, $xmin, $ymin, $xmax, $ymax, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | return $class->polygon( | |||||||||||||||||||||||||||||||||||||||||
| 101 | [[ [$xmin,$ymin], [$xmax,$ymin], [$xmax,$ymax], [$xmin,$ymax], [$xmin,$ymin] ]], | ||||||||||||||||||||||||||||||||||||||||||
| 102 | %args, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | ▶ | sub from_geojson { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_geojson: called CC=12 SCAR=30.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | my ($class, $gj, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | ▶ | my $srid = exists $args{srid} ? $args{srid} : 4326; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | my $type = $gj->{type} | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | or DBIO::Exception->throw("from_geojson: missing 'type'"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | my $coords = $gj->{coordinates}; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | my $wkt; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | if ($type eq 'Point') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | $wkt = 'POINT(' . join(' ', @$coords) . ')'; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | ▶ | elsif ($type eq 'LineString' or $type eq 'MultiPoint') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "LineString" or $type eq "MultiPoint"
MC/DC0%0/2
$type eq "LineString" or $type eq "MultiPoint"
$type eq "LineString"
$type eq "MultiPoint"
Truth table33%1/3
A or B
A= $type eq "LineString"B= $type eq "MultiPoint"
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $wkt = uc($type =~ s/(?<=[a-z])(?=[A-Z])/ /gr) =~ s/ //gr; | |||||||||||||||||||||||||||||||||||||||||
| 119 | $wkt = ($type eq 'LineString' ? 'LINESTRING' : 'MULTIPOINT') | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | . '(' . join(',', map { join ' ', @$_ } @$coords) . ')'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | ▶ | elsif ($type eq 'Polygon' or $type eq 'MultiLineString') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$type eq "Polygon" or $type eq "MultiLineString"
MC/DC50%1/2
$type eq "Polygon" or $type eq "MultiLineString"
$type eq "Polygon"
$type eq "MultiLineString"
Truth table66%2/3
A or B
A= $type eq "Polygon"B= $type eq "MultiLineString"
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | $wkt = ($type eq 'Polygon' ? 'POLYGON' : 'MULTILINESTRING') . '(' | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | . join(',', map { '(' . join(',', map { join ' ', @$_ } @$_) . ')' } @$coords) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | . ')'; | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | elsif ($type eq 'MultiPolygon') { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | $wkt = 'MULTIPOLYGON(' | ||||||||||||||||||||||||||||||||||||||||||
| 129 | . join(',', | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | map { '(' | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | . join(',', map { '(' . join(',', map { join ' ', @$_ } @$_) . ')' } @$_) | |||||||||||||||||||||||||||||||||||||||||
| 132 | . ')' | ||||||||||||||||||||||||||||||||||||||||||
| 133 | } @$coords) | ||||||||||||||||||||||||||||||||||||||||||
| 134 | . ')'; | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | DBIO::Exception->throw("from_geojson: unsupported type '$type'"); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | return $class->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | wkt => $wkt, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | srid => $srid, | ||||||||||||||||||||||||||||||||||||||||||
| 142 | geometry_type => uc($wkt =~ /\A([A-Z]+)/ ? $1 : ''), | ||||||||||||||||||||||||||||||||||||||||||
| 143 | coordinates => $coords, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 9 | ▶ | sub srid { $_[0]{srid} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
srid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 16 | ▶ | sub wkt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wkt: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 16 | ▶ | return $self->{wkt} if defined $self->{wkt}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return $self->to_wkt; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | sub ewkb_hex { $_[0]{ewkb_hex} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ewkb_hex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 6 | ▶ | sub geometry_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
geometry_type: called CC=4 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 6 | ▶ | return $self->{geometry_type} if defined $self->{geometry_type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if (defined $self->{wkt} && $self->{wkt} =~ /\A\s*([A-Z]+)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"wkt"} and $self->{"wkt"} =~ /\A\s*([A-Z]+)/i
MC/DC0%0/2
defined $self->{"wkt"} and $self->{"wkt"} =~ /\A\s*([A-Z]+)/i
defined $self->{"wkt"}
$self->{"wkt"} =~ /\A\s*([A-Z]+)/i
Truth table0%0/3
A and B
A= defined $self->{"wkt"}B= $self->{"wkt"} =~ /\A\s*([A-Z]+)/i
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return $self->{geometry_type} = uc $1; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | ▶ | sub ewkt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ewkt: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | my $wkt = $self->wkt; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | ▶ | return undef unless defined $wkt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | ▶ | return defined $self->{srid} ? "SRID=$self->{srid};$wkt" : $wkt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | ▶ | sub to_wkt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_wkt: called CC=3 SCAR=15.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | ▶ | return $self->{wkt} if defined $self->{wkt}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | return DBIO::PostgreSQL::PostGIS::Codec::WKT::Builder->build({ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | type => $self->geometry_type, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | coords => $self->coordinates, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | has_z => (defined $self->z ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||
| 181 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 14 | ▶ | sub coordinates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
coordinates: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 14 | ▶ | return $self->{coordinates} if defined $self->{coordinates}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | my $wkt = $self->wkt; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 5 | ▶ | return undef unless defined $wkt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | my $parsed = DBIO::PostgreSQL::PostGIS::Codec::WKT::Parser->parse($wkt); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | ▶ | return $self->{coordinates} = $parsed ? $parsed->{coords} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | ▶ | sub x { my $c = $_[0]->coordinates; ref $c eq 'ARRAY' ? $c->[0] : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x: called CC=2 SCAR=7.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | sub y { my $c = $_[0]->coordinates; ref $c eq 'ARRAY' ? $c->[1] : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
y: called CC=2 SCAR=7.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub z { my $c = $_[0]->coordinates; ref $c eq 'ARRAY' ? $c->[2] : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
z: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | ▶ | sub is_empty { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_empty: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | my $wkt = $self->wkt; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | ▶ | return defined $wkt && $wkt =~ /EMPTY\b/i ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $wkt and $wkt =~ /EMPTY\b/i
MC/DC50%1/2
defined $wkt and $wkt =~ /EMPTY\b/i
defined $wkt
$wkt =~ /EMPTY\b/i
Truth table66%2/3
A and B
A= defined $wktB= $wkt =~ /EMPTY\b/i
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | ▶ | sub bbox { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bbox: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 4 | my $coords = $self->coordinates; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | ▶ | return undef unless defined $coords; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | my (@xs, @ys); | |||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | _walk_xy($coords, \@xs, \@ys); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 4 | ▶ | return undef unless @xs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 4 | my @sx = sort { $a <=> $b } @xs; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | my @sy = sort { $a <=> $b } @ys; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 4 | return [ $sx[0], $sy[0], $sx[-1], $sy[-1] ]; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 33 | ▶ | sub _walk_xy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_walk_xy: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 33 | my ($node, $xs, $ys) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 33 | ▶ | return unless ref $node eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 33 | ▶ | if (@$node && !ref $node->[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$node and not ref $node->[0]
MC/DC50%1/2
@$node and not ref $node->[0]
@$node
not ref $node->[0]
Truth table66%2/3
A and not(B)
A= @$nodeB= not ref $node->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 23 | push @$xs, $node->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 23 | push @$ys, $node->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 23 | return; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 10 | _walk_xy($_, $xs, $ys) for @$node; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | ▶ | sub to_geojson { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_geojson: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | ▶ | my $type = $self->geometry_type or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | my $coords = $self->coordinates; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | ▶ | return undef unless defined $coords; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | my %map = ( | |||||||||||||||||||||||||||||||||||||||||
| 237 | POINT => 'Point', LINESTRING => 'LineString', POLYGON => 'Polygon', | ||||||||||||||||||||||||||||||||||||||||||
| 238 | MULTIPOINT => 'MultiPoint', MULTILINESTRING => 'MultiLineString', | ||||||||||||||||||||||||||||||||||||||||||
| 239 | MULTIPOLYGON => 'MultiPolygon', | ||||||||||||||||||||||||||||||||||||||||||
| 240 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | ▶ | my $gj_type = $map{$type} or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | return { type => $gj_type, coordinates => $coords }; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub to_ogr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_ogr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | require Geo::OGR; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return Geo::OGR::Geometry->new(WKT => $self->wkt); | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | DBIO::PostgreSQL::PostGIS::Geometry - Lightweight PostGIS geometry/geography value object | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | version 0.900001 | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | use DBIO::PostgreSQL::PostGIS::Geometry; | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | # From WKT | ||||||||||||||||||||||||||||||||||||||||||
| 273 | my $point = DBIO::PostgreSQL::PostGIS::Geometry->from_wkt( | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 'POINT(13.4 52.5)', srid => 4326, | ||||||||||||||||||||||||||||||||||||||||||
| 275 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | # From WKB hex (what PostGIS returns by default) | ||||||||||||||||||||||||||||||||||||||||||
| 278 | my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_ewkb_hex($hex); | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | $point->srid; # 4326 | ||||||||||||||||||||||||||||||||||||||||||
| 281 | $point->geometry_type; # 'POINT' | ||||||||||||||||||||||||||||||||||||||||||
| 282 | $point->wkt; # 'POINT(13.4 52.5)' | ||||||||||||||||||||||||||||||||||||||||||
| 283 | $point->ewkt; # 'SRID=4326;POINT(13.4 52.5)' | ||||||||||||||||||||||||||||||||||||||||||
| 284 | $point->coordinates; # [13.4, 52.5] | ||||||||||||||||||||||||||||||||||||||||||
| 285 | $point->x; $point->y; | ||||||||||||||||||||||||||||||||||||||||||
| 286 | $point->is_empty; | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | # Helpers | ||||||||||||||||||||||||||||||||||||||||||
| 289 | $point->to_geojson; # { type => 'Point', coordinates => [...] } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | $point->bbox; # [xmin, ymin, xmax, ymax] | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | A lightweight Perl-side representation of a PostGIS geometry or geography | ||||||||||||||||||||||||||||||||||||||||||
| 295 | value. Stores SRID + WKT (lazily parsed). Optional inflate path through | ||||||||||||||||||||||||||||||||||||||||||
| 296 | L<Geo::OGR> when installed for heavy spatial operations. | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | This object is what L<DBIO::PostgreSQL::PostGIS> inflates C<geometry> | ||||||||||||||||||||||||||||||||||||||||||
| 299 | and C<geography> column values to. On the way out (deflate) it serializes | ||||||||||||||||||||||||||||||||||||||||||
| 300 | back to EWKT for the database. | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | =head2 from_wkt | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_wkt($wkt, srid => 4326); | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | Constructs from a Well-Known Text representation. | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | =head2 from_ewkt | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_ewkt('SRID=4326;POINT(0 0)'); | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | Parses an Extended WKT string (PostGIS's C<SRID=N;WKT> form). | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | =head2 from_ewkb_hex | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_ewkb_hex($hex); | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | Constructs from PostGIS's default hex-encoded EWKB output. Stores the | ||||||||||||||||||||||||||||||||||||||||||
| 321 | hex unparsed; geometry_type/coordinates are decoded lazily on demand. | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | =head2 point | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | my $p = DBIO::PostgreSQL::PostGIS::Geometry->point($x, $y, srid => 4326); | ||||||||||||||||||||||||||||||||||||||||||
| 326 | my $p = DBIO::PostgreSQL::PostGIS::Geometry->point($x, $y, $z, srid => 4326); | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | Constructs a POINT geometry. Accepts 2 or 3 numeric coords followed by | ||||||||||||||||||||||||||||||||||||||||||
| 329 | named options (currently just C<srid>). | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | =head2 from_lat_lon | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | my $p = DBIO::PostgreSQL::PostGIS::Geometry->from_lat_lon($lat, $lon); | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | Convenience for building a 4326 POINT from latitude/longitude. Note the | ||||||||||||||||||||||||||||||||||||||||||
| 336 | order: lat first (the human convention), but the WKT/PostGIS axis order | ||||||||||||||||||||||||||||||||||||||||||
| 337 | is C<POINT(lon lat)> — this method swaps for you. | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | =head2 linestring | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | my $l = DBIO::PostgreSQL::PostGIS::Geometry->linestring( | ||||||||||||||||||||||||||||||||||||||||||
| 342 | [[0,0],[1,1],[2,0]], srid => 4326, | ||||||||||||||||||||||||||||||||||||||||||
| 343 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | =head2 polygon | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | my $p = DBIO::PostgreSQL::PostGIS::Geometry->polygon( | ||||||||||||||||||||||||||||||||||||||||||
| 348 | [ [[0,0],[10,0],[10,10],[0,10],[0,0]] ], # outer ring + optional holes | ||||||||||||||||||||||||||||||||||||||||||
| 349 | srid => 4326, | ||||||||||||||||||||||||||||||||||||||||||
| 350 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | =head2 bbox_polygon | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | my $b = DBIO::PostgreSQL::PostGIS::Geometry->bbox_polygon( | ||||||||||||||||||||||||||||||||||||||||||
| 355 | $xmin, $ymin, $xmax, $ymax, srid => 4326, | ||||||||||||||||||||||||||||||||||||||||||
| 356 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | Convenience for an axis-aligned rectangle as a closed POLYGON ring. | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | =head2 from_geojson | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_geojson(\%geojson); | ||||||||||||||||||||||||||||||||||||||||||
| 363 | my $g = DBIO::PostgreSQL::PostGIS::Geometry->from_geojson(\%geojson, srid => 4326); | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | Builds from a GeoJSON-shaped hashref. SRID defaults to 4326 (per the | ||||||||||||||||||||||||||||||||||||||||||
| 366 | GeoJSON spec) unless overridden. | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | =head2 srid | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | =head2 wkt | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | =head2 ewkb_hex | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | =head2 geometry_type | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | The geometry type as an upper-case string: C<POINT>, C<LINESTRING>, | ||||||||||||||||||||||||||||||||||||||||||
| 377 | C<POLYGON>, C<MULTIPOINT>, C<MULTILINESTRING>, C<MULTIPOLYGON>, | ||||||||||||||||||||||||||||||||||||||||||
| 378 | C<GEOMETRYCOLLECTION>. Lazily derived from WKT or EWKB. | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | =head2 ewkt | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | Returns C<SRID=N;WKT> if SRID is set, otherwise the bare WKT. | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | =head2 to_wkt | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | Returns the WKT string. Uses stored wkt if available; otherwise builds | ||||||||||||||||||||||||||||||||||||||||||
| 387 | from coordinates using L<DBIO::PostgreSQL::PostGIS::Codec::WKT::Builder>. | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | =head2 coordinates | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | Returns the parsed coordinate structure for simple geometry types | ||||||||||||||||||||||||||||||||||||||||||
| 392 | (POINT → [x,y], LINESTRING → [[x,y],...], POLYGON → [[[x,y],...],...]). | ||||||||||||||||||||||||||||||||||||||||||
| 393 | Returns undef when the geometry is too complex to parse from WKT alone | ||||||||||||||||||||||||||||||||||||||||||
| 394 | (use L</to_geojson> via L<Geo::OGR> for those). | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | =head2 x | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | =head2 y | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | =head2 z | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | Convenience accessors for POINT geometries. | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | =head2 is_empty | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | True if this represents an empty geometry (e.g. C<POINT EMPTY>). | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | =head2 bbox | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | Returns the bounding box as C<[xmin, ymin, xmax, ymax]>. Requires | ||||||||||||||||||||||||||||||||||||||||||
| 411 | coordinate parsing or a Geo::OGR fallback. | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | =head2 to_geojson | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | Returns a GeoJSON-shaped hashref for the simple geometry types. | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | =head2 to_ogr | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | Returns a L<Geo::OGR::Geometry> object if Geo::OGR is installed; dies | ||||||||||||||||||||||||||||||||||||||||||
| 420 | otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | DBIO Authors | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 431 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | =cut | ||||||||||||||||||||||||||||||||||||||||||