Class: ADIWG::Mdtranslator::Writers::Fgdc::SpatialDomain

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

Instance Method Summary collapse

Constructor Details

#initialize(xml, hResponseObj) ⇒ SpatialDomain

Returns a new instance of SpatialDomain.



18
19
20
21
22
# File 'lib/adiwg/mdtranslator/writers/fgdc/classes/class_spatialDomain.rb', line 18

def initialize(xml, hResponseObj)
   @xml = xml
   @hResponseObj = hResponseObj
   @NameSpace = ADIWG::Mdtranslator::Writers::Fgdc
end

Instance Method Details

#writeXML(aExtents) ⇒ Object



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
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
# File 'lib/adiwg/mdtranslator/writers/fgdc/classes/class_spatialDomain.rb', line 24

def writeXML(aExtents)

   # spatial domain section is not required under biological extension rules

   # look for geographic description - take first
   # <- geographicExtent[:description]
   geoDescription = ''
   aExtents.each do |hExtent|
      unless hExtent.empty?
         hExtent[:geographicExtents].each do |hGeoExtent|
            unless hGeoExtent.empty?
               unless hGeoExtent[:description].nil?
                  geoDescription = hGeoExtent[:description]
                  break
               end
            end
         end
      end
   end

   # look for bounding box - take first
   # <- geographicExtent[:boundingBox]
   hBBox = {}
   aExtents.each do |hExtent|
      unless hExtent.empty?
         hExtent[:geographicExtents].each do |hGeoExtent|
            unless hGeoExtent.empty?
               unless hGeoExtent[:boundingBox].empty?
                  hBBox = hGeoExtent[:boundingBox]
                  break
               end
            end
         end
      end
   end

   # look for bounding polygon
   # <- geographicExtent[:geographicElements]
   # polygon must be in a FeatureCollection with properties description of 'FGDC bounding polygon'
   aBPoly = []
   aExtents.each do |hExtent|
      unless hExtent.empty?
         hExtent[:geographicExtents].each do |hGeoExtent|
            unless hGeoExtent.empty?
               unless hGeoExtent[:geographicElements].empty?
                  hGeoExtent[:geographicElements].each do |hGeoElement|
                     if hGeoElement[:type] == 'FeatureCollection'
                        hGeoElement[:features].each do |hFeature|
                           if hFeature[:geometryObject][:type] == 'Polygon'
                              unless hFeature[:properties].empty?
                                 if hFeature[:properties][:description] == 'FGDC bounding polygon'
                                    aBPoly << hFeature[:geometryObject][:coordinates]
                                 end
                              end
                           end
                        end
                     end
                  end
               end
            end
         end
      end
   end

   # spatial domain 1.5 (spdom)
   unless geoDescription.empty? && hBBox.empty? && aBPoly.empty?
      @xml.tag!('spdom') do

         # spatial domain bio (descgeog) - geographic description (required)
         unless geoDescription.empty?
            @xml.tag!('descgeog', geoDescription)
         end
         if geoDescription.empty?
            @NameSpace.issueWarning(370, 'descgeog')
         end

         # spatial domain 1.5.1 (bounding) - bounding box (required)
         unless hBBox.empty?
            @xml.tag!('bounding') do

               # bounding box 1.5.1.1 (westbc) - west bounding coordinate
               @xml.tag!('westbc', hBBox[:westLongitude])

               # bounding box 1.5.1.2 (eastbc) - east bounding coordinate
               @xml.tag!('eastbc', hBBox[:eastLongitude])

               # bounding box 1.5.1.3 (northbc) - north bounding coordinate
               @xml.tag!('northbc', hBBox[:northLatitude])

               # bounding box 1.5.1.4 (southbc) - south bounding coordinate
               @xml.tag!('southbc', hBBox[:southLatitude])

               # altitude bounding bio extension
               unless hBBox[:minimumAltitude].nil? && hBBox[:maximumAltitude].nil? && hBBox[:unitsOfAltitude].nil?
                  @xml.tag!('boundalt') do

                     # altitude bounding (altmin) - minimum altitude (required)
                     unless hBBox[:minimumAltitude].nil?
                        @xml.tag!('altmin', hBBox[:minimumAltitude])
                     end
                     if hBBox[:minimumAltitude].nil?
                        @NameSpace.issueWarning(371, 'altmin')
                     end

                     # altitude bounding (altmax) - maximum altitude (required)
                     unless hBBox[:maximumAltitude].nil?
                        @xml.tag!('altmax', hBBox[:minimumAltitude])
                     end
                     if hBBox[:maximumAltitude].nil?
                        @NameSpace.issueWarning(372, 'altmax')
                     end

                     # altitude bounding (altunit) - units of altitude
                     unless hBBox[:unitsOfAltitude].nil?
                        @xml.tag!('altunits', hBBox[:unitsOfAltitude])
                     end
                     if hBBox[:unitsOfAltitude].nil?  && @hResponseObj[:writerShowTags]
                        @xml.tag!('altunits')
                     end

                  end
               end
               if hBBox[:minimumAltitude].nil? && hBBox[:maximumAltitude].nil? &&
                  hBBox[:unitsOfAltitude].nil? && @hResponseObj[:writerShowTags]
                  @xml.tag!('boundalt')
               end
            end
         end
         if hBBox.empty?
            @NameSpace.issueWarning(373, nil)
         end

         # spatial domain 1.5.2 (dsgpoly) - bounding polygon [] (required)
         unless aBPoly.empty?
            @xml.tag!('dsgpoly') do
               aBPoly.each do |aPoly|

                  # outer polygon 1.5.2.1 (dsgpolyo) - (required)
                  unless aPoly.empty?
                     @xml.tag!('dsgpolyo') do
                        aPoly[0].each do |aCoord|
                           @xml.tag!('grngpoin') do
                              @xml.tag!('grnglat', aCoord[0])
                              @xml.tag!('grnglon', aCoord[1])
                           end
                        end
                     end
                  end

                  # outer polygon 1.5.2.2 (dsgpolyx)
                  aPoly.delete_at(0)
                  unless aPoly.empty?
                     aPoly.each do |aExclude|
                        @xml.tag!('dsgpolyx') do
                           aExclude.each do |aCoord|
                              @xml.tag!('grngpoin') do
                                 @xml.tag!('grnglat', aCoord[0])
                                 @xml.tag!('grnglon', aCoord[1])
                              end
                           end
                        end
                     end
                  end

               end
            end
         end

      end
   end

end