Code Monkey home page Code Monkey logo

dm-geokit's Introduction

dm-geokit

A mixin for Datamapper models that enables geographic functionality.

  • Search for content via DataMapper-style query methods, e.g. Location.all(:address.near => {:origin => 'Portland, OR', :distance => 5.mi})
  • Sort by distance easily: Location.all(:address.near => {:origin => 'Portland, OR', :distance => 5.mi}, :order => [:address_distance.desc])
  • Ability to specify multiple fields that are geocodable (mostly)

Usage

Basic Class Definition:

class Location
  include DataMapper::Resource
  include DataMapper::GeoKit
  property :id, Serial
  has_geographic_location :address
end

This will automatically generate fields and methods for use with the DM Object, prefixed with the field name specified. Since the above example used the field :address, the following fields would be generated:

  • address_street_address
  • address_city
  • address_state
  • address_zip
  • address_country_code
  • address_full_address
  • address_lat
  • address_lng

You can either reference those fields directly, or use the proxy object returned by calling .address on your object:

l = Location.all(:address.near => {:origin => 'Portland, OR', :distance => 5.mi})

l.each do |loc|
  puts loc.address # .to_s yields string representation of full address, e.g. "12345 My St. Portland, OR USA"
  puts loc.address.inspect # the proxy object, GeographicLocation, with matching methods for each property
  puts loc.address.street_address # getting the street_address from the proxy object
  puts loc.address_street_address # directly access the SQL column
end

The GeographicLocation proxy object is a convenience to allow you to compare and sort results in Ruby.

Requirements

  • geokit >= 1.5.0
  • dm-core >= 1.0.2
  • dm-aggregates >= 1.0.2

dm-geokit's People

Contributors

dlo avatar flyingmachine avatar foysavas avatar itsmattking avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

solon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.