Module: ADIWG::Mdtranslator::Readers::MdJson::GeometryCollection

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

Class Method Summary collapse

Class Method Details

.unpack(hGeoCol, responseObj) ⇒ Object



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
69
70
71
72
73
74
75
76
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_geometryCollection.rb', line 19

def self.unpack(hGeoCol, responseObj)

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

   # return nil object if input is empty
   if hGeoCol.empty?
      @MessagePath.issueWarning(360, responseObj)
      return nil
   end

   # instance classes needed in script
   intMetadataClass = InternalMetadata.new
   intGeoCol = intMetadataClass.newGeometryCollection

   # geometry collection - type (required)
   if hGeoCol.has_key?('type')
      if hGeoCol['type'] != ''
         if hGeoCol['type'] == 'GeometryCollection'
            intGeoCol[:type] = hGeoCol['type']
         else
            @MessagePath.issueError(361, responseObj)
         end
      end
   end
   if intGeoCol[:type].nil? || intGeoCol[:type] == ''
      @MessagePath.issueError(362, responseObj)
   end

   # geometry collection - bounding box
   if hGeoCol.has_key?('bbox')
      unless hGeoCol['bbox'].empty?
         intGeoCol[:bbox] = hGeoCol['bbox']
      end
   end

   # geometry collection - geometries (required, but can be empty)
   if hGeoCol.has_key?('geometries')
      hGeoCol['geometries'].each do |hGeometry|
         hReturn = GeoJson.unpack(hGeometry, responseObj)
         unless hReturn.nil?
            intGeoCol[:geometryObjects] << hReturn
         end
      end
   else
      @MessagePath.issueError(363, responseObj)
   end

   # geometry collection - compute bbox for geometry collection
   unless intGeoCol[:geometryObjects].empty?
      intGeoCol[:computedBbox] = AdiwgCoordinates.computeBbox(intGeoCol[:geometryObjects])
   end

   # geometry collection - save GeoJSON for the collection
   intGeoCol[:nativeGeoJson] = hGeoCol

   return intGeoCol

end