Geonames Local
Download and store (pg, mongo, tokyo) Geonames.org data. Making every Geoname API operation possible on your servers. No hit limit, fast as possible.
Usage
To use one adapter, install the corresponding gem:
PostgreSQL => pg
MongoDB => mongo (optional: mongo_ext)
Tokyo => tokyocabinet
You will also need in your system:
-
unzip
-
curl
PostgreSQL
Be sure to use a database based on the PostGIS template.
MongoDB
MongoDB 2D support is new, only mongo >= 1.3.3 mongodb gem >= 0.19.2 github.com/mongodb/mongo-ruby-driver
Config YML
geonames conf
Will generate a “geonames.yml” file on your folder. The file is self explanatory.
geonames -c geonames.yml
To run it. Use -v for verbose.
If you are not sure your country code, use:
geonames list <search>
Relational Mapping
When using PG, this gem will (try) to relational map Geonames data on your scheme.
ActiveRecord
Check out lib/geonames/models/ar.rb
I`m wondering the best way (and if it`s a good idea) to auto include’em on rails. For now, just copy as you see fit.
PostgreSQL
So, supposing ActiveRecord, something like this is possible:
City.first.province.country.abbr
=> "BR"
Migration
Default PG migration:
create_table :cities do |t|
t.references :country, :null => false
t.references :province
t.string :name, :null => false
t.point :geom, :srid => 4326
t.integer :gid, :zip
end
create_table :provinces do |t|
t.references :country, :null => false
t.string :name, :null => false
t.string :abbr, :limit => 2, :null => false
t.integer :gid
end
create_table :countries do |t|
t.string :name, :limit => 30, :null => false
t.string :abbr, :limit => 2, :null => false
end
add_index :cities, :name
add_index :cities, :zip
add_index :cities, :country_id
add_index :cities, :province_id
add_index :cities, :gid, :unique => true
add_index :cities, :geom, :spatial => true
add_index :provinces, :name
add_index :provinces, :abbr
add_index :provinces, :country_id
add_index :provinces, :gid, :unique => true
add_index :countries, :abbr, :unique => true
add_index :countries, :name, :unique => true
TODO/Problems
-
Local relational mapping of geonames data
-
Map geonames fields to your db scheme
-
Countries are a static yml file :/
-
IP Geonames? ipinfodb.com
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright
Copyright © 2009 Marcos Piccinini. See LICENSE for details.