| 1 | package DBIO::PostgreSQL::PostGIS::Geometry; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Lightweight PostGIS geometry/geography value object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use DBIO::Exception (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use DBIO::PostgreSQL::PostGIS::Codec::WKT::Parser (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use DBIO::PostgreSQL::PostGIS::Codec::WKT::Builder (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use DBIO::PostgreSQL::PostGIS::Codec::WKB::Decoder (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 189 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 189 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | srid => $args{srid}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | wkt => $args{wkt}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ewkb_hex => $args{ewkb_hex}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | geometry_type => defined $args{geometry_type} ? uc $args{geometry_type} : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | coordinates => $args{coordinates}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | has_z => $args{has_z}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | has_m => $args{has_m}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | is_empty => $args{is_empty}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 189 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 189 | return bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 41 | ▶ | sub from_wkt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_wkt: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 41 | my ($class, $wkt, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 41 | ▶ | DBIO::Exception->throw("from_wkt requires a WKT string") unless defined $wkt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 40 | my $parsed = DBIO::PostgreSQL::PostGIS::Codec::WKT::Parser->parse($wkt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | return $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | wkt => $wkt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | srid => $args{srid}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | geometry_type => $parsed ? $parsed->{type} : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | coordinates => $parsed ? $parsed->{coords} : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 40 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 28 | ▶ | sub from_ewkt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_ewkt: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 28 | my ($class, $ewkt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 28 | ▶ | DBIO::Exception->throw("from_ewkt requires an EWKT string") unless defined $ewkt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 27 | ▶ | if ($ewkt =~ /\A\s*srid=(\d+)\s*;\s*(.+)\z/is) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 25 | return $class->new(srid => $1, wkt => $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | return $class->new(wkt => $ewkt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 72 | ▶ | sub from_ewkb_hex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_ewkb_hex: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 72 | my ($class, $hex) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 72 | ▶ | DBIO::Exception->throw("from_ewkb_hex requires an EWKB hex string") unless defined $hex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 71 | my $decoder = 'DBIO::PostgreSQL::PostGIS::Codec::WKB::Decoder'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 71 | my $decoded = eval { $decoder->decode_hex($hex) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 71 | ▶ | unless ($decoded) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # No value: no object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 11 | ▶ | return undef unless length $hex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # Refused by the decoder. It is a value all the same and must not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # read as none; its header, if it has one, says what it claims to be. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 10 | ▶ | $decoded = eval { $decoder->decode_header($hex) } // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
eval {
do {
$decoder->decode_header($hex)
}
} // {}
MC/DC100%1/1
eval {
do {
$decoder->decode_header($hex)
}
} // {}
eval {
do {
$decoder->decode_header($hex)
}
}
Truth table100%2/2
A
A= eval {
do {
$decoder->decode_header($hex)
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | return $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ewkb_hex => $hex, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | srid => $decoded->{srid}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | geometry_type => $decoded->{type}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | coordinates => $decoded->{coords}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | has_z => $decoded->{has_z}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | has_m => $decoded->{has_m}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | is_empty => $decoded->{is_empty}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 70 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 9 | ▶ | sub point { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
point: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 9 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 9 | my @coords; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 9 | ▶ | push @coords, shift while @_ && !ref $_[0] && $_[0] =~ /\A-?[0-9.eE+\-]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@_ and not ref $_[0] and $_[0] =~ /\A-?[0-9.eE+\-]+\z/
@_ and not ref $_[0]
MC/DC66%2/3
@_ and not ref $_[0] and $_[0] =~ /\A-?[0-9.eE+\-]+\z/
@_
not ref $_[0]
$_[0] =~ /\A-?[0-9.eE+\-]+\z/
Truth table75%3/4
A and not(B) and C
A= @_B= not ref $_[0]C= $_[0] =~ /\A-?[0-9.eE+\-]+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 9 | my $wkt = 'POINT(' . join(' ', @coords) . ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 9 | return $class->new(wkt => $wkt, srid => $args{srid}, geometry_type => 'POINT'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | sub from_lat_lon { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_lat_lon: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | my ($class, $lat, $lon) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | return $class->point($lon, $lat, srid => 4326); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 5 | ▶ | sub linestring { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
linestring: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | my ($class, $coords, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 5 | my $wkt = 'LINESTRING(' . join(',', map { join ' ', @$_ } @$coords) . ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | return $class->new(wkt => $wkt, srid => $args{srid}, geometry_type => 'LINESTRING'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 5 | ▶ | sub polygon { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
polygon: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 5 | my ($class, $rings, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | my $wkt = 'POLYGON(' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | . join(',', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | '(' . join(',', map { join ' ', @$_ } @$_) . ')' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } @$rings) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | . ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | return $class->new(wkt => $wkt, srid => $args{srid}, geometry_type => 'POLYGON'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | ▶ | sub bbox_polygon { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bbox_polygon: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | my ($class, $xmin, $ymin, $xmax, $ymax, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | return $class->polygon( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | [[ [$xmin,$ymin], [$xmax,$ymin], [$xmax,$ymax], [$xmin,$ymax], [$xmin,$ymin] ]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | %args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 10 | ▶ | sub from_geojson { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_geojson: called CC=12 SCAR=26.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 10 | my ($class, $gj, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 10 | ▶ | my $srid = exists $args{srid} ? $args{srid} : 4326; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | my $type = $gj->{type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 10 | ▶ | or DBIO::Exception->throw("from_geojson: missing 'type'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 9 | my $coords = $gj->{coordinates}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 9 | my $wkt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 9 | ▶ | if ($type eq 'Point') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | $wkt = 'POINT(' . join(' ', @$coords) . ')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ▶ | elsif ($type eq 'LineString' or $type eq 'MultiPoint') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$type eq "LineString" or $type eq "MultiPoint"
MC/DC100%2/2
$type eq "LineString" or $type eq "MultiPoint"
$type eq "LineString"
$type eq "MultiPoint"
Truth table100%3/3
A or B
A= $type eq "LineString"B= $type eq "MultiPoint"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | $wkt = ($type eq 'LineString' ? 'LINESTRING' : 'MULTIPOINT') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | ▶ | . '(' . join(',', map { join ' ', @$_ } @$coords) . ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | $wkt = ($type eq 'Polygon' ? 'POLYGON' : 'MULTILINESTRING') . '(' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | . join(',', map { '(' . join(',', map { join ' ', @$_ } @$_) . ')' } @$coords) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | . ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | elsif ($type eq 'MultiPolygon') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | $wkt = 'MULTIPOLYGON(' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | . join(',', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | map { '(' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | . join(',', map { '(' . join(',', map { join ' ', @$_ } @$_) . ')' } @$_) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | . ')' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } @$coords) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | . ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | DBIO::Exception->throw("from_geojson: unsupported type '$type'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 8 | ▶ | return $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | wkt => $wkt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | srid => $srid, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | geometry_type => uc($wkt =~ /\A([A-Z]+)/ ? $1 : ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | coordinates => $coords, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 36 | ▶ | sub srid { $_[0]{srid} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
srid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 253 | ▶ | sub wkt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wkt: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 253 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 253 | ▶ | return $self->{wkt} if defined $self->{wkt}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 159 | return $self->to_wkt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 77 | ▶ | sub ewkb_hex { $_[0]{ewkb_hex} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ewkb_hex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 400 | ▶ | sub geometry_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
geometry_type: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 400 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 400 | ▶ | return $self->{geometry_type} if defined $self->{geometry_type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 53 | ▶ | if (defined $self->{wkt} && $self->{wkt} =~ /\A\s*([A-Z]+)/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"wkt"} and $self->{"wkt"} =~ /\A\s*([A-Z]+)/i
MC/DC50%1/2
defined $self->{"wkt"} and $self->{"wkt"} =~ /\A\s*([A-Z]+)/i
defined $self->{"wkt"}
$self->{"wkt"} =~ /\A\s*([A-Z]+)/i
Truth table66%2/3
A and B
A= defined $self->{"wkt"}B= $self->{"wkt"} =~ /\A\s*([A-Z]+)/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # ST_AsEWKT glues the M of a measured geometry to the type: POINTM(...). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # No geometry type ends in Z or M, so the marker is told by that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 15 | (my $type = uc $1) =~ s/(?:ZM|Z|M)\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 15 | return $self->{geometry_type} = $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 38 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 56 | ▶ | sub ewkt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ewkt: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 56 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 56 | my $wkt = $self->wkt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 56 | ▶ | return undef unless defined $wkt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 43 | ▶ | return defined $self->{srid} ? "SRID=$self->{srid};$wkt" : $wkt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 199 | ▶ | sub to_wkt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_wkt: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 199 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 199 | ▶ | return $self->{wkt} if defined $self->{wkt}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # The stored coordinates, not ->coordinates: without them that method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # asks for the WKT, which is this one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 197 | my $coords = $self->{coordinates}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 197 | ▶ | return undef unless defined $coords; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # Coordinates are not a WKT without the type they are coordinates of; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # the builder would write '()'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 103 | ▶ | return undef unless defined $self->geometry_type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 93 | my ($has_z, $has_m) = $self->_dimension_flags($coords); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | return DBIO::PostgreSQL::PostGIS::Codec::WKT::Builder->build({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | type => $self->geometry_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | coords => $coords, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | has_z => $has_z, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | has_m => $has_m, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | is_empty => $self->{is_empty}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 93 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # Why this object cannot be written to the database or bound as a helper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # argument, as the message of the exception for it (karr k23); undef when it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # can. A hex, a WKT or coordinates under a type are a writable form. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 26 | ▶ | sub _unwritable_reason { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unwritable_reason: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 26 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 26 | my $hex = $self->ewkb_hex; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 26 | ▶ | return undef if defined $hex && length $hex; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $hex and length $hex
MC/DC100%2/2
defined $hex and length $hex
defined $hex
length $hex
Truth table100%3/3
A and B
A= defined $hexB= length $hex
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 19 | ▶ | return undef if defined $self->wkt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | return 'Geometry has coordinates but no geometry_type, so no WKT can be built from them' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 8 | ▶ | if defined $self->{coordinates}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 4 | return 'Geometry has no ewkb_hex, wkt or coordinates, so there is nothing to write'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # Z/M of a geometry that has no WKT to say it: the flags given to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # constructor, else the number of ordinates of one point. Never the shape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # of the coordinate list -- its third element is a Z only for a POINT; for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # a line it is the third point, for a polygon the third ring. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 93 | ▶ | sub _dimension_flags { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dimension_flags: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 93 | my ($self, $coords) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 93 | ▶ | if (defined $self->{has_z} or defined $self->{has_m}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"has_z"} or defined $self->{"has_m"}
MC/DC100%2/2
defined $self->{"has_z"} or defined $self->{"has_m"}
defined $self->{"has_z"}
defined $self->{"has_m"}
Truth table100%3/3
A or B
A= defined $self->{"has_z"}B= defined $self->{"has_m"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 85 | ▶ | return ($self->{has_z} ? 1 : 0, $self->{has_m} ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 8 | my $point = $coords; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 8 | ▶ | $point = $point->[0] while ref $point eq 'ARRAY' and ref $point->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $point eq "ARRAY" and ref $point->[0]
MC/DC50%1/2
ref $point eq "ARRAY" and ref $point->[0]
ref $point eq "ARRAY"
ref $point->[0]
Truth table66%2/3
A and B
A= ref $point eq "ARRAY"B= ref $point->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | ▶ | my $ordinates = ref $point eq 'ARRAY' ? scalar @$point : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 8 | ▶ | return ($ordinates >= 3 ? 1 : 0, $ordinates >= 4 ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 178 | ▶ | sub coordinates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
coordinates: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 178 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 178 | ▶ | return $self->{coordinates} if defined $self->{coordinates}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 66 | my $wkt = $self->wkt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 66 | ▶ | return undef unless defined $wkt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 24 | my $parsed = DBIO::PostgreSQL::PostGIS::Codec::WKT::Parser->parse($wkt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 24 | ▶ | return $self->{coordinates} = $parsed ? $parsed->{coords} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 89 | ▶ | sub _point_ordinate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_point_ordinate: called CC=14 SCAR=27.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 89 | my ($self, $i) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 89 | my $type = $self->geometry_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 89 | ▶ | return undef unless defined $type && $type eq 'POINT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $type and $type eq "POINT"
MC/DC100%2/2
defined $type and $type eq "POINT"
defined $type
$type eq "POINT"
Truth table100%3/3
A and B
A= defined $typeB= $type eq "POINT"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 35 | my $c = $self->coordinates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 35 | ▶ | return undef unless ref $c eq 'ARRAY' && !ref $c->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $c eq "ARRAY" and not ref $c->[0]
MC/DC50%1/2
ref $c eq "ARRAY" and not ref $c->[0]
ref $c eq "ARRAY"
not ref $c->[0]
Truth table66%2/3
A and not(B)
A= ref $c eq "ARRAY"B= not ref $c->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 29 | ▶ | return $c->[$i] if $i < 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 8 | ▶ | return undef unless @$c > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # A third ordinate of a measured point is M, not Z. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | ▶ | if (@$c == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | ▶ | return undef if $self->{has_m} && !$self->{has_z}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"has_m"} and not $self->{"has_z"}
MC/DC0%0/2
$self->{"has_m"} and not $self->{"has_z"}
$self->{"has_m"}
not $self->{"has_z"}
Truth table33%1/3
A and not(B)
A= $self->{"has_m"}B= not $self->{"has_z"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | my $wkt = $self->{wkt}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | return undef if !defined $self->{has_z} && !defined $self->{has_m} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 4 | ▶ | && defined $wkt && $wkt =~ /\A\s*POINT\s*M\b/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
not defined $self->{"has_z"} || defined $self->{"has_m"} and defined $wkt and $wkt =~ /\A\s*POINT\s*M\b/i
not defined $self->{"has_z"} || defined $self->{"has_m"} and defined $wkt
defined $self->{'has_z'} || defined $self->{'has_m'}
MC/DC25%1/4
not defined $self->{"has_z"} || defined $self->{"has_m"} and defined $wkt and $wkt =~ /\A\s*POINT\s*M\b/i
defined $self->{'has_z'}
defined $self->{'has_m'}
defined $wkt
$wkt =~ /\A\s*POINT\s*M\b/i
Truth table40%2/5
not(A || B) and C and D
A= defined $self->{'has_z'}B= defined $self->{'has_m'}C= defined $wktD= $wkt =~ /\A\s*POINT\s*M\b/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 3 | return $c->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 36 | ▶ | sub x { $_[0]->_point_ordinate(0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 27 | ▶ | sub y { $_[0]->_point_ordinate(1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
y: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 26 | ▶ | sub z { $_[0]->_point_ordinate(2) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
z: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 44 | ▶ | sub is_empty { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_empty: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 44 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 44 | ▶ | return $self->{is_empty} ? 1 : 0 if defined $self->{is_empty}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 29 | my $wkt = $self->wkt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # A number in the WKT is a real ordinate: EMPTY as one part of several | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # (MULTIPOINT(EMPTY,(1 2))) does not make the whole empty. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 29 | ▶ | return defined $wkt && $wkt =~ /EMPTY\b/i && $wkt !~ /[0-9]/ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $wkt and $wkt =~ /EMPTY\b/i and not $wkt =~ /[0-9]/
defined $wkt and $wkt =~ /EMPTY\b/i
MC/DC100%3/3
defined $wkt and $wkt =~ /EMPTY\b/i and not $wkt =~ /[0-9]/
defined $wkt
$wkt =~ /EMPTY\b/i
not $wkt =~ /[0-9]/
Truth table100%4/4
A and B and not(C)
A= defined $wktB= $wkt =~ /EMPTY\b/iC= not $wkt =~ /[0-9]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 30 | ▶ | sub bbox { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bbox: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 30 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 30 | my $coords = $self->coordinates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 30 | ▶ | return undef unless defined $coords; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 18 | my (@xs, @ys); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 18 | _walk_xy($coords, \@xs, \@ys); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 18 | ▶ | return undef unless @xs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 9 | my @sx = sort { $a <=> $b } @xs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 9 | my @sy = sort { $a <=> $b } @ys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 9 | return [ $sx[0], $sy[0], $sx[-1], $sy[-1] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 60 | ▶ | sub _walk_xy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_walk_xy: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 60 | my ($node, $xs, $ys) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # A member of a collection: its type does not matter for the extent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 60 | ▶ | $node = $node->{coords} if ref $node eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 60 | ▶ | return unless ref $node eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 60 | ▶ | if (@$node && !ref $node->[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$node and not ref $node->[0]
MC/DC100%2/2
@$node and not ref $node->[0]
@$node
not ref $node->[0]
Truth table100%3/3
A and not(B)
A= @$nodeB= not ref $node->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 33 | push @$xs, $node->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 33 | push @$ys, $node->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 33 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 27 | _walk_xy($_, $xs, $ys) for @$node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 60 | ▶ | sub to_geojson { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_geojson: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 60 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 60 | ▶ | my $type = $self->geometry_type or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 54 | my $coords = $self->coordinates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 54 | ▶ | if ($type eq 'GEOMETRYCOLLECTION') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # A collection from WKT has no coordinates (the parser does not read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # it); it is known to be empty, and then it has no members to give. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 7 | ▶ | return { type => 'GeometryCollection', geometries => [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $coords and $self->is_empty
MC/DC0%0/2
not defined $coords and $self->is_empty
not defined $coords
$self->is_empty
Truth table66%2/3
not(A) and B
A= not defined $coordsB= $self->is_empty
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | if !defined $coords && $self->is_empty; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 54 | ▶ | return undef unless defined $coords; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 48 | return _geojson($type, $coords); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # GeoJSON of one geometry, or a member of a collection: undef for a type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # GeoJSON has no name for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 54 | ▶ | sub _geojson { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_geojson: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 54 | my ($type, $coords) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 54 | my %map = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | POINT => 'Point', LINESTRING => 'LineString', POLYGON => 'Polygon', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | MULTIPOINT => 'MultiPoint', MULTILINESTRING => 'MultiLineString', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | MULTIPOLYGON => 'MultiPolygon', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # The type of a collection member comes from the codec, lower-case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 54 | ▶ | if (uc $type eq 'GEOMETRYCOLLECTION') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 5 | my @geometries = map { _geojson($_->{type}, $_->{coords}) } @$coords; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 5 | return { type => 'GeometryCollection', geometries => \@geometries }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 49 | ▶ | my $gj_type = $map{uc $type} or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 49 | return { type => $gj_type, coordinates => $coords }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | sub to_ogr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_ogr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | require Geo::OGR; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return Geo::OGR::Geometry->new(WKT => $self->wkt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||