stanford-mods 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/stanford-mods/geo_spatial.rb +7 -7
- data/lib/stanford-mods/version.rb +1 -1
- data/spec/geo_spatial_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 821295322c2777baac42e0142a690a24b44cf931
|
4
|
+
data.tar.gz: 0134f68110a263ddedf3fb9fec7439bedbbad6dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9976025d220435fc45c4f97901bba4ef506b5e0f3c503b3fb377f3a6a10f4bb74239802abf66fb407c23a121b4339451511485ca94cd06fa620ddec8223fa92
|
7
|
+
data.tar.gz: 758b2840f7bb52959d4bf5ffceb0e9d281325ff5adcf848176535aa9b2a81f98386bfdfbcc03374c8b1622b99b3bb01184e38cb66ef460c95187a8272c9ff0cf
|
@@ -25,20 +25,20 @@ module Stanford
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def coord_to_bbox(coord)
|
28
|
-
matches = coord.match %r{\A(?<lat>[EW]
|
28
|
+
matches = coord.match %r{\A(?<lat>[EW].+-+.+)\s*/\s*(?<lng>[NS].+-+.+)\Z}
|
29
29
|
return unless matches
|
30
30
|
|
31
|
-
min_x, max_x = matches['lat'].split(
|
32
|
-
|
31
|
+
min_x, max_x = matches['lat'].split(/-+/).map { |x| coord_to_decimal(x) }.minmax
|
32
|
+
min_y, max_y = matches['lng'].split(/-+/).map { |y| coord_to_decimal(y) }.minmax
|
33
33
|
|
34
|
-
"#{min_x} #{min_y} #{max_x} #{max_y}" if valid_bbox?(min_x, max_x,
|
34
|
+
"#{min_x} #{min_y} #{max_x} #{max_y}" if valid_bbox?(min_x, max_x, min_y, max_y)
|
35
35
|
end
|
36
36
|
|
37
37
|
def coord_to_decimal(point)
|
38
|
-
regex = /(?<dir>[NESW])\s*(?<deg>\d+)
|
38
|
+
regex = /(?<dir>[NESW])\s*(?<deg>\d+)[°⁰º](?:(?<min>\d+)[ʹ'])?(?:(?<sec>\d+)[ʺ"])?/
|
39
39
|
match = regex.match(point)
|
40
40
|
|
41
|
-
return Float::
|
41
|
+
return Float::INFINITY unless match
|
42
42
|
|
43
43
|
dec = match['deg'].to_i
|
44
44
|
dec += match['min'].to_f / 60
|
@@ -48,7 +48,7 @@ module Stanford
|
|
48
48
|
dec
|
49
49
|
end
|
50
50
|
|
51
|
-
def valid_bbox?(min_x, max_x,
|
51
|
+
def valid_bbox?(min_x, max_x, min_y, max_y)
|
52
52
|
range_x = -180.0..180.0
|
53
53
|
range_y = -90.0..90.0
|
54
54
|
|
data/spec/geo_spatial_spec.rb
CHANGED
@@ -72,8 +72,16 @@ describe "Cartographic coordinates" do
|
|
72
72
|
['-123.38777777777779 38.29805555555556 -122.52277777777778 39.399166666666666'],
|
73
73
|
%(E 10°03'00"--E 12°58'00"/N 45°00'00"--N 41°46'00") =>
|
74
74
|
['10.05 41.766666666666666 12.966666666666667 45.0'],
|
75
|
+
%(E 8°41'-E 12°21'/N 46°04'-N 44°23') =>
|
76
|
+
['8.683333333333334 44.38333333333333 12.35 46.06666666666667'],
|
77
|
+
%((E17°--E11°/N14°--N18°).) =>
|
78
|
+
['11.0 14.0 17.0 18.0'], # coordinates need to be reordered
|
79
|
+
%((W 170⁰--E 55⁰/N 40⁰--S 36⁰).) =>
|
80
|
+
['-170.0 -36.0 55.0 40.0'], # superscript 0 is almost a degree character..
|
75
81
|
%(W80°--E100°/N487°--S42°) =>
|
76
82
|
[], # N487 is out of bounds for the bounding box
|
83
|
+
%((W 0°-W 0°/S 90°---S 90°)) =>
|
84
|
+
['-0.0 -90.0 -0.0 -90.0'], # one dash, two dashes, three dashes.. what's the difference?
|
77
85
|
%(W 650--W 100/N 700--N 550) =>
|
78
86
|
[] # missing degree character, and all coordinates are out of bounds.
|
79
87
|
}.each do |value, expected|
|