Skip to content

Instantly share code, notes, and snippets.

@Fedcomp
Created January 12, 2019 14:07
Show Gist options
  • Save Fedcomp/daa678303a850424705934eb0478da39 to your computer and use it in GitHub Desktop.
Save Fedcomp/daa678303a850424705934eb0478da39 to your computer and use it in GitHub Desktop.
# Geo/RGeo tools
class GeoService
# @!method line(start_point, end_point) Create LineString from start to end points
# @param start_point [RGeo::Geographic::SphericalPointImpl]
# @param end_point [RGeo::Geographic::SphericalPointImpl]
# @return [RGeo::Cartesian::LineStringImpl]
# @!method line_string(points) Create LineString from array of coordinates
# @param points [Array<RGeo::Geographic::SphericalPointImpl>]
# @return [RGeo::Geographic::SphericalLineStringImpl]
delegate :line, :line_string, to: :spherical_factory
# Create Point from lon, lat coordinates
# @param lon [Float]
# @param lat [Float]
# @return [RGeo::Geographic::SphericalPointImpl]
# rubocop: disable Rails/Delegate
def point(lon:, lat:)
spherical_factory.point(lon, lat)
end
# rubocop: enable Rails/Delegate
private
def spherical_factory
@spherical_factory ||= geographic_adapter.spherical_factory(srid: 4326)
end
def geographic_adapter
RGeo::Geographic
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment