| 1 | package Eve::Geometry; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use parent qw(Eve::Class); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | ▶ | use POSIX qw(strtod); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 4 | ▶ | use Eve::Geometry::Point; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 4 | ▶ | use Eve::Geometry::Polygon; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | =head1 NAME | ||||||||||
| 14 | |||||||||||
| 15 | B<Eve::Geometry> - an abstract geometry class for map projection purposes. | ||||||||||
| 16 | |||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||
| 18 | |||||||||||
| 19 | use Eve::Geometry; | ||||||||||
| 20 | |||||||||||
| 21 | my $geo = Eve::Geometry->from_string( | ||||||||||
| 22 | string => 'PostGIS textual geometry representation'); | ||||||||||
| 23 | |||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||
| 25 | |||||||||||
| 26 | The class is a base for a generic geometry object that is required in | ||||||||||
| 27 | all operations with objects on the map projection. | ||||||||||
| 28 | |||||||||||
| 29 | =head1 METHODS | ||||||||||
| 30 | |||||||||||
| 31 | =head2 B<from_string> | ||||||||||
| 32 | |||||||||||
| 33 | A static method that parses the PostGIS textual representation of a | ||||||||||
| 34 | geometry object and returns a corresponding object. | ||||||||||
| 35 | |||||||||||
| 36 | =head3 B<Arguments> | ||||||||||
| 37 | |||||||||||
| 38 | =over 4 | ||||||||||
| 39 | |||||||||||
| 40 | =item C<string> | ||||||||||
| 41 | |||||||||||
| 42 | =back | ||||||||||
| 43 | |||||||||||
| 44 | =head3 B<Returns> | ||||||||||
| 45 | |||||||||||
| 46 | =over 4 | ||||||||||
| 47 | |||||||||||
| 48 | =item C<Eve::Geometry> | ||||||||||
| 49 | |||||||||||
| 50 | an object that implements the C<Eve::Geometry> abstract class. | ||||||||||
| 51 | |||||||||||
| 52 | =back | ||||||||||
| 53 | |||||||||||
| 54 | =cut | ||||||||||
| 55 | |||||||||||
| 56 | 2 | ▶ | sub from_string { | ||||||||
|
Subroutine
from_string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 57 | 2 | my ($class, %arg_hash) = @_; | |||||||||
| 58 | 2 | Eve::Support::arguments(\%arg_hash, my ($string)); | |||||||||
| 59 | |||||||||||
| 60 | 2 | my $result; | |||||||||
| 61 | 2 | ▶ | if ($string =~ m/^POINT/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | |||||||||||
| 63 | 1 | $string =~ s/^POINT\(//; | |||||||||
| 64 | 1 | $string =~ s/\)$//g; | |||||||||
| 65 | |||||||||||
| 66 | 1 | my ($lng, $lat) = split(' ', $string); | |||||||||
| 67 | |||||||||||
| 68 | 1 | $lat = strtod($lat); | |||||||||
| 69 | 1 | $lng = strtod($lng); | |||||||||
| 70 | |||||||||||
| 71 | 1 | $result = Eve::Geometry::Point->new(data => [$lat, $lng]); | |||||||||
| 72 | } else { | ||||||||||
| 73 | 1 | $string =~ s/^POLYGON\(\(//; | |||||||||
| 74 | 1 | $string =~ s/\)\)$//g; | |||||||||
| 75 | |||||||||||
| 76 | 1 | my $data = []; | |||||||||
| 77 | 1 | my @pairs = split(',', $string); | |||||||||
| 78 | |||||||||||
| 79 | map { | ||||||||||
| 80 | 1 | my ($lng, $lat) = split(' ', $_); | |||||||||
| 81 | 3 | $lat = strtod($lat); | |||||||||
| 82 | 3 | $lng = strtod($lng); | |||||||||
| 83 | 3 | push @{$data}, [$lat, $lng]; | |||||||||
| 84 | } @pairs; | ||||||||||
| 85 | |||||||||||
| 86 | 1 | $result = Eve::Geometry::Polygon->new(data => $data); | |||||||||
| 87 | } | ||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | |||||||||||
| 91 | =head1 METHODS | ||||||||||
| 92 | |||||||||||
| 93 | =head2 B<clone()> | ||||||||||
| 94 | |||||||||||
| 95 | Clones and returns the object. | ||||||||||
| 96 | |||||||||||
| 97 | =head3 Returns | ||||||||||
| 98 | |||||||||||
| 99 | The object identical to self. | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||
| 102 | |||||||||||
| 103 | 2 | ▶ | sub clone { | ||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 104 | 2 | my ($self) = @_; | |||||||||
| 105 | |||||||||||
| 106 | 2 | return $self->new(data => $self->export()); | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | =head2 B<export()> | ||||||||||
| 110 | |||||||||||
| 111 | Returns an array reference with the representation of the geometry object. | ||||||||||
| 112 | |||||||||||
| 113 | =head3 Returns | ||||||||||
| 114 | |||||||||||
| 115 | C<ARRAY>. | ||||||||||
| 116 | |||||||||||
| 117 | =cut | ||||||||||
| 118 | |||||||||||
| 119 | 0 | ▶ | sub export { | ||||||||
|
Subroutine
export: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 120 | 0 | my ($self) = @_; | |||||||||
| 121 | |||||||||||
| 122 | 0 | return [$self->latitude, $self->longitude]; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | =head2 B<serialize()> | ||||||||||
| 126 | |||||||||||
| 127 | Returns a string representation of the geometry object. | ||||||||||
| 128 | |||||||||||
| 129 | =head3 Returns | ||||||||||
| 130 | |||||||||||
| 131 | C<ARRAY>. | ||||||||||
| 132 | |||||||||||
| 133 | =cut | ||||||||||
| 134 | |||||||||||
| 135 | 0 | ▶ | sub serialize { | ||||||||
|
Subroutine
serialize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 136 | 0 | my ($self) = @_; | |||||||||
| 137 | |||||||||||
| 138 | 0 | return 'POINT((' . join(' ', @{$self->export()}) . '))'; | |||||||||
| 139 | } | ||||||||||
| 140 | |||||||||||
| 141 | =head1 SEE ALSO | ||||||||||
| 142 | |||||||||||
| 143 | =over 4 | ||||||||||
| 144 | |||||||||||
| 145 | =item C<Eve::Class> | ||||||||||
| 146 | |||||||||||
| 147 | =back | ||||||||||
| 148 | |||||||||||
| 149 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 150 | |||||||||||
| 151 | Copyright 2012 Igor Zinovyev. | ||||||||||
| 152 | |||||||||||
| 153 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 154 | under the terms of either: the GNU General Public License as published | ||||||||||
| 155 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 156 | |||||||||||
| 157 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 158 | |||||||||||
| 159 | |||||||||||
| 160 | =head1 AUTHOR | ||||||||||
| 161 | |||||||||||
| 162 | =over 4 | ||||||||||
| 163 | |||||||||||
| 164 | =item L<Igor Zinovyev|mailto:zinigor@gmail.com> | ||||||||||
| 165 | |||||||||||
| 166 | =back | ||||||||||
| 167 | |||||||||||
| 168 | =cut | ||||||||||
| 169 | |||||||||||
| 170 | 4 | 1; | |||||||||