Skip to content

Commit

Permalink
Georeference (#with_geographic_area) and small changes to test objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
TuckerJD committed Apr 22, 2014
1 parent 1dca60f commit 4617e6c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 37 deletions.
6 changes: 3 additions & 3 deletions app/models/georeference.rb
Expand Up @@ -277,19 +277,19 @@ def proper_data_is_provided
retval = false
end
unless chk_error_radius_inside_area
problem = 'collecting_event area must contain error_radius bounding box.'
problem = 'collecting_event area must contain georeference error_radius bounding box.'
errors.add(:error_radius, problem)
errors.add(:collecting_event, problem)
retval = false
end
unless chk_error_geo_item_inside_area
problem = 'collecting_event area must contain error_geographic_item.'
problem = 'collecting_event area must contain georeference error_geographic_item.'
errors.add(:error_geographic_item, problem)
errors.add(:collecting_event, problem)
retval = false
end
unless chk_obj_inside_area
problem = 'collecting_event area must contain geographic_item.'
problem = 'collecting_event area must contain georeference geographic_item.'
errors.add(:geographic_item, problem)
errors.add(:collecting_event, problem)
retval = false
Expand Down
32 changes: 31 additions & 1 deletion spec/models/geographic_item_spec.rb
Expand Up @@ -535,10 +535,40 @@
[-21.0, -11.0],
[-27.0, -13.0],
[-33.0, -11.0]
],
[
[-1.0, 1.0],
[1.0, 1.0],
[1.0, -1.0],
[-1.0, -1.0],
[-1.0, 1.0]
],
[
[-2.0, 2.0],
[2.0, 2.0],
[2.0, -2.0],
[-2.0, -2.0],
[-2.0, 2.0]
],
[
[-3.0, 3.0],
[3.0, 3.0],
[3.0, -3.0],
[-3.0, -3.0],
[-3.0, 3.0]
],
[
[-4.0, 4.0],
[4.0, 4.0],
[4.0, -4.0],
[-4.0, -4.0],
[-4.0, 4.0]
]
]

expect(@all_items.rendering_hash).to eq ({lines: [[[-32.0, 21.0], [-25.0, 21.0], [-25.0, 16.0], [-21.0, 20.0]], [[23.0, 21.0], [16.0, 21.0], [16.0, 16.0], [11.0, 20.0]], [[4.0, 12.6], [16.0, 12.6], [16.0, 7.6]], [[21.0, 12.6], [26.0, 12.6], [22.0, 17.6]], [[-33.0, 11.0], [-24.0, 4.0], [-26.0, 13.0], [-31.0, 4.0], [-33.0, 11.0]], [[-20.0, -1.0], [-26.0, -6.0]], [[-21.0, -4.0], [-31.0, -4.0]], [[27.0, -14.0], [18.0, -21.0], [20.0, -12.0], [25.0, -23.0]], [[27.0, -14.0], [18.0, -21.0], [20.0, -12.0], [25.0, -23.0]], [[-16.0, -15.5], [-22.0, -20.5]]], points: [[3.0, -14.0], [6.0, -12.9], [5.0, -16.0], [4.0, -17.9], [7.0, -17.9], [3.0, -14.0], [6.0, -12.9], [5.0, -16.0], [4.0, -17.9], [7.0, -17.9], [-88.241421, 40.091565], [-88.241417, 40.09161], [-88.241413, 40.091655], [0.0, 0.0], [-29.0, -16.0], [-25.0, -18.0], [-28.0, -21.0], [-19.0, -18.0], [3.0, -14.0], [6.0, -12.9], [5.0, -16.0], [4.0, -17.9], [7.0, -17.9], [32.2, 22.0], [-17.0, 7.0], [-9.8, 5.0], [-10.7, 0.0], [-30.0, 21.0], [-25.0, 18.3], [-23.0, 18.0], [-19.6, -13.0], [-7.6, 14.2], [-4.6, 11.9], [-8.0, -4.0], [-4.0, -3.0], [-10.0, -6.0]], polygons: [[[-14.0, 23.0], [-14.0, 11.0], [-2.0, 11.0], [-2.0, 23.0], [-8.0, 21.0], [-14.0, 23.0]], [[-19.0, 9.0], [-9.0, 9.0], [-9.0, 2.0], [-19.0, 2.0], [-19.0, 9.0]], [[5.0, -1.0], [-14.0, -1.0], [-14.0, 6.0], [5.0, 6.0], [5.0, -1.0]], [[-11.0, -1.0], [-11.0, -5.0], [-7.0, -5.0], [-7.0, -1.0], [-11.0, -1.0]], [[-3.0, -9.0], [-3.0, -1.0], [-7.0, -1.0], [-7.0, -9.0], [-3.0, -9.0]], [[-7.0, -9.0], [-7.0, -5.0], [-11.0, -5.0], [-11.0, -9.0], [-7.0, -9.0]], [[28.0, 2.3], [23.0, -1.7], [26.0, -4.8], [28.0, 2.3]], [[22.0, -6.8], [22.0, -9.8], [16.0, -6.8], [22.0, -6.8]], [[16.0, 2.3], [14.0, -2.8], [18.0, -2.8], [16.0, 2.3]], [[28.0, 2.3], [23.0, -1.7], [26.0, -4.8], [28.0, 2.3]], [[22.0, -6.8], [22.0, -9.8], [16.0, -6.8], [22.0, -6.8]], [[16.0, 2.3], [14.0, -2.8], [18.0, -2.8], [16.0, 2.3]], [[-33.0, -11.0], [-33.0, -23.0], [-21.0, -23.0], [-21.0, -11.0], [-27.0, -13.0], [-33.0, -11.0]]]})


expect(@all_items.rendering_hash).to eq ({:points=>[[3.0, -14.0], [6.0, -12.9], [5.0, -16.0], [4.0, -17.9], [7.0, -17.9], [3.0, -14.0], [6.0, -12.9], [5.0, -16.0], [4.0, -17.9], [7.0, -17.9], [-88.241421, 40.091565], [-88.241417, 40.09161], [-88.241413, 40.091655], [0.0, 0.0], [-29.0, -16.0], [-25.0, -18.0], [-28.0, -21.0], [-19.0, -18.0], [3.0, -14.0], [6.0, -12.9], [5.0, -16.0], [4.0, -17.9], [7.0, -17.9], [32.2, 22.0], [-17.0, 7.0], [-9.8, 5.0], [-10.7, 0.0], [-30.0, 21.0], [-25.0, 18.3], [-23.0, 18.0], [-19.6, -13.0], [-7.6, 14.2], [-4.6, 11.9], [-8.0, -4.0], [-4.0, -3.0], [-10.0, -6.0]], :lines=>[[[-32.0, 21.0], [-25.0, 21.0], [-25.0, 16.0], [-21.0, 20.0]], [[23.0, 21.0], [16.0, 21.0], [16.0, 16.0], [11.0, 20.0]], [[4.0, 12.6], [16.0, 12.6], [16.0, 7.6]], [[21.0, 12.6], [26.0, 12.6], [22.0, 17.6]], [[-33.0, 11.0], [-24.0, 4.0], [-26.0, 13.0], [-31.0, 4.0], [-33.0, 11.0]], [[-20.0, -1.0], [-26.0, -6.0]], [[-21.0, -4.0], [-31.0, -4.0]], [[27.0, -14.0], [18.0, -21.0], [20.0, -12.0], [25.0, -23.0]], [[27.0, -14.0], [18.0, -21.0], [20.0, -12.0], [25.0, -23.0]], [[-16.0, -15.5], [-22.0, -20.5]]], :polygons=>[[[-14.0, 23.0], [-14.0, 11.0], [-2.0, 11.0], [-2.0, 23.0], [-8.0, 21.0], [-14.0, 23.0]], [[-19.0, 9.0], [-9.0, 9.0], [-9.0, 2.0], [-19.0, 2.0], [-19.0, 9.0]], [[5.0, -1.0], [-14.0, -1.0], [-14.0, 6.0], [5.0, 6.0], [5.0, -1.0]], [[-11.0, -1.0], [-11.0, -5.0], [-7.0, -5.0], [-7.0, -1.0], [-11.0, -1.0]], [[-3.0, -9.0], [-3.0, -1.0], [-7.0, -1.0], [-7.0, -9.0], [-3.0, -9.0]], [[-7.0, -9.0], [-7.0, -5.0], [-11.0, -5.0], [-11.0, -9.0], [-7.0, -9.0]], [[28.0, 2.3], [23.0, -1.7], [26.0, -4.8], [28.0, 2.3]], [[22.0, -6.8], [22.0, -9.8], [16.0, -6.8], [22.0, -6.8]], [[16.0, 2.3], [14.0, -2.8], [18.0, -2.8], [16.0, 2.3]], [[28.0, 2.3], [23.0, -1.7], [26.0, -4.8], [28.0, 2.3]], [[22.0, -6.8], [22.0, -9.8], [16.0, -6.8], [22.0, -6.8]], [[16.0, 2.3], [14.0, -2.8], [18.0, -2.8], [16.0, 2.3]], [[-33.0, -11.0], [-33.0, -23.0], [-21.0, -23.0], [-21.0, -11.0], [-27.0, -13.0], [-33.0, -11.0]], [[-1.0, 1.0], [1.0, 1.0], [1.0, -1.0], [-1.0, -1.0], [-1.0, 1.0]], [[-2.0, 2.0], [2.0, 2.0], [2.0, -2.0], [-2.0, -2.0], [-2.0, 2.0]], [[-3.0, 3.0], [3.0, 3.0], [3.0, -3.0], [-3.0, -3.0], [-3.0, 3.0]], [[-4.0, 4.0], [4.0, 4.0], [4.0, -4.0], [-4.0, -4.0], [-4.0, 4.0]]]})
end
end
end
Expand Down
19 changes: 14 additions & 5 deletions spec/models/georeference_spec.rb
Expand Up @@ -360,14 +360,23 @@
level0: p_a,
ne_geo_item: @area_d)

@g_a4.save! # make sure the id is set

# Create an orphan collecting_event which uses g_a4, so that first phase of 'with_geographic_area' will
# have two records to fins
o_c_e = FactoryGirl.create(:valid_collecting_event, geographic_area: @g_a4)
expect(o_c_e.valid?).to be_true

# there are no georeferences which have collecting_events which have geographic_areas which refer to @g_a1
pending 'construction of appropriate Georeference objects'
expect(Georeference.with_geographic_area(@g_a1).to_a).to eq([])
expect(Georeference.with_geographic_area(@g_a4).to_a).to eq([])

@gr1.collecting_event.georgaphic_area = @g_a1
@gr1.save
@gr1.collecting_event.geographic_area = @g_a4
@gr1.geographic_item = @area_a
@gr1.collecting_event.save!
@gr1.save!

expect(Georeference.with_geographic_area(@g_a1).to_a).to eq([@gr1.becomes(Georeference::VerbatimData)])
expect(Georeference.with_geographic_area(@g_a4).to_a).to eq([@gr1.becomes(Georeference::VerbatimData)])
# pending 'construction of appropriate Georeference objects'


end
Expand Down
65 changes: 37 additions & 28 deletions spec/support/geo.rb
Expand Up @@ -198,6 +198,31 @@
SHAPE_L = RSPEC_GEO_FACTORY.line(RSPEC_GEO_FACTORY.point(-16, -15.5),
RSPEC_GEO_FACTORY.point(-22, -20.5))

LIST_T1 = RSPEC_GEO_FACTORY.line_string([RSPEC_GEO_FACTORY.point(-1, 1),
RSPEC_GEO_FACTORY.point(1, 1),
RSPEC_GEO_FACTORY.point(1, -1),
RSPEC_GEO_FACTORY.point(-1, -1)])

LIST_T2 = RSPEC_GEO_FACTORY.line_string([RSPEC_GEO_FACTORY.point(-2, 2),
RSPEC_GEO_FACTORY.point(2, 2),
RSPEC_GEO_FACTORY.point(2, -2),
RSPEC_GEO_FACTORY.point(-2, -2)])

LIST_T3 = RSPEC_GEO_FACTORY.line_string([RSPEC_GEO_FACTORY.point(-3, 3),
RSPEC_GEO_FACTORY.point(3, 3),
RSPEC_GEO_FACTORY.point(3, -3),
RSPEC_GEO_FACTORY.point(-3, -3)])

LIST_T4 = RSPEC_GEO_FACTORY.line_string([RSPEC_GEO_FACTORY.point(-4, 4),
RSPEC_GEO_FACTORY.point(4, 4),
RSPEC_GEO_FACTORY.point(4, -4),
RSPEC_GEO_FACTORY.point(-4, -4)])

BOX_1 = RSPEC_GEO_FACTORY.polygon(LIST_T1)
BOX_2 = RSPEC_GEO_FACTORY.polygon(LIST_T2)
BOX_3 = RSPEC_GEO_FACTORY.polygon(LIST_T3)
BOX_4 = RSPEC_GEO_FACTORY.polygon(LIST_T4)

ALL_SHAPES = RSPEC_GEO_FACTORY.collection([SHAPE_A,
SHAPE_B,
SHAPE_C,
Expand Down Expand Up @@ -233,7 +258,11 @@
POINT19,
POINT20,
POINT21,
POINT22])
POINT22,
BOX_1,
BOX_2,
BOX_3,
BOX_4])

CONVEX_HULL = ALL_SHAPES.convex_hull

Expand Down Expand Up @@ -284,7 +313,12 @@
[POINT19, 'P19'],
[POINT20, 'P20'],
[POINT21, 'P21'],
[POINT22, 'P22']]
[POINT22, 'P22'],
[BOX_1, 'Box_1'],
[BOX_2, 'Box_2'],
[BOX_3, 'Box_3'],
[BOX_4, 'Box_4']
]

E1_AND_E2 = RSPEC_GEO_FACTORY.parse_wkt('POLYGON ((-9.0 6.0 0.0, -9.0 2.0 0.0, -14.0 2.0 0.0, -14.0 6.0 0.0, -9.0 6.0 0.0))')
E1_OR_E2 = RSPEC_GEO_FACTORY.parse_wkt('POLYGON ((-19.0 9.0 0.0, -9.0 9.0 0.0, -9.0 6.0 0.0, 5.0 6.0 0.0, 5.0 -1.0 0.0, -14.0 -1.0 0.0, -14.0 2.0 0.0, -19.0 2.0 0.0, -19.0 9.0 0.0))')
Expand All @@ -293,31 +327,6 @@

P16_ON_A = RSPEC_GEO_FACTORY.parse_wkt("POINT (-23.0 18.0 0.0)")

LIST_T1 = RSPEC_GEO_FACTORY.line_string([RSPEC_GEO_FACTORY.point(-1, 1),
RSPEC_GEO_FACTORY.point(1, 1),
RSPEC_GEO_FACTORY.point(1, -1),
RSPEC_GEO_FACTORY.point(-1, -1)])

LIST_T2 = RSPEC_GEO_FACTORY.line_string([RSPEC_GEO_FACTORY.point(-2, 2),
RSPEC_GEO_FACTORY.point(2, 2),
RSPEC_GEO_FACTORY.point(2, -2),
RSPEC_GEO_FACTORY.point(-2, -2)])

LIST_T3 = RSPEC_GEO_FACTORY.line_string([RSPEC_GEO_FACTORY.point(-3, 3),
RSPEC_GEO_FACTORY.point(3, 3),
RSPEC_GEO_FACTORY.point(3, -3),
RSPEC_GEO_FACTORY.point(-3, -3)])

LIST_T4 = RSPEC_GEO_FACTORY.line_string([RSPEC_GEO_FACTORY.point(-4, 4),
RSPEC_GEO_FACTORY.point(4, 4),
RSPEC_GEO_FACTORY.point(4, -4),
RSPEC_GEO_FACTORY.point(-4, -4)])

BOX_1 = RSPEC_GEO_FACTORY.polygon(LIST_T1)
BOX_2 = RSPEC_GEO_FACTORY.polygon(LIST_T2)
BOX_3 = RSPEC_GEO_FACTORY.polygon(LIST_T3)
BOX_4 = RSPEC_GEO_FACTORY.polygon(LIST_T4)

def generate_test_objects


Expand Down Expand Up @@ -533,7 +542,7 @@ def generate_test_objects
area_d: @area_d.id
}

my_debug = true
my_debug = false

if my_debug
@debug_names.collect { |k, v| print "#{' ' * 4}" + v.to_s + ": " + k.to_s }
Expand Down

0 comments on commit 4617e6c

Please sign in to comment.