Class: ADIWG::Mdtranslator::Writers::Fgdc::SpatialReference

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

Instance Method Summary collapse

Constructor Details

#initialize(xml, hResponseObj) ⇒ SpatialReference



22
23
24
25
# File 'lib/adiwg/mdtranslator/writers/fgdc/classes/class_spatialReference.rb', line 22

def initialize(xml, hResponseObj)
   @xml = xml
   @hResponseObj = hResponseObj
end

Instance Method Details

#writeXML(hResourceInfo) ⇒ Object



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

def writeXML(hResourceInfo)

   aRepTypes = hResourceInfo[:spatialRepresentationTypes]
   aResolutions = hResourceInfo[:spatialResolutions]
   aSpaceRefs = hResourceInfo[:spatialReferenceSystems]

   # classes used
   geoResClass = GeographicResolution.new(@xml, @hResponseObj)
   planarClass = PlanarReference.new(@xml, @hResponseObj)
   localClass = LocalSystem.new(@xml, @hResponseObj)
   geodeticClass = GeodeticReference.new(@xml, @hResponseObj)
   vDatumClass = VerticalDatum.new(@xml, @hResponseObj)

   outContext = 'spatial reference'

   # spatial reference 4.1 (horizsys) - horizontal coordinate reference system (required)
   # oneOf [geograph | planar | local]
   @xml.tag!('horizsys') do

      # horizontal reference 4.1.1 (geograph) - geographic resolution
      # <- resourceInfo.spatialResolution[].geographicResolution (first)
      aResolutions.each do |hSpaceRes|
         unless hSpaceRes.empty?
            if hSpaceRes[:geographicResolution]
               unless hSpaceRes[:geographicResolution].empty?
                  @xml.tag!('geograph') do
                     geoResClass.writeXML(hSpaceRes[:geographicResolution], outContext)
                  end
                  break
               end
            end
         end
      end

      # horizontal reference 4.1.2 (planar) - planar coordinate system []
      # <- spatialReferencesTypes[]
      # <- spatialReferences[].systemParameterSet.projection
      # <- spatialResolution[].coordinateResolution
      # <- spatialResolution[].bearingDistanceResolution
      havePlanar = false
      havePlanar = true unless aRepTypes.empty?
      aSpaceRefs.each do |hSpaceRef|
         unless hSpaceRef[:systemParameterSet].empty?
            unless hSpaceRef[:systemParameterSet][:projection].empty?
               hProjection = hSpaceRef[:systemParameterSet][:projection]
               unless hProjection[:projectionIdentifier][:identifier] == 'localSystem'
                  havePlanar = true
               end
            end
         end
      end
      aResolutions.each do |hResolution|
         havePlanar = true if hResolution[:coordinateResolution]
         havePlanar = true if hResolution[:bearingDistanceResolution]
      end
      if havePlanar
         @xml.tag!('planar') do
            planarClass.writeXML(aSpaceRefs, aRepTypes, aResolutions, outContext)
         end
      end

      # horizontal reference 4.1.3 (local) - any rectangular coordinate system not aligned with surface of earth
      # <- spatialReferences[].systemParameterSet.projection
      # localSYSTEM is not the same as localPLANAR in fgdc
      # however the same projection parameters are used in mdJson to save info
      # local system sets projection = 'localSystem'
      # local planar sets projection = 'localPlanar'
      aSpaceRefs.each do |hSpaceRef|
         unless hSpaceRef[:systemParameterSet].empty?
            if hSpaceRef[:systemParameterSet][:projection]
               hProjection = hSpaceRef[:systemParameterSet][:projection]
               unless hProjection.empty?
                  if hProjection[:projectionIdentifier][:identifier] == 'localSystem'
                     @xml.tag!('local') do
                        localClass.writeXML(hProjection, outContext)
                     end
                  end
               end
            end
         end
      end

      # horizontal reference 4.1.4 (geodetic) - parameters for shape of earth
      # <- spatialReferences[].systemParameterSet.geodetic
      aSpaceRefs.each do |hSpaceRef|
         unless hSpaceRef[:systemParameterSet].empty?
            if hSpaceRef[:systemParameterSet][:geodetic]
               hGeodetic = hSpaceRef[:systemParameterSet][:geodetic]
               unless hGeodetic.empty?
                  @xml.tag!('geodetic') do
                     geodeticClass.writeXML(hGeodetic, outContext)
                  end
               end
            end
         end
      end

   end

   # vertical reference 4.2 (vertdef) - vertical coordinate reference system
   # <- spatialReferences[].systemParameterSet.verticalDatum
   # pass in the full spatial reference array,
   # ... all vertical datum must be under same 'vertdef' tag
   haveVertical = false
   aSpaceRefs.each do |hSpaceRef|
      unless hSpaceRef[:systemParameterSet].empty?
         unless hSpaceRef[:systemParameterSet][:verticalDatum].empty?
            haveVertical = true
         end
      end
   end
   if haveVertical
      @xml.tag!('vertdef') do
         vDatumClass.writeXML(aSpaceRefs, outContext)
      end
   end

end