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
71 72 73 74 75 76 77 78 |
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 71 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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 52 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
22 23 24 25 26 27 28 29 30 |
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 22 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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 32 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 |
#xyz ⇒ Object
18 19 20 |
# File 'lib/rgeo/geographic/spherical_feature_methods.rb', line 18 def xyz @xyz ||= SphericalMath::PointXYZ.from_latlon(@y, @x) end |