Class: MI_Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_metadata.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ MI_Metadata

Returns a new instance of MI_Metadata.



39
40
41
# File 'lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_metadata.rb', line 39

def initialize(xml)
  @xml = xml
end

Instance Method Details

#writeXML(internalObj) ⇒ Object



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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_metadata.rb', line 43

def writeXML(internalObj)

  # # classes used in MD_Metadata
  charCode = MD_CharacterSetCode.new(@xml)
  scopeCode = MD_ScopeCode.new(@xml)
  rPartyClass = CI_ResponsibleParty.new(@xml)
  mdExtClass = MD_MetadataExtensionInformation.new(@xml)
  dataIdClass = MD_DataIdentification.new(@xml)
  distClass = MD_Distribution.new(@xml)
  dqClass = DQ_DataQuality.new(@xml)
  metaMaintClass = MD_MaintenanceInformation.new(@xml)
  refSysClass = MD_ReferenceSystem.new(@xml)

   = internalObj[:metadata]
  hMetaInfo = [:metadataInfo]
  hResInfo = [:resourceInfo]
  aAssocRes = [:associatedResources]
  $intContactList = internalObj[:contacts]

  # document head
  @xml.instruct! :xml, encoding: 'UTF-8'
  @xml.comment!('core gmi based instance document ISO 19115-2')
  @xml.tag!('gmi:MI_Metadata',{'xmlns:gmi' => 'http://www.isotc211.org/2005/gmi',
                'xmlns:gmd' => 'http://www.isotc211.org/2005/gmd',
                'xmlns:gco' => 'http://www.isotc211.org/2005/gco',
                'xmlns:gml' => 'http://www.opengis.net/gml/3.2',
                'xmlns:gsr' => 'http://www.isotc211.org/2005/gsr',
                'xmlns:gss' => 'http://www.isotc211.org/2005/gss',
                'xmlns:gst' => 'http://www.isotc211.org/2005/gst',
                'xmlns:gmx' => 'http://www.isotc211.org/2005/gmx',
                'xmlns:gfc' => 'http://www.isotc211.org/2005/gfc',
                'xmlns:srv' => 'http://www.isotc211.org/2005/srv',
                'xmlns:xlink' => 'http://www.w3.org/1999/xlink',
                'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
                'xsi:schemaLocation' => 'http://www.isotc211.org/2005/gmi ftp://ftp.ncddc.noaa.gov/pub/Metadata/Online_ISO_Training/Intro_to_ISO/schemas/ISObio/schema.xsd'}) do

    # metadata information - file identifier - default
    # the internal object stores the file identifier as a MD_Identifier to support 19115-1
    # hMetaInfo => metadata > metadataInfo
    # hMetaInfo[:metadataId] => MD_Identifier
    # ISO 19115-2 only support the file identifier as a character string
    @xml.tag!('gmd:fileIdentifier') do
      s = nil
      if hMetaInfo
        if hMetaInfo[:metadataId]
          s = hMetaInfo[:metadataId][:identifier]
          unless s.nil?
            @xml.tag!('gco:CharacterString',s)
          end
        end
      end
      if s.nil?
        # generate fileIdentifier if one not provided
        @xml.tag!('gco:CharacterString',UUIDTools::UUID.random_create.to_s)
      end
    end

    # metadata information - file language - default
    @xml.tag!('gmd:language') do
      # all xml is written in US English
      @xml.tag!('gco:CharacterString','eng; USA')
    end

    # metadata information - character set - default
    @xml.tag!('gmd:characterSet') do
      # all out put is in utf8
      charCode.writeXML('utf8')
    end

    # metadata information - parent identifier
    # the internal object stores the parent identifier as a CI_Citation to support 19115-1
    # hMetaInfo => metadata > metadataInfo
    # hMetaInfo[:parentMetadata] => hParent => CI_Citation
    # ISO 19115-2 only support the parent identifier as a character string
    s = nil
    if hMetaInfo
      if hMetaInfo[:parentMetadata]
        hParent = hMetaInfo[:parentMetadata]
        if !hParent.empty?
          s = hParent[:citTitle]
          aResIds = hParent[:citResourceIDs]
          if aResIds.length > 0
            s += ' ids: | '
            aResIds.each do |resource|
              s += resource[:identifierType] + ': ' + resource[:identifier] + ' | '
            end
          end
        end
      end
    end
    if !s.nil?
      @xml.tag!('gmd:parentIdentifier') do
        @xml.tag!('gco:CharacterString',s)
      end
    elsif $showAllTags
      @xml.tag!('gmd:parentIdentifier')
    end

    # metadata information - hierarchy level - defaults to 'dataset',
    # values taken from resourceInfo > resourceType
    fileHierarchy = false
      s = hResInfo[:resourceType]
      if s != ''
        fileHierarchy = true
        @xml.tag!('gmd:hierarchyLevel') do
          scopeCode.writeXML(s)
        end
      end
    if !fileHierarchy
      @xml.tag!('gmd:hierarchyLevel') do
        scopeCode.writeXML('dataset')
      end
    end

    # metadata information - metadata custodian - required
    custodians = false
    if hMetaInfo
        if hMetaInfo[:metadataCustodians]
        aCustodians = hMetaInfo[:metadataCustodians]
        unless aCustodians.empty?
          custodians = true
          aCustodians.each do |hCustodian|
            @xml.tag!('gmd:contact') do
              rPartyClass.writeXML(hCustodian)
            end
          end
        end
      end
    end
    if !custodians
      @xml.tag!('gmd:contact', {'gco:nilReason' => 'missing'})
    end

    # metadata information - date stamp - required - default to now()
    mDate = AdiwgDateTimeFun.stringDateFromDateTime(DateTime.now, 'YMD')
    if hMetaInfo
      if hMetaInfo[:metadataCreateDate]
        hDate = hMetaInfo[:metadataCreateDate]
        unless hDate.empty?
          mDateTime = hDate[:dateTime]
          mDateRes = hDate[:dateResolution]
          if mDateTime.nil?
            mDate = AdiwgDateTimeFun.stringDateFromDateTime(mDateTime, mDateRes)
          end
        end
      end
    end
    @xml.tag!('gmd:dateStamp') do
      @xml.tag!('gco:Date',mDate)
    end

    # metadata information - metadata standard name - default
    @xml.tag!('gmd:metadataStandardName') do
      @xml.tag!('gco:CharacterString','ISO 19115-2')
    end

    # metadata information - metadata standard version - default
    @xml.tag!('gmd:metadataStandardVersion') do
      @xml.tag!('gco:CharacterString','ISO 19115-2:2009(E)')
    end

    # metadata information - dataset URI
    # for the dataset URI adiwgJson follows the ISO 19115-1 convention which is
    # ... to include links to the resource in the onlineResource section of the
    # ... resource citation.  Because citation onlineResource(s) are not supported
    # ... in -2, the URI from the first onlineResource in the adiwgJson is used
    # ... for the datasetURI.
    # ... metadata: {resourceInfo: {citation: {citOlResources[0]: {olResURI:}}}}
    s = nil
    if hResInfo[:citation]
      if hResInfo[:citation][:citOlResources][0]
        if hResInfo[:citation][:citOlResources][0][:olResURI]
          s = hResInfo[:citation][:citOlResources][0][:olResURI]
        end
      end
    end
    if !s.nil?
      @xml.tag!('gmd:dataSetURI') do
        @xml.tag!('gco:CharacterString',s)
      end
    elsif $showAllTags
      @xml.tag!('gmd:dataSetURI')
    end

    # metadata information - reference system
    hRefSystems = hResInfo[:spatialReferenceSystem]
    if !hRefSystems.empty?

      # named reference systems
      aRefNames = hRefSystems[:sRNames]
      aRefNames.each do |refName|
        @xml.tag!('gmd:referenceSystemInfo') do
          refSysClass.writeXML(refName, 'name')
        end
      end

      # epsg reference systems
      aRefNames = hRefSystems[:sREPSGs]
      aRefNames.each do |refName|
        @xml.tag!('gmd:referenceSystemInfo') do
          refSysClass.writeXML(refName, 'epsg')
        end
      end

      # wkt reference systems
      aRefNames = hRefSystems[:sRWKTs]
      aRefNames.each do |refName|
        @xml.tag!('gmd:referenceSystemInfo') do
          refSysClass.writeXML(refName, 'wkt')
        end
      end

    elsif $showAllTags
      @xml.tag!('gmd:referenceSystemInfo')
    end

    # metadata information - metadata extension info
    extensions = false
    if hMetaInfo
      if hMetaInfo[:extensions]
        aExtensions = hMetaInfo[:extensions]
        if !aExtensions.empty?
          extensions = true
          aExtensions.each do |hExtension|
            @xml.tag!('gmd:metadataExtensionInfo') do
              mdExtClass.writeXML(hExtension)
            end
          end
        end
      end
    end
    if !extensions && $showAllTags
      @xml.tag!('gmd:metadataExtensionInfo')
    end

    # metadata information - identification info - required
    if hResInfo.empty?
      @xml.tag!('gmd:identificationInfo', {'gco:nilReason' => 'missing'})
    else
      @xml.tag!('gmd:identificationInfo') do
        dataIdClass.writeXML(hResInfo, aAssocRes)
      end
    end

    # metadata information - content info
    # ... information about data and link to 19110
    # ... on hold until 19115-1 release

    # metadata information - distribution info []
    aDistInfo = [:distributorInfo]
    if !aDistInfo.empty?
      @xml.tag!('gmd:distributionInfo') do
        distClass.writeXML(aDistInfo)
      end
    elsif $showAllTags
      @xml.tag!('gmd:distributionInfo')
    end

    # metadata information - data quality info
    aDQInfo = hResInfo[:dataQualityInfo]
    if !aDQInfo.empty?
      aDQInfo.each do |hDQInfo|
        @xml.tag!('gmd:dataQualityInfo') do
          dqClass.writeXML(hDQInfo)
        end
      end
    elsif $showAllTags
      @xml.tag!('gmd:dataQualityInfo')
    end

    # metadata information - metadata maintenance
    maintInfo = false
    if hMetaInfo
      if hMetaInfo[:maintInfo]
        hMetaMaint = hMetaInfo[:maintInfo]
        if !hMetaMaint.empty?
          maintInfo = true
          @xml.tag!('gmd:metadataMaintenance') do
            metaMaintClass.writeXML(hMetaMaint)
          end
        end
      end
    end
    if !maintInfo && $showAllTags
      @xml.tag!('gmd:metadataMaintenance')
    end

  end
end