Module: ADIWG::Mdtranslator::Readers::MdJson::GeographicExtent

Defined in:
lib/adiwg/mdtranslator/readers/mdJson/modules/module_geographicExtent.rb

Class Method Summary collapse

Class Method Details

.unpack(hGeoExt, responseObj, inContext = nil) ⇒ Object



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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_geographicExtent.rb', line 21

def self.unpack(hGeoExt, responseObj, inContext = nil)

   @MessagePath = ADIWG::Mdtranslator::Readers::MdJson::MdJson

   # return nil object if input is empty
   if hGeoExt.empty?
      @MessagePath.issueWarning(320, responseObj, inContext)
      return nil
   end

   # instance classes needed in script
   intMetadataClass = .new
   intGeoExt = intMetadataClass.newGeographicExtent

   outContext = 'geographic extent'
   outContext = inContext + ' > ' + outContext unless inContext.nil?

   haveGExtent = false

   # geographic extent - description
   if hGeoExt.has_key?('description')
      if hGeoExt['description'] != ''
         intGeoExt[:description] = hGeoExt['description']
         haveGExtent = true
      end
   end

   # geographic extent - contains data
   if hGeoExt.has_key?('containsData')
      if hGeoExt['containsData'] === false
         intGeoExt[:containsData] = hGeoExt['containsData']
      end
   end

   # geographic extent - identifier
   if hGeoExt.has_key?('identifier')
      unless hGeoExt['identifier'].empty?
         hReturn = Identifier.unpack(hGeoExt['identifier'], responseObj, outContext)
         unless hReturn.nil?
            intGeoExt[:identifier] = hReturn
         end
         haveGExtent = true
      end
   end

   # geographic extent - bounding box
   if hGeoExt.has_key?('boundingBox')
      unless hGeoExt['boundingBox'].empty?
         hReturn = BoundingBox.unpack(hGeoExt['boundingBox'], responseObj, outContext)
         unless hReturn.nil?
            intGeoExt[:boundingBox] = hReturn
            haveGExtent = true
         end
      end
   end

   # geographic extent - geographic elements
   if hGeoExt.has_key?('geographicElement')
      hGeoExt['geographicElement'].each do |hElement|
         hReturn = GeoJson.unpack(hElement, responseObj, outContext)
         unless hReturn.nil?
            intGeoExt[:geographicElements] << hReturn
            haveGExtent = true
         end
      end
   end

   # save native GeoJson
   if hGeoExt.has_key?('geographicElement')
      unless hGeoExt['geographicElement'].empty?
         intGeoExt[:nativeGeoJson] = hGeoExt['geographicElement']
      end
   end

   # compute bbox for extent
   unless intGeoExt[:geographicElements].empty?
      intGeoExt[:computedBbox] = AdiwgCoordinates.computeBbox(intGeoExt[:geographicElements])
   end

   # error messages
   unless haveGExtent
      @MessagePath.issueError(321, responseObj, inContext)
   end

   return intGeoExt

end