@@ -252,15 +252,18 @@ def source_attribute_groups
252252 @source_attribute_groups
253253 end
254254
255+ ##
256+ # Finds the locations of all source samples associated to this genome, and
257+ # returns them as an Array of 2-element Arrays ([lat, lon]) or +nil+
255258 def source_sample_locations
256259 coord = /([-+] *)?(\d +(?:[\. \, ]\d +)?|\d +°(?:\d +['"])*)( *[NSEW])?/
257260 keys = {
258261 lat : %i[ lat geographic_location_latitude latitude_start latitude_end ] ,
259262 lon : %i[ lon geographic_location_longitude longitude_start longitude_end ]
260263 }
261264
265+ coords = { lat : nil , lon : nil }
262266 @_source_sample_locations ||=
263- coords = { lat : nil , lon : nil }
264267 source_cannonical_samples . map do |sample |
265268 # Try joint keys
266269 if sample [ :lat_lon ]
@@ -306,6 +309,29 @@ def source_sample_locations
306309 end
307310 end
308311
312+ ##
313+ # Finds the rectangular bounds of all sample locations, with a minimum range
314+ # of latitudes of +minlat+ and longitudes of +minlon+, and returns it as an
315+ # array in the [south, west, north, east] order
316+ def source_sample_area ( minlat = 0.1 , minlon = 0.1 )
317+ loc = source_sample_locations . compact
318+ return unless loc . present?
319+
320+ min = { lat : minlat , lon : minlon }
321+ rng = { lat : loc . map { |i | i [ 0 ] } . minmax , lon : loc . map { |i | i [ 1 ] } . minmax }
322+
323+ rng . each do |k , v |
324+ width = v . inject ( :- ) . abs
325+ if width < min [ k ]
326+ pad = ( min [ k ] - width ) / 2
327+ rng [ k ] [ 0 ] -= pad
328+ rng [ k ] [ 1 ] += pad
329+ end
330+ end
331+
332+ [ rng [ :lat ] [ 0 ] , rng [ :lon ] [ 0 ] , rng [ :lat ] [ 1 ] , rng [ :lon ] [ 1 ] ]
333+ end
334+
309335 ##
310336 # TODO
311337 # Use source_cannonical_samples instead!
0 commit comments