| 1 | package Geo::JSON::Simple; | ||||||||||||||
| 2 | 2 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | $Geo::JSON::Simple::AUTHORITY = 'cpan:GETTY'; | |||||||||||||
| 4 | } | ||||||||||||||
| 5 | { | ||||||||||||||
| 6 | 2 | $Geo::JSON::Simple::VERSION = '0.001'; | |||||||||||||
| 7 | } | ||||||||||||||
| 8 | # ABSTRACT: Simplified functions for generating Geo::JSON objects | ||||||||||||||
| 9 | |||||||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 2 | ▶ | use Exporter 'import'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 2 | ▶ | use Carp 'croak'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 2 | ▶ | use List::MoreUtils qw( | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | natatime | ||||||||||||||
| 16 | 2 | ); | |||||||||||||
| 17 | |||||||||||||||
| 18 | 2 | ▶ | use Geo::JSON; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 2 | ▶ | use Geo::JSON::Point; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | 2 | ▶ | use Geo::JSON::MultiPoint; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 21 | 2 | ▶ | use Geo::JSON::LineString; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 2 | ▶ | use Geo::JSON::MultiLineString; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | 2 | ▶ | use Geo::JSON::Polygon; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 24 | 2 | ▶ | use Geo::JSON::MultiPolygon; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 25 | 2 | ▶ | use Geo::JSON::Feature; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 26 | 2 | ▶ | use Geo::JSON::FeatureCollection; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 27 | 2 | ▶ | use Geo::JSON::GeometryCollection; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 28 | |||||||||||||||
| 29 | 2 | our @EXPORT = qw( | |||||||||||||
| 30 | |||||||||||||||
| 31 | point | ||||||||||||||
| 32 | multipoint | ||||||||||||||
| 33 | linestring | ||||||||||||||
| 34 | multilinestring | ||||||||||||||
| 35 | polygon | ||||||||||||||
| 36 | multipolygon | ||||||||||||||
| 37 | |||||||||||||||
| 38 | feature | ||||||||||||||
| 39 | featurecollection | ||||||||||||||
| 40 | geometrycollection | ||||||||||||||
| 41 | |||||||||||||||
| 42 | from_geo_json | ||||||||||||||
| 43 | |||||||||||||||
| 44 | ); | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 6 | ▶ | sub point { Geo::JSON::Point->new({ coordinates => [ $_[0], $_[1] ] }) } | ||||||||||||
|
Subroutine
point: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 47 | 1 | ▶ | sub multipoint { Geo::JSON::MultiPoint->new({ coordinates => [ _make_positions(@_) ] }) } | ||||||||||||
|
Subroutine
multipoint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | 1 | ▶ | sub linestring { Geo::JSON::LineString->new({ coordinates => [ _make_positions(@_) ] }) } | ||||||||||||
|
Subroutine
linestring: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 50 | 1 | ▶ | sub multilinestring { Geo::JSON::MultiLineString->new({ coordinates => [ map { | ||||||||||||
|
Subroutine
multilinestring: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 51 | 1 | [_make_positions(@{$_})] | |||||||||||||
| 52 | } @_ ] }) } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 1 | ▶ | sub polygon { Geo::JSON::Polygon->new({ coordinates => [ _make_linear_ring(@_) ] }) } | ||||||||||||
|
Subroutine
polygon: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 55 | 0 | ▶ | sub multipolygon { Geo::JSON::MultiPolygon->new({ coordinates => [ map { | ||||||||||||
|
Subroutine
multipolygon: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 56 | 0 | [_make_linear_ring(@{$_})] | |||||||||||||
| 57 | } @_ ] }) } | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 1 | ▶ | sub _make_linear_ring { map { | ||||||||||||
|
Subroutine
_make_linear_ring: called CC=1 SCAR=0.0
| |||||||||||||||
| 60 | 1 | my @coordlist = _make_positions(@{$_}); [@coordlist,$coordlist[0]] | |||||||||||||
| 61 | } @_ } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | 6 | ▶ | sub _make_positions { | ||||||||||||
|
Subroutine
_make_positions: called CC=2 SCAR=6.9
| |||||||||||||||
| 64 | 6 | my $it = natatime 2, @_; | |||||||||||||
| 65 | 6 | my @coords; | |||||||||||||
| 66 | 6 | ▶ | while (my @pair = $it->()) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | 22 | push @coords, [@pair]; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | 6 | return @coords; | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 3 | ▶ | sub feature { | ||||||||||||
|
Subroutine
feature: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 73 | 3 | my ( $object, %properties ) = @_; | |||||||||||||
| 74 | 3 | Geo::JSON::Feature->new({ | |||||||||||||
| 75 | geometry => $object, | ||||||||||||||
| 76 | properties => \%properties | ||||||||||||||
| 77 | }); | ||||||||||||||
| 78 | } | ||||||||||||||
| 79 | |||||||||||||||
| 80 | 1 | ▶ | sub featurecollection { | ||||||||||||
|
Subroutine
featurecollection: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||
| 81 | 1 | my @features; | |||||||||||||
| 82 | my $current_geometry; | ||||||||||||||
| 83 | 1 | my @args; | |||||||||||||
| 84 | 1 | for (@_) { | |||||||||||||
| 85 | 10 | ▶ | if (ref $_) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 86 | 2 | ▶ | if ($current_geometry) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 87 | 1 | push @features, feature($current_geometry, @args); | |||||||||||||
| 88 | 1 | @args = (); | |||||||||||||
| 89 | 1 | $current_geometry = $_; | |||||||||||||
| 90 | } else { | ||||||||||||||
| 91 | 1 | $current_geometry = $_; | |||||||||||||
| 92 | } | ||||||||||||||
| 93 | } elsif (!$current_geometry) { | ||||||||||||||
| 94 | 0 | croak "featurecollection needs to start with a geometry"; | |||||||||||||
| 95 | } else { | ||||||||||||||
| 96 | 8 | push @args, $_; | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | } | ||||||||||||||
| 99 | 1 | ▶ | if ($current_geometry) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 100 | 1 | push @features, feature($current_geometry, @args); | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | Geo::JSON::FeatureCollection->new({ | ||||||||||||||
| 103 | 1 | features => \@features | |||||||||||||
| 104 | }); | ||||||||||||||
| 105 | } | ||||||||||||||
| 106 | |||||||||||||||
| 107 | 1 | ▶ | sub geometrycollection { | ||||||||||||
|
Subroutine
geometrycollection: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 108 | 1 | Geo::JSON::GeometryCollection->new({ | |||||||||||||
| 109 | geometries => \@_ | ||||||||||||||
| 110 | }); | ||||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | 0 | ▶ | sub from_geo_json { Geo::JSON->from_json(@_) } | ||||||||||||
|
Subroutine
from_geo_json: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 114 | |||||||||||||||
| 115 | 2 | 1; | |||||||||||||
| 116 | |||||||||||||||
| 117 | __END__ | ||||||||||||||