line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::WKT::Simple; |
2
|
3
|
|
|
3
|
|
75665
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
119
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
89
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
2567
|
use parent 'Exporter'; |
|
3
|
|
|
|
|
924
|
|
|
3
|
|
|
|
|
15
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT; |
10
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
11
|
|
|
|
|
|
|
all => \@EXPORT, |
12
|
|
|
|
|
|
|
parse => [qw/ |
13
|
|
|
|
|
|
|
wkt_parse_point |
14
|
|
|
|
|
|
|
wkt_parse_linestring |
15
|
|
|
|
|
|
|
wkt_parse_multilinestring |
16
|
|
|
|
|
|
|
wkt_parse_polygon |
17
|
|
|
|
|
|
|
wkt_parse_multipolygon |
18
|
|
|
|
|
|
|
wkt_parse_geometrycollection |
19
|
|
|
|
|
|
|
wkt_parse |
20
|
|
|
|
|
|
|
/], |
21
|
|
|
|
|
|
|
make => [qw/ |
22
|
|
|
|
|
|
|
wkt_make_point |
23
|
|
|
|
|
|
|
wkt_make_linestring |
24
|
|
|
|
|
|
|
wkt_make_multilinestring |
25
|
|
|
|
|
|
|
wkt_make_polygon |
26
|
|
|
|
|
|
|
wkt_make_multipolygon |
27
|
|
|
|
|
|
|
wkt_make_geometrycollection |
28
|
|
|
|
|
|
|
wkt_make |
29
|
|
|
|
|
|
|
/], |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
@EXPORT = map { @{ $_ } } @EXPORT_TAGS{qw/ parse make /}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _parse_point { |
34
|
76
|
|
|
76
|
|
457
|
$_[0] =~ /^\s*(\S+)\s+(\S+)\s*$/ |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _parse_points_list { |
38
|
27
|
|
|
27
|
|
104
|
map { [ _parse_point($_) ] } split /\s*,\s*/, $_[0] |
|
71
|
|
|
|
|
118
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _parse_points_group { |
42
|
22
|
|
|
|
|
37
|
map { |
43
|
16
|
|
|
16
|
|
47
|
[ _parse_points_list($_) ] |
44
|
|
|
|
|
|
|
} split /\s*\)\s*,\s*\(\s*/, $_[0] |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _parse_points_group_list { |
48
|
6
|
|
|
|
|
13
|
map { |
49
|
4
|
|
|
4
|
|
18
|
[ _parse_points_group($_) ] |
50
|
|
|
|
|
|
|
} split /\s*\)\s*\)\s*,\s*\(\s*\(\s*/, $_[0] |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub wkt_parse_point { |
54
|
6
|
100
|
|
6
|
1
|
1028
|
my ($data) = $_[0] =~ /^point\s*\((.+)\)$/i |
55
|
|
|
|
|
|
|
or return; |
56
|
|
|
|
|
|
|
|
57
|
5
|
|
|
|
|
13
|
_parse_point($data); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub wkt_parse_linestring { |
61
|
6
|
100
|
|
6
|
1
|
1634
|
my ($data) = $_[0] =~ /^linestring\s*\((.+)\)$/i |
62
|
|
|
|
|
|
|
or return; |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
12
|
_parse_points_list($data); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub wkt_parse_multilinestring { |
68
|
6
|
100
|
|
6
|
1
|
1544
|
my ($data) = $_[0] =~ /^multilinestring\s*\(\s*\((.+)\)\s*\)$/i |
69
|
|
|
|
|
|
|
or return; |
70
|
|
|
|
|
|
|
|
71
|
5
|
|
|
|
|
14
|
_parse_points_group($data); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub wkt_parse_polygon { |
75
|
7
|
100
|
|
7
|
1
|
1611
|
my ($data) = $_[0] =~ /^polygon\s*\(\s*\((.+)\)\s*\)$/i |
76
|
|
|
|
|
|
|
or return; |
77
|
|
|
|
|
|
|
|
78
|
5
|
|
|
|
|
12
|
_parse_points_group($data); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub wkt_parse_multipolygon { |
82
|
4
|
50
|
|
4
|
1
|
1577
|
my ($data) = $_[0] =~ /^multipolygon\s*\(\s*\(\s*\((.+)\)\s*\)\s*\)$/i |
83
|
|
|
|
|
|
|
or return; |
84
|
|
|
|
|
|
|
|
85
|
4
|
|
|
|
|
11
|
_parse_points_group_list($data); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $ALLTYPES = 'POINT|(?:MULTI)?(?:LINESTRING|POLYGON)|GEOMETRYCOLLECTION'; |
89
|
|
|
|
|
|
|
sub wkt_parse_geometrycollection { |
90
|
3
|
50
|
|
3
|
1
|
1609
|
my ($wkt) = $_[0] =~ /^geometrycollection\s*\((.+)\)$/i |
91
|
|
|
|
|
|
|
or return; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Copy from Geo::WKT |
94
|
3
|
|
|
|
|
5
|
my @comps; |
95
|
3
|
|
|
|
|
11
|
while ($wkt =~ /\D/) { |
96
|
7
|
100
|
|
|
|
47
|
last unless $wkt =~ s/^[^(]*\([^)]*\)//; |
97
|
6
|
|
|
|
|
13
|
my $take = $&; |
98
|
6
|
|
|
|
|
7
|
while (1) { |
99
|
10
|
|
|
|
|
26
|
my @open = $take =~ /\(/g; |
100
|
10
|
|
|
|
|
17
|
my @close = $take =~ /\)/g; |
101
|
10
|
100
|
|
|
|
23
|
last if @open == @close; |
102
|
4
|
50
|
|
|
|
21
|
$take .= $& if $wkt =~ s/^[^\)]*\)//; |
103
|
|
|
|
|
|
|
} |
104
|
6
|
|
|
|
|
66
|
my ($type) = $take =~ /^($ALLTYPES)/i; |
105
|
6
|
|
|
|
|
16
|
push @comps, [ uc($type) => [ wkt_parse($type => $take) ] ]; |
106
|
|
|
|
|
|
|
|
107
|
6
|
|
|
|
|
30
|
$wkt =~ s/^\s*,\s*//; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
30
|
@comps; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub wkt_parse { |
114
|
13
|
|
|
13
|
1
|
1722
|
my ($type, $wkt) = @_; |
115
|
|
|
|
|
|
|
|
116
|
13
|
100
|
|
|
|
143
|
return if $type !~ /^$ALLTYPES$/i; |
117
|
12
|
|
|
|
|
90
|
__PACKAGE__->can('wkt_parse_'.lc($type))->($wkt); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _cat { |
121
|
41
|
|
|
41
|
|
223
|
'('.join(', ', @_).')' |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _catlinestring { |
125
|
21
|
|
|
21
|
|
27
|
_cat( map { "$_->[0] $_->[1]" } @_ ) |
|
66
|
|
|
|
|
279
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _catpolygon { |
129
|
11
|
|
|
11
|
|
16
|
_cat( map { _catlinestring(@$_) } @_ ) |
|
16
|
|
|
|
|
30
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub wkt_make_point { |
133
|
5
|
|
|
5
|
1
|
768
|
'POINT'._cat("$_[0] $_[1]") |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub wkt_make_linestring { |
137
|
5
|
|
|
5
|
1
|
1447
|
'LINESTRING'._catlinestring(@_) |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub wkt_make_multilinestring { |
141
|
2
|
|
|
2
|
1
|
1289
|
'MULTILINESTRING'._catpolygon(@_) |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub wkt_make_polygon { |
145
|
5
|
|
|
5
|
1
|
1527
|
'POLYGON'._catpolygon(@_) |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub wkt_make_multipolygon { |
149
|
4
|
|
|
|
|
9
|
'MULTIPOLYGON'._cat( |
150
|
2
|
|
|
2
|
1
|
1197
|
map { _catpolygon(@$_) } @_ |
151
|
|
|
|
|
|
|
) |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub wkt_make_geometrycollection { |
155
|
2
|
|
|
2
|
1
|
1314
|
'GEOMETRYCOLLECTION'._cat( map { wkt_make(@$_) } @_ ) |
|
6
|
|
|
|
|
17
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub wkt_make { |
159
|
13
|
|
|
13
|
1
|
1403
|
my ($type, $data) = @_; |
160
|
|
|
|
|
|
|
|
161
|
13
|
100
|
|
|
|
175
|
return if $type !~ /^$ALLTYPES$/i; |
162
|
12
|
|
|
|
|
103
|
__PACKAGE__->can('wkt_make_'.lc($type))->(@$data); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
166
|
|
|
|
|
|
|
__END__ |