Skip to content

Commit

Permalink
FactoryGirl minor changes for geographic_item, changes in geographic_…
Browse files Browse the repository at this point in the history
…item_spec for FactoryGirl, cleanup of load_geographic_area_shapes.
  • Loading branch information
TuckerJD committed Mar 3, 2014
1 parent 03b30db commit ca369c4
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 280 deletions.
34 changes: 17 additions & 17 deletions lib/tasks/initialization/geographic_areas.rake
Expand Up @@ -42,7 +42,7 @@ namespace :tw do
#row_data.delete('lft')
r = GeographicArea.new(row_data)
records[r.id] = r
print "Build: record #{r.id}\r"
print "\rBuild: record #{r.id}"
}

count = records.count
Expand All @@ -58,7 +58,7 @@ namespace :tw do
v.level2 = records[v.level2_id]
v.parent = records[v.parent_id]
v.geographic_area_type = GeographicAreaType.where(id: v.geographic_area_type_id).first
print "Update: record #{v.id} of #{count}.\r"
print "\rUpdate: record #{v.id} of #{count}."
end
puts

Expand All @@ -68,9 +68,9 @@ namespace :tw do
#time_then = snap

r.save!
print "Save: record #{r.id} of #{count}"
print "\rSave: record #{r.id} of #{count}"
#print ": #{Time.at(elapsed).getgm.strftime "%S:%L"}"
print ".\r"
print "."
end
=begin
puts
Expand Down Expand Up @@ -117,6 +117,8 @@ namespace :tw do
'tdwg_geo_item' => [],
'gadm_geo_item' => []}
check ={}
placer = nil
finder = {}

filenames.each { |filename|
shapes = RGeo::Shapefile::Reader.open(filename, factory: Georeference::FACTORY)
Expand All @@ -129,8 +131,6 @@ namespace :tw do
shapes.each do |record|

# there are different ways of locating the record for this shape, depending on where the data came from.
finder = {}
placer = nil
case filename
when /ne_10m_admin_0_countries\.shp/i
finder = {:neID => record['iso_n3']}
Expand Down Expand Up @@ -158,20 +158,20 @@ namespace :tw do
placer = nil
end

if check[finder]
puts "\nDanger"
puts
end
check[finder] = record.index
#if check[finder]
# puts "\nDanger"
# puts
#end
#check[finder] = record.index

if finder.nil?
else
ga = GeographicArea.where(finder)
if ga.count < 1
skipped[placer].push(finder.values.first)
$stderr.puts
$stderr.print "Skipped #{skipped[placer].count} : (#{record.index}) #{finder} from #{filename} (#{record['name']})."
$stderr.puts
#$stderr.puts
#$stderr.print "Skipped #{skipped[placer].count} : (#{record.index}) #{finder} from #{filename} (#{record['name']})."
#$stderr.puts

else

Expand All @@ -183,9 +183,9 @@ namespace :tw do

ga.each { |area|
multiples.push(finder => area.name)
$stderr.puts
$stderr.print "Multiple #{multiples.count}: #{finder} found #{area.name} from #{area.data_origin}."
$stderr.puts
#$stderr.puts
#$stderr.print "Multiple #{multiples.count}: #{finder} found #{area.name} from #{area.data_origin}."
#$stderr.puts
} if ga.count > 1

ga.each { |area|
Expand Down
13 changes: 6 additions & 7 deletions spec/factories/geographic_item_factory.rb
@@ -1,23 +1,22 @@

#@ffi_factory = ::RGeo::Geos.factory(native_interface: :ffi, srid: 4326, has_m_coordinate: false, has_z_coordinate: true)


FactoryGirl.define do

factory :geographic_item, traits: [:creator_and_updater] do

factory :geographic_item_with_point do
factory :valid_geographic_item, aliases: [:geographic_item_with_point] do

point {GEO_FACTORY.point(-88.241413, 40.091655)}
point { GEO_FACTORY.point(-88.241413, 40.091655) }

end

factory :geographic_item_with_line_string do

line_string {GEO_FACTORY.line_string([GEO_FACTORY.point(-32, 21),
GEO_FACTORY.point(-25, 21),
GEO_FACTORY.point(-25, 16),
GEO_FACTORY.point(-21, 20)])}
line_string { GEO_FACTORY.line_string([GEO_FACTORY.point(-32, 21),
GEO_FACTORY.point(-25, 21),
GEO_FACTORY.point(-25, 16),
GEO_FACTORY.point(-21, 20)]) }

end

Expand Down

0 comments on commit ca369c4

Please sign in to comment.