25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/models/document/bbox_validator.rb', line 25
def proper_bounding_box(record, valid_geom)
min_max = [-180.0, -90.0, 180.0, 90.0]
unless record.send(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box]).split(",").nil?
geom = record.send(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box]).split(",")
if geom.empty?
valid_geom = true
elsif geom.size != 4
valid_geom = false
record.errors.add(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box], "invalid W,S,E,N syntax")
elsif geom[0].to_f < min_max[0]
valid_geom = false
record.errors.add(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box], "invalid minX present")
elsif geom[1].to_f < min_max[1]
valid_geom = false
record.errors.add(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box], "invalid minY present")
elsif geom[2].to_f > min_max[2]
valid_geom = false
record.errors.add(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box], "invalid maX present")
elsif geom[3].to_f > min_max[3]
valid_geom = false
record.errors.add(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box], "invalid maxY present")
elsif geom[1].to_f >= geom[3].to_f
valid_geom = false
record.errors.add(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box], "maxY must be >= minY")
end
geom.each do |val|
next unless val.count(".") >= 2
valid_geom = false
record.errors.add(GeoblacklightAdmin::Schema.instance.solr_fields[:bounding_box],
"invalid ENVELOPE(W,E,N,S) syntax - found multiple periods in a coordinate value.")
end
end
valid_geom
end
|