File Coverage

lib/Neo4j/Types/Point.pm
Criterion Covered Total %
statement 25 25 100.0
branch 6 6 100.0
condition n/a
subroutine 12 12 100.0
pod 9 9 100.0
total 52 52 100.0


line stmt bran cond sub pod time code
1 2     2   79648 use strict;
  2         9  
  2         65  
2 2     2   9 use warnings;
  2         4  
  2         106  
3              
4             package Neo4j::Types::Point;
5             # ABSTRACT: Represents a Neo4j spatial point value
6             $Neo4j::Types::Point::VERSION = '1.00';
7              
8 2     2   11 use Carp qw(croak);
  2         2  
  2         750  
9              
10              
11             my %DIM = ( 4326 => 2, 4979 => 3, 7203 => 2, 9157 => 3 );
12              
13             sub new {
14 25     25 1 12015 my ($class, $srid, @coordinates) = @_;
15            
16 25 100       90 croak "Points must have SRID" unless defined $srid;
17 21         40 my $dim = $DIM{$srid};
18 21 100       66 croak "Unsupported SRID $srid" unless defined $dim;
19 17 100       101 croak "Points with SRID $srid must have $dim dimensions" if @coordinates < $dim;
20 11         60 return bless [ $srid, @coordinates[0 .. $dim - 1] ], $class;
21             }
22              
23              
24 2     2 1 8 sub X { shift->[1] }
25 2     2 1 11 sub Y { shift->[2] }
26 2     2 1 11 sub Z { shift->[3] }
27              
28 2     2 1 10 sub longitude { shift->[1] }
29 2     2 1 22 sub latitude { shift->[2] }
30 2     2 1 9 sub height { shift->[3] }
31              
32 7     7 1 1003 sub srid { shift->[0] }
33              
34 7     7 1 17 sub coordinates { @{$_[0]}[ 1 .. $#{$_[0]} ] }
  7         48  
  7         17  
35              
36              
37             1;
38              
39             =pod
40              
41             =encoding UTF-8
42              
43             =head1 NAME
44              
45             Neo4j::Types::Point - Represents a Neo4j spatial point value
46              
47             =head1 VERSION
48              
49             version 1.00
50              
51             =head1 SYNOPSIS
52              
53             $longitude = $point->X;
54             $latitude = $point->Y;
55             $height = $point->Z;
56             $neo4j_srid = $point->srid;
57            
58             @coords = ($x, $y, $z);
59             $point = Neo4j::Types::Point->new( $neo4j_srid, @coords );
60              
61             =head1 DESCRIPTION
62              
63             Represents a spatial point value in Neo4j. Includes coordinates in
64             two or three dimensions and a SRID that may define their semantics.
65              
66             The SRID and thereby the coordinate semantics are defined by Neo4j.
67             See L for details.
68              
69             This module makes no assumptions about its internal data structure.
70             While default implementations for all methods are provided,
71             inheritors are free to override these according to their needs.
72             The default implementations assume the data is stored in an array
73             reference whose order of elements matches that of
74             L
75             for Point2D/Point3D.
76              
77             Supported in Neo4j S and above.
78              
79             =head1 METHODS
80              
81             L implements the following methods.
82              
83             =head2 coordinates
84              
85             @coordinates = $point->coordinates;
86             ($x, $y, $z) = @coordinates;
87              
88             Retrieve the point's coordinates as a list.
89              
90             =head2 height
91              
92             $value = $point->height;
93              
94             Alias for L|/"Z">.
95              
96             =head2 latitude
97              
98             $value = $point->latitude;
99              
100             Alias for L|/"Y">.
101              
102             =head2 longitude
103              
104             $value = $point->longitude;
105              
106             Alias for L|/"X">.
107              
108             =head2 new
109              
110             $point = Neo4j::Types::Point->new($neo4j_srid, @coordinates);
111              
112             Creates a new Point instance with the specified value.
113              
114             This method will fail if the SRID provided is not supported by Neo4j
115             or if it requires a greater number of coordinates than provided.
116              
117             =head2 srid
118              
119             $neo4j_srid = $point->srid;
120              
121             Retrieve an identifier for this point's spatial reference system.
122             This SRID has no meaning outside the context of Neo4j; in particular,
123             it is B
124              
125             To date, Neo4j has defined four SRIDs: 4326, 4979, 7203, and 9157.
126             Every point retrieved from Neo4j is referred to a coordinate system
127             identified by one of them.
128              
129             =over
130              
131             =item Neo4j SRID 4326
132              
133             Geographical ellipsoidal coordinates, referred to WGS84
134             (but spherically developed with C in Cypher).
135             Axes: longitude (East), latitude (North). Units: decimal degrees.
136             Neo4j moniker: C.
137              
138             =item Neo4j SRID 4979
139              
140             Geographical ellipsoidal coordinates, referred to WGS84
141             (but spherically developed with C in Cypher).
142             Axes: longitude (East), latitude (North), height (Up).
143             Units: decimal degrees; height in metres. The height is
144             referred to the ellipsoid (which is not at sea level).
145             Neo4j moniker: C.
146              
147             =item Neo4j SRID 7203
148              
149             Coordinates in a two-dimensional Euclidian space (a plane).
150             The geodetic datum, axis orientation and units are all undefined,
151             but both axes must use the same unit.
152             Neo4j moniker: C.
153              
154             =item Neo4j SRID 9157
155              
156             Coordinates in a three-dimensional Euclidian space. The geodetic
157             datum, axis orientation and units are all undefined, but all axes
158             must use the same unit.
159             Neo4j moniker: C.
160              
161             =back
162              
163             The primary semantics of a Neo4j SRID can be easily determined by
164             simple boolean expressions.
165              
166             $is_geographic = $neo4j_srid == 4326 or $neo4j_srid == 4979;
167             $is_euclidian = $neo4j_srid == 7203 or $neo4j_srid == 9157;
168             $is_2d = $neo4j_srid == 4326 or $neo4j_srid == 7203;
169             $is_3d = $neo4j_srid == 4979 or $neo4j_srid == 9157;
170              
171             Note that Neo4j does not support geographic coordinates that are
172             referred to any other geodetic datum than WGS84 (such as GCJ02,
173             ETRS89, NAD27, or local datums), nor does it support geographic
174             coordinates that are referred to an unknown datum. While it is
175             technically possible to ignore Neo4j SRID semantics and just use
176             other geographic coordinate reference systems anyway, you should
177             be aware that this may create interoperability issues, particularly
178             if more than a single client uses the Neo4j database.
179              
180             Neo4j does I impose constraints on the datum of Euclidian
181             coordinates, so using (for example) cartesian coordinates referred
182             to WGS84 is possible. However, Neo4j does not offer a way to tag
183             point values with the datum they actually use. Care should be taken
184             not to mix different geodetic datums in the same database without
185             considering the interoperability issues that this may cause, again
186             particularly if more than a single client uses the Neo4j database.
187              
188             =head2 X
189              
190             $value = $point->X;
191              
192             Retrieve the point's first ordinate, also known as the abscissa.
193             Commonly used for the horizontal axis in an Euclidean plane or for
194             the geographical longitude.
195              
196             =head2 Y
197              
198             $value = $point->Y;
199              
200             Retrieve the point's second ordinate. Commonly used for the vertical
201             axis in an Euclidean plane or for the geographical latitude.
202              
203             =head2 Z
204              
205             $value = $point->Z;
206              
207             Retrieve the point's third ordinate. Commonly used for height.
208              
209             For points in coordinate systems that have no more than two
210             dimensions, this method returns an undefined value.
211              
212             =head1 BUGS
213              
214             The behaviour of the C method when called in scalar
215             context has not yet been defined.
216              
217             There are currently no methods named C, C, or C.
218             This is to avoid confusion with Perl's C operator.
219              
220             =head1 SEE ALSO
221              
222             =over
223              
224             =item * L
225              
226             =item * L<"Spatial values" in Neo4j Cypher Manual|https://neo4j.com/docs/cypher-manual/current/syntax/spatial/>
227              
228             =back
229              
230             =head1 AUTHOR
231              
232             Arne Johannessen
233              
234             =head1 COPYRIGHT AND LICENSE
235              
236             This software is Copyright (c) 2021 by Arne Johannessen.
237              
238             This is free software, licensed under:
239              
240             The Artistic License 2.0 (GPL Compatible)
241              
242             =cut
243              
244             __END__