Created
September 11, 2012 17:33
-
-
Save jeregrine/3700090 to your computer and use it in GitHub Desktop.
Postgres Sequel: GIS and Full Text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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