Module: Adiwg_BoundingBox

Defined in:
lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.9.0/module_boundingBox.rb

Overview

History: Stan Smith 2013-11-07 original script

Stan Smith 2014-04-28 reorganized for json schema 0.3.0

Class Method Summary collapse

Class Method Details

.unpack(aBBox) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
# File 'lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.9.0/module_boundingBox.rb', line 10

def self.unpack(aBBox)

  # instance classes needed in script
  intMetadataClass = .new
  intGeometry = intMetadataClass.newGeometry
  intGeometry[:geoType] = 'BoundingBox'

  # unpack GeoJSON bounding box elements
  intBBox = intMetadataClass.newBoundingBox
  west = aBBox[0]
  south = aBBox[1]
  east = aBBox[2]
  north = aBBox[3]

  # validate coordinates if easting +/-180 and northing +/-90
  valid = false
  if (180 >= west) && (west >= -180)
    if (90 >= south) && (south >= -90)
      if (180 >= east) && (east >= -180)
        if (90 >= north) &&(north >= -90)
          valid = true
        end
      end
    end
  end

  # build internal geo element if valid
  if valid
    intBBox[:westLong] = west
    intBBox[:eastLong] = east
    intBBox[:southLat] = south
    intBBox[:northLat] = north
    intGeometry[:geometry] = intBBox

    return intGeometry
  else
    return nil
  end

end