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



79
80
81
82
83
84
85
86
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 79

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



16
17
18
19
20
21
22
23
24
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 16

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



26
27
28
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 26

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

#buffer(distance_) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 60

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



30
31
32
33
34
35
36
37
38
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 30

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)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 40

def equals?(rhs_)
  return false unless rhs_.is_a?(self.class) && rhs_.factory == 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