module ADIWG::Mdtranslator::Readers::MdJson::GeometryCollection

Public Class Methods

unpack(hGeoCol, responseObj) click to toggle source
# 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