3/30/2023 0 Comments Psequel database![]() The guts of the import is in the GeoName model class ("geoname.rb"), which I'll break in two: parse ( line ) rescue Exception => e puts "Exception during parsing: # " end endĪs you can see it's a pretty trivial little driver that just loads the data from a file provided to standard input or as an argument on the command line, tries to parse the line, and insert it into the database (g.save), with some minimal error handling. ![]() each do | line | g = nil begin g = GeoName. Require 'rubygems' require 'sequel' DB = Sequel ( "sqlite:///allCountries.db" ) require 'geoname' For Fedora/Redhat at least, Sqlite and the ruby bindings are included - if you don't have it installed do "yum install ruby-sqlite" or "up2date -i ruby-sqlite" if you're on RHEL.įirst "model.rb", a tiny helper file requiring rubygems and Sequel, and initializing the database: You can install sequel from a gem with "gem install sequel". To make this code work you need Rubygems, Sequel and Sqlite installed. In practice you may have to change the schema too. In theory it's just a matter of changing the "DB =" line. It should be trivial to make it work with MySQL or Postgres (or any of the other databases supported by Sequel) too. Here's an example Ruby script to use Sequel to load it into a Sqlite database. ![]() ![]() I've been playing with it a bit and wanted to load the dataset into a SQL database to make it easier to work with. It's great for putting place names on a map for example. names of populated places, locations and all kinds of other things that have a name and location. The version I have contains a whopping 6.7 million. GeoNames is a project to gather geographical information under the creative commons attribution license, which means it's ideal for commercial use and hobbyists alike. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |