Sha256: 7af18f7e933270bb186a2fcfcd105f9ee431a5e2ff53e0f8fce46e50a3caf142

Contents?: true

Size: 689 Bytes

Versions: 1

Compression:

Stored size: 689 Bytes

Contents

require 'geo_ruby'

module Mongoid
  module Geospatial
    # Wrapper to GeoRuby's Point
    class Point
      delegate :distance, to: :to_geo

      def to_geo
        return unless valid?
        GeoRuby::SimpleFeatures::Point.xy(x, y)
      end

      def geo_distance(other)
        to_geo.spherical_distance(other.to_geo)
      end
    end

    # Wrapper to GeoRuby's Line
    class Line < GeometryField
      def to_geo
        GeoRuby::SimpleFeatures::LineString.from_coordinates(self)
      end
    end

    # Wrapper to GeoRuby's Polygon
    class Polygon < GeometryField
      def to_geo
        GeoRuby::SimpleFeatures::Polygon.from_coordinates(self)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-geospatial-3.9.0 lib/mongoid/geospatial/wrappers/georuby.rb