Module: ADIWG::Mdtranslator::Writers::SbJson::Spatial

Defined in:
lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_spatial.rb

Class Method Summary collapse

Class Method Details

.build(aExtents) ⇒ Object



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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_spatial.rb', line 13

def self.build(aExtents)

   aBoxObjects = []

   aExtents.each do |hExtent|
      hExtent[:geographicExtents].each do |hGeoExtent|
         # use computedBbox if exists
         # ... this is always exists if geographic extent has objects
         # otherwise use user provided boundingBox
         hBbox = {}
         if hGeoExtent[:computedBbox].empty?
            unless hGeoExtent[:boundingBox].empty?
               hBbox = hGeoExtent[:boundingBox]
            end
         else
            hBbox = hGeoExtent[:computedBbox]
         end

         # turn the box into a polygon
         unless hBbox.empty?
            sw = [ hBbox[:westLongitude], hBbox[:southLatitude] ]
            nw = [ hBbox[:westLongitude], hBbox[:northLatitude] ]
            ne = [ hBbox[:eastLongitude], hBbox[:northLatitude] ]
            se = [ hBbox[:eastLongitude], hBbox[:southLatitude] ]
            aPoly = [ sw, nw, ne, se ]
            geoJson = {
               type: 'Polygon',
               coordinates: [
                  aPoly
               ]
            }
            aBoxObjects << geoJson
         end

      end
   end

   spatial = {}

   unless aBoxObjects.empty?
      hBox = AdiwgCoordinates.computeBbox(aBoxObjects)
      sbBox = {}

      # transform to sbJson bbox format
      sbBox[:maxY] = hBox[:northLatitude]
      sbBox[:minY] = hBox[:southLatitude]
      sbBox[:maxX] = hBox[:eastLongitude]
      sbBox[:minX] = hBox[:westLongitude]
      spatial[:boundingBox] = sbBox
   end

   # sbJson representational point is not provided

   spatial

end