Class: Neo4j::Driver::Types::Point

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#sridObject (readonly)

Returns the value of attribute srid.



8
9
10
# File 'lib/neo4j/driver/types/point.rb', line 8

def srid
  @srid
end

#xObject (readonly)

Returns the value of attribute x.



8
9
10
# File 'lib/neo4j/driver/types/point.rb', line 8

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



8
9
10
# File 'lib/neo4j/driver/types/point.rb', line 8

def y
  @y
end

#zObject (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

#coordinatesObject



37
38
39
# File 'lib/neo4j/driver/types/point.rb', line 37

def coordinates
  [x, y, z].compact.map(&:to_f)
end

#dimensionObject



33
34
35
# File 'lib/neo4j/driver/types/point.rb', line 33

def dimension
  @z.nil? ? 2 : 3
end

#to_sObject



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