Module: GD::GIS::BBoxResolver

Defined in:
lib/gd/gis/bbox_resolver.rb

Overview

Resolves bounding box inputs into a normalized WGS84 bbox array.

Accepts:

  • Symbol or String referencing a named extent (e.g. :world, :argentina)

  • Array in the form [min_lng, min_lat, max_lng, max_lat]

Returns a 4-element array of Float values.

Examples:

Using a named extent

BBoxResolver.resolve(:europe)

Using a raw bbox

BBoxResolver.resolve([-10, 35, 5, 45])

Class Method Summary collapse

Class Method Details

.resolve(bbox) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gd/gis/bbox_resolver.rb', line 19

def self.resolve(bbox)
  case bbox
  when Symbol, String
    Extents.fetch(bbox)

  when Array
    validate!(bbox)
    bbox.map(&:to_f)

  else
    raise ArgumentError,
          "bbox must be Symbol, String or [min_lng, min_lat, max_lng, max_lat]"
  end
end

.validate!(bbox) ⇒ Object

Raises:

  • (ArgumentError)


34
35
36
37
38
39
# File 'lib/gd/gis/bbox_resolver.rb', line 34

def self.validate!(bbox)
  return if bbox.is_a?(Array) && bbox.size == 4

  raise ArgumentError,
        "bbox must be [min_lng, min_lat, max_lng, max_lat]"
end