Giter VIP home page Giter VIP logo

geonames_dump's Introduction

GeonamesDump

GeonamesDump import geographic data from geonames project into your application, avoiding to use external service like google maps. It's a "gem" version of the application brownbeagle/geonames. Now you only need to include the dependency into your Gemfile and your project will include geonames.

You're free to use geocoder or geokit or any other geocoding solution.

Installation

Add this line to your application's Gemfile:

gem 'geonames_dump'

And then execute:

bundle install

Or install it yourself as:

gem install geonames_dump

Usage

Create models and migration files

rails generate geonames_dump:install

Import data (takes a loonnnng time!), it will download data, import countries and many features (Countries, Cities having more than 15000 people, Admin1 (first administrative subdivision), Admin2 (second level administrative subdivision))

rake geonames_dump:install

If you need more fine grained control over the installation process you can run individual geoname rake tasks instead of the all-in-one install :

$ rake -T | grep geonames_dump

rake geonames_dump:import:all               # Import ALL geonames data.
rake geonames_dump:import:many              # Import most of geonames data.

rake geonames_dump:import:admin1            # Import admin1 codes
rake geonames_dump:import:admin2            # Import admin2 codes
rake geonames_dump:import:cities            # Import all cities, regardless of population.
rake geonames_dump:import:cities1000        # Import cities with population greater than 1000
rake geonames_dump:import:cities15000       # Import cities with population greater than 15000
rake geonames_dump:import:cities5000        # Import cities with population greater than 5000
rake geonames_dump:import:countries         # Import countries informations
rake geonames_dump:import:features          # Import feature data.
rake geonames_dump:import:alternate_names   # Import alternate names

rake geonames_dump:truncate:all             # Truncate all geonames data.
rake geonames_dump:truncate:countries       # Truncate countries informations
rake geonames_dump:truncate:admin1          # Truncate admin1 codes
rake geonames_dump:truncate:admin2          # Truncate admin2 codes
rake geonames_dump:truncate:cities          # Truncate cities informations
rake geonames_dump:truncate:features        # Truncate features informations
rake geonames_dump:truncate:alternate_names # Import alternate names

Geonames data usage

The above commands will import geonames data in your Rails application, in other words, this will create models and fill database with place/city/country informations.

A convenient way to search for data is to use GeonamesDump search accessor GeonamesDump.search. This method interate on data types to find a result. Search order is the following :

  1. Cities
  2. Alternate names (names in non-latin alphabets)
  3. First level admin subdivisions
  4. Second level admin subdivisions
  5. Features (lakes, mountains and others various features)

Now to find a city for example :

GeonamesDump.search('paris')
GeonamesDump.search('東京') # tokyo :-)

If your request is ambiguous, like not searching Dublin in Ireland but Dublin in the USA, you may specify country :

GeonamesDump.search('dublin').first.country_code
=> 'IE'
GeonamesDump.search('dublin, us').first.country_code
=> 'US'

If needed, requested type may be specified too :

GeonamesDump.search('dublin', type: :city)
GeonamesDump.search('dublin, us', type: :city)
GeonamesDump.search('paris', type: :feature)

As GeonamesDump.search is returning Feature objects by default, type should specified to search for Countries :

GeonamesDump.search('Ireland', type: :country)

The following types are available :

  • :admin1, for first level of adminstrative subdivision
  • :admin2, for second level of adminstrative subdivision
  • :city, for city names
  • :feature, for generic names including all the above
  • :auto, to find any type of feature (even with non-latin characters) matching the query
  • :alternate_name, for names in non-latin alphabets (may be useless)
  • :country, for country names

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

geonames_dump's People

Contributors

kmmndr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

geonames_dump's Issues

`migration_template': wrong number of arguments (given 1, expected 2..3)

Hi, i have some problems with "rails generate geonames_dump:install"

`/home/user/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/generators/migration.rb:54:in 'migration_template': wrong number of arguments (given 1, exp 2..3) (ArgumentError)

    from /home/user/.rvm/gems/ruby-2.3.0/gems/geonames_dump-0.0.6/lib/generators/geonames_dump/install_generator.rb:20:in 'block in copy_migrations_f

    from /home/user/.rvm/gems/ruby-2.3.0/gems/geonames_dump-0.0.6/lib/generators/geonames_dump/install_generator.rb:13:in 'each'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/geonames_dump-0.0.6/lib/generators/geonames_dump/install_generator.rb:13:in 'copy_migrations_files'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/command.rb:27:in 'run'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in 'invoke_command'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in 'block in invoke_all'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in 'each'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in 'map'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in 'invoke_all'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/group.rb:232:in 'dispatch'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/base.rb:440:in 'start'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/generators.rb:157:in 'invoke'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/generate.rb:13:in '<top (required)>'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in 'require'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in 'block in require'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in 'load_dependency'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in 'require'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:123:in 'require_command!'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:130:in 'generate_or_destroy'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:50:in 'generate'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in 'run_command!'

    from /home/user/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in '<top (required)>'
    from bin/rails:9:in 'require'

    from bin/rails:9:in '<main>'`

So i can't do the rest part "rake geonames_dump:install"

rake aborted!
NameError: uninitialized constant GeonamesCountry
/home/user/.rvm/gems/ruby-2.3.0/gems/geonames_dump-0.0.6/lib/tasks/truncate.rake:29:in 'block (3 levels) in <top (required)>'
/home/user/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in 'eval'
/home/user/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in '

'
Tasks: TOP => geonames_dump:install => geonames_dump:truncate:all => geonames_dump:truncate:countries

rake aborted! cannot load such file -- zip/zip

I can't execute any take task.

Updating files in vendor/cache

  • activerecord-reset-pk-sequence-0.2.0.gem
  • ruby-progressbar-1.4.2.gem
  • geonames_dump-0.0.2.gem
    Your bundle is complete!
    It was installed into ./vendor/bundle

$ bin/rails generate geonames_dump:install
create db/migrate/20140311085358_create_geonames_countries.rb
create db/migrate/20140311085359_create_geonames_features.rb
create app/models/geonames_admin1.rb
create app/models/geonames_admin2.rb
create app/models/geonames_city.rb
create app/models/geonames_country.rb
create app/models/geonames_feature.rb

$ bundle exec rake geonames_dump:install
rake aborted!
cannot load such file -- zip/zip

$ bundle exec rake -T | grep geonames_dump

rake aborted!
cannot load such file -- zip/zip

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.