Skip to content

Instantly share code, notes, and snippets.

@jeregrine
Created September 11, 2012 17:33
Show Gist options
  • Select an option

  • Save jeregrine/3700090 to your computer and use it in GitHub Desktop.

Select an option

Save jeregrine/3700090 to your computer and use it in GitHub Desktop.
Postgres Sequel: GIS and Full Text
#Find Nearest points in a radius in miles
def_dataset_method(:nearest) do |lat, lng, radius|
radius = radius / 0.000621371
where("ST_DWithin(geo_location, 'POINT(#{lng} #{lat})', #{radius})")
end
#To set the geo location for an event
def updateGeography()
self.db.run("update events set geo_location = ST_GeographyFromText('POINT(#{self.lng} #{self.lat})') where id=#{self.id};")
end
Sequel.migration do
up do
run("create extension if not exists postgis;")
alter_table :events do
add_column :geo_location, :geography
add_full_text_index [:description, :name], :language=>'english'
add_index :geo_location, :type=>:gist
end
end
down do
alter_table :events do
drop_column :geo_location
drop_index :geo_location
drop_index [:description, :name]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment