-
-
Save universal/1a72a67bbc176173bbec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| task :postcode_import => :environment do | |
| puts "\n\n Importing PostCodes" | |
| lat_long_res = [] | |
| CSV.foreach "lib/data/example.csv" do |row| | |
| if row[0].include? " " | |
| postcode = row[0] | |
| else | |
| postcode = row[0][0..3] + " " + row[4..-1] | |
| end | |
| easting = row[1].to_i | |
| northing = row[2].to_i | |
| en_to_ll = Silva::Location.from(:en, :easting => easting, :northing => northing).to(:wgs84) | |
| lat_long_res << en_to_ll | |
| end | |
| lat_long_res.flatten | |
| lat_long_res.each { |lat, long| Postcode.first_or_create(lat: lat, long: long)} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CB114ZX | 553692 | 238424 | |
|---|---|---|---|
| CB2 0AA | 546031 | 254843 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment