lib/Neo4j/Types/Point.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 9 / 9 totaltotal 100% 55 / 55 SCAR 13.9
CC
4
Cov
100%
new
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« lib/Neo4j/Types/Path.pm ↑ Summary lib/Neo4j/Types/Relationship.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Neo4j::Types::Point;
5 # ABSTRACT: Represents a Neo4j spatial point value
6 2 $Neo4j::Types::Point::VERSION = '1.00';
7  
8 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 2 my %DIM = ( 4326 => 2, 4979 => 3, 7203 => 2, 9157 => 3 );
12  
13 sub new {
14 25 ▶ my ($class, $srid, @coordinates) = @_;
Subroutine new: called CC=4 SCAR=13.9
Pod documented
15
16 25 ▶ croak "Points must have SRID" unless defined $srid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $srid 4 21 25
17 21 my $dim = $DIM{$srid};
18 21 ▶ croak "Unsupported SRID $srid" unless defined $dim;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dim 4 17 21
19 17 ▶ croak "Points with SRID $srid must have $dim dimensions" if @coordinates < $dim;
Branch: 1 branch
BranchTrueFalseTotal
if @coordinates < $dim 6 11 17
20 11 return bless [ $srid, @coordinates[0 .. $dim - 1] ], $class;
21 }
22  
23  
24 2 ▶sub X { shift->[1] }
Subroutine X: called CC=1 SCAR=0.0
Pod documented
25 2 ▶sub Y { shift->[2] }
Subroutine Y: called CC=1 SCAR=0.0
Pod documented
26 2 ▶sub Z { shift->[3] }
Subroutine Z: called CC=1 SCAR=0.0
Pod documented
27  
28 2 ▶sub longitude { shift->[1] }
Subroutine longitude: called CC=1 SCAR=0.0
Pod documented
29 2 ▶sub latitude { shift->[2] }
Subroutine latitude: called CC=1 SCAR=0.0
Pod documented
30 2 ▶sub height { shift->[3] }
Subroutine height: called CC=1 SCAR=0.0
Pod documented
31  
32 7 ▶sub srid { shift->[0] }
Subroutine srid: called CC=1 SCAR=0.0
Pod documented
33  
34 7 ▶sub coordinates { @{$_[0]}[ 1 .. $#{$_[0]} ] }
Subroutine coordinates: called CC=1 SCAR=0.0
Pod documented
35  
36  
37 2 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</"srid"> 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<Bolt PackStream|https://7687.org/packstream/packstream-specification-1.html#point2d---structure>
75 for Point2D/Point3D.
76  
77 Supported in Neo4j S<version 3.4> and above.
78  
79 =head1 METHODS
80  
81 L<Neo4j::Types::Point> 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<C<Z()>|/"Z">.
95  
96 =head2 latitude
97  
98 $value = $point->latitude;
99  
100 Alias for L<C<Y()>|/"Y">.
101  
102 =head2 longitude
103  
104 $value = $point->longitude;
105  
106 Alias for L<C<X()>|/"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<not an EPSG code.>
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<distance()> in Cypher).
135 Axes: longitude (East), latitude (North). Units: decimal degrees.
136 Neo4j moniker: C<wgs-84>.
137  
138 =item Neo4j SRID 4979
139  
140 Geographical ellipsoidal coordinates, referred to WGS84
141 (but spherically developed with C<distance()> 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<wgs-84-3d>.
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<cartesian>.
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<cartesian-3d>.
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<not> 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<coordinates()> method when called in scalar
215 context has not yet been defined.
216  
217 There are currently no methods named C<x()>, C<y()>, or C<z()>.
218 This is to avoid confusion with Perl's C<y///> operator.
219  
220 =head1 SEE ALSO
221  
222 =over
223  
224 =item * L<Neo4j::Driver::Type::Point>
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 <ajnn@cpan.org>
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__
« lib/Neo4j/Types/Path.pm ↑ Summary lib/Neo4j/Types/Relationship.pm »