Code Monkey home page Code Monkey logo

geonames_local's Introduction

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 © 2009 Marcos Piccinini. See LICENSE for details.

geonames_local's People

Contributors

nofxx avatar boxmo avatar

Stargazers

 avatar

Watchers

 avatar

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.