Class: Neo4j::Driver::Types::Point
- Inherits:
-
Object
- Object
- Neo4j::Driver::Types::Point
- Defined in:
- lib/neo4j/driver/types/point.rb
Overview
Point (2D or 3D)
Constant Summary collapse
- WGS_84_2D =
SRID constants for coordinate reference systems
4326- WGS_84_3D =
Geographic 2D (longitude, latitude)
4979- CARTESIAN_2D =
Geographic 3D (longitude, latitude, height)
7203- CARTESIAN_3D =
Cartesian 2D (x, y)
9157
Instance Attribute Summary collapse
-
#srid ⇒ Object
readonly
Returns the value of attribute srid.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
-
#z ⇒ Object
readonly
Returns the value of attribute z.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #coordinates ⇒ Object
- #dimension ⇒ Object
-
#initialize(srid: nil, x: nil, y: nil, z: nil, longitude: nil, latitude: nil, height: nil) ⇒ Point
constructor
Cartesian 3D (x, y, z).
- #to_s ⇒ Object
Constructor Details
#initialize(srid: nil, x: nil, y: nil, z: nil, longitude: nil, latitude: nil, height: nil) ⇒ Point
Cartesian 3D (x, y, z)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/neo4j/driver/types/point.rb', line 16 def initialize(srid: nil, x: nil, y: nil, z: nil, longitude: nil, latitude: nil, height: nil) # Handle longitude/latitude aliases for x/y if longitude || latitude @x = (longitude || x).to_f @y = (latitude || y).to_f @z = (height || z)&.to_f # Use WGS-84 SRID for geographic coordinates @srid = srid || (@z ? WGS_84_3D : WGS_84_2D) else @x = x.to_f @y = y.to_f @z = z&.to_f # Use Cartesian SRID for x/y/z coordinates @srid = srid || (@z ? CARTESIAN_3D : CARTESIAN_2D) end end |
Instance Attribute Details
#srid ⇒ Object (readonly)
Returns the value of attribute srid.
8 9 10 |
# File 'lib/neo4j/driver/types/point.rb', line 8 def srid @srid end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
8 9 10 |
# File 'lib/neo4j/driver/types/point.rb', line 8 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
8 9 10 |
# File 'lib/neo4j/driver/types/point.rb', line 8 def y @y end |
#z ⇒ Object (readonly)
Returns the value of attribute z.
8 9 10 |
# File 'lib/neo4j/driver/types/point.rb', line 8 def z @z end |
Instance Method Details
#==(other) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/neo4j/driver/types/point.rb', line 49 def ==(other) other.is_a?(Point) && other.srid == @srid && (other.x - @x).abs < 0.00001 && (other.y - @y).abs < 0.00001 && (@z.nil? || (other.z - @z).abs < 0.00001) end |
#coordinates ⇒ Object
37 38 39 |
# File 'lib/neo4j/driver/types/point.rb', line 37 def coordinates [x, y, z].compact.map(&:to_f) end |
#dimension ⇒ Object
33 34 35 |
# File 'lib/neo4j/driver/types/point.rb', line 33 def dimension @z.nil? ? 2 : 3 end |
#to_s ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/neo4j/driver/types/point.rb', line 41 def to_s if @z "Point{srid=#{@srid}, x=#{@x}, y=#{@y}, z=#{@z}}" else "Point{srid=#{@srid}, x=#{@x}, y=#{@y}}" end end |