Module: RGeo::Geographic::SphericalPointMethods

Included in:
SphericalPointImpl
Defined in:
lib/rgeo/geographic/spherical_feature_methods.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 88

def self.included(klass)
  klass.module_eval do
    alias_method :longitude, :x
    alias_method :lon, :x
    alias_method :latitude, :y
    alias_method :lat, :y
  end
end

Instance Method Details

#buffer(distance) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 69

def buffer(distance)
  radius = distance / SphericalMath::RADIUS
  radius = 1.5 if radius > 1.5
  cos = Math.cos(radius)
  sin = Math.sin(radius)
  point_count = factory.property(:buffer_resolution) * 4
  p0 = xyz
  p1 = p0.create_perpendicular
  p2 = p1 % p0
  angle = Math::PI * 2.0 / point_count
  points = (0...point_count).map do |i|
    r = angle * i
    pi = SphericalMath::PointXYZ.weighted_combination(p1, Math.cos(r), p2, Math.sin(r))
    p = SphericalMath::PointXYZ.weighted_combination(p0, cos, pi, sin)
    factory.point(*p.lonlat)
  end
  factory.polygon(factory.linear_ring(points))
end

#distance(rhs) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 38

def distance(rhs)
  rhs = Feature.cast(rhs, @factory)
  case rhs
  when SphericalPointImpl
    xyz.dist_to_point(rhs.xyz) * SphericalMath::RADIUS
  else
    super
  end
end

#equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 48

def equals?(rhs)
  return false unless rhs.is_a?(self.class) && rhs.factory == factory
  case rhs
  when Feature::Point
    case @y
    when 90
      rhs.y == 90
    when -90
      rhs.y == -90
    else
      rhs.x == @x && rhs.y == @y
    end
  when Feature::LineString
    rhs.num_points > 0 && rhs.points.all? { |elem| equals?(elem) }
  when Feature::GeometryCollection
    rhs.num_geometries > 0 && rhs.all? { |elem| equals?(elem) }
  else
    false
  end
end

#xyzObject



34
35
36
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 34

def xyz
  @xyz ||= SphericalMath::PointXYZ.from_latlon(@y, @x)
end