Skip to content

Instantly share code, notes, and snippets.

@cgrusden
Created May 14, 2012 23:18
Show Gist options
  • Save cgrusden/2698035 to your computer and use it in GitHub Desktop.
Save cgrusden/2698035 to your computer and use it in GitHub Desktop.
Latitude & Longitude average string lengths
require 'fastercsv'
desc "Parse city data"
task "cities" do
headers = [:country_code, :ascii_name, :name, :state, :population, :lat, :long]
long_num, lat_num = [], []
FasterCSV.foreach(File.join(File.dirname(__FILE__), "../../", "doc/us_cities.txt"), :headers => headers) do |row|
begin
lat_num << row[:lat].length
long_num << row[:long].length
rescue Exception => e
puts e.message
end
end
puts "Lat: #{lat_num.sort.uniq.inspect}"
puts "Long: #{long_num.sort.uniq.inspect}"
end
Output:
$ rake cities
Lat: [9, 10, 11]
Long: [11, 12]
So, US Cities Latitude numbers are in the 9-11 character length range and Longitude can be 11-12 characters long
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment