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


124
125
126
127
128
129
130
131
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 124

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

#_validate_geometryObject


56
57
58
59
60
61
62
63
64
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 56

def _validate_geometry
  if @x < -180.0 || @x >= 180.0
    @x = @x % 360.0
    @x -= 360.0 if @x >= 180.0
  end
  @y = 90.0 if @y > 90.0
  @y = -90.0 if @y < -90.0
  super
end

#_xyzObject


67
68
69
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 67

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

#buffer(distance_) ⇒ Object


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 104

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


72
73
74
75
76
77
78
79
80
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 72

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)

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 83

def equals?(rhs_)
  return false unless rhs_.is_a?(self.class) && rhs_.factory == self.factory
  case rhs_
  when Feature::Point
    if @y == 90
      rhs_.y == 90
    elsif @y == -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