diff --git a/.gitignore b/.gitignore index 87a458f..730b242 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.o *.so +pkg/ bin/shp2sqlite src/shp2sqlite/shp2sqlite src/liblwgeom/liblwgeom.a diff --git a/History.txt b/History.txt new file mode 100644 index 0000000..f285db3 --- /dev/null +++ b/History.txt @@ -0,0 +1,6 @@ +=== 1.0.0 / 2009-06-02 + +* 1 major enhancement + + * Birthday! + diff --git a/Manifest.txt b/Manifest.txt new file mode 100644 index 0000000..d4cc6ce --- /dev/null +++ b/Manifest.txt @@ -0,0 +1,18 @@ +History.txt +Manifest.txt +README.txt +Rakefile +lib/geocoder/us/database.rb +lib/geocoder/us/numbers.rb +lib/geocoder/us/address.rb +lib/geocoder/us/constants.rb +tests/database.rb +tests/numbers.rb +tests/generate.rb +tests/run.rb +tests/address.rb +tests/benchmark.rb +tests/constants.rb +tests/data/address-sample.csv +tests/data/locations.csv +tests/data/db-test.csv diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..9babf84 --- /dev/null +++ b/README.txt @@ -0,0 +1,48 @@ += geocoder_us + +* FIX (url) + +== DESCRIPTION: + +FIX (describe your package) + +== FEATURES/PROBLEMS: + +* FIX (list of features or problems) + +== SYNOPSIS: + + FIX (code sample of usage) + +== REQUIREMENTS: + +* FIX (list of requirements) + +== INSTALL: + +* FIX (sudo gem install, anything else) + +== LICENSE: + +(The MIT License) + +Copyright (c) 2009 FIX + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..4472b43 --- /dev/null +++ b/Rakefile @@ -0,0 +1,29 @@ +require 'rubygems' +Gem::manage_gems +require 'rake/gempackagetask' + +spec = Gem::Specification.new do |s| + s.platform = Gem::Platform::RUBY + s.name = 'Geocoder-US' + s.version = "1.0.0" + s.author = "Schuyler Erle" + s.email = 'geocoder@entropyfree.com' + s.description = "US address geocoding based on TIGER/Line." + s.summary = "US address geocoding based on TIGER/Line." + s.homepage = "http://geocoder.us/" + s.files = FileList[ + 'lib/geocoder/*.rb', 'lib/geocoder/us/*.rb', 'tests/*'].to_a + s.require_path = "lib" + s.test_files = "tests/run.rb" + s.has_rdoc = true + s.extra_rdoc_files = ["README"] +end + +Rake::GemPackageTask.new(spec) do |pkg| + pkg.need_tar = true +end + +task :default => "pkg/#{spec.name}-#{spec.version}.gem" do + puts "generated latest version" +end + diff --git a/demo/views/index.builder b/demo/views/index.builder index d7f94f3..2c2816d 100644 --- a/demo/views/index.builder +++ b/demo/views/index.builder @@ -3,7 +3,7 @@ xml.locations do @records.each do |record| xml.location do xml.score format("%.2f", record[:score]*100) - %w{lat lon prefix pretyp predir prequal street suftyp sufdir sufqual city state zip}.each do |field| + %w{lat lon number prefix pretyp predir prequal street suftyp sufdir sufqual city state zip}.each do |field| xml.tag! field, record[field.to_sym] end end diff --git a/demo/ws.rb b/demo/ws.rb index 2b2cf62..da8a443 100644 --- a/demo/ws.rb +++ b/demo/ws.rb @@ -2,12 +2,14 @@ require 'sinatra' require 'geocoder/us/database' require 'fastercsv' +require 'json' set :port, 8080 get '/' do unless params[:address].nil? - db = Geocoder::US::Database.new("/mnt/tiger2008/geocoder.db") + db = Geocoder::US::Database.new("/mnt/tiger2008/geocoder.db", + "/home/sderle/geocoder/lib/libsqlite3_geocoder.so") @records = db.geocode params[:address] end @@ -54,26 +56,34 @@ post '/batch' do + if params.include?(:uploaded_csv) FileUtils.mkdir_p('uploads/') FileUtils.mv(params[:uploaded_csv][:tempfile].path, "uploads/#{params[:uploaded_csv][:filename]}") - csv_file = "uploads/#{params[:uploaded_csv][:filename]}" - db = Geocoder::US::Database.new("/mnt/tiger2008/geocoder.db") + csv_file = open("uploads/#{params[:uploaded_csv][:filename]}") @filename = params[:uploaded_csv][:filename].gsub(/\.csv/,"") - csv = FasterCSV.parse(open(csv_file)) + csv = FasterCSV.parse(csv_file) + else + csv_file = request.env["rack.input"].read + csv = FasterCSV.parse(csv_file, :row_sep => "*", :col_sep => "|") + end + db = Geocoder::US::Database.new("/mnt/tiger2008/geocoder.db") headers = csv[0] @records = csv.collect do |record| next if record == headers begin - (db.geocode record[1]).first + puts record[1] + (db.geocode record[1]).first.merge(headers[0] => record[0]) rescue Exception => e puts e.message next end end.compact case params[:format] - when /atom/ + when /atom|xml/ builder :index + when /json/ + @records.to_json else erb :index end diff --git a/lib/geocoder/us.rb b/lib/geocoder/us.rb new file mode 100644 index 0000000..fa99a82 --- /dev/null +++ b/lib/geocoder/us.rb @@ -0,0 +1,4 @@ +require "geocoder/us/database" +require "geocoder/us/address" + +Geocoder::US::VERSION = "1.0.0"