Class: ADIWG::Mdtranslator::Writers::Iso19115_3::Polygon

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

Instance Method Summary collapse

Constructor Details

#initialize(xml, hResponseObj) ⇒ Polygon

Returns a new instance of Polygon.



17
18
19
20
# File 'lib/adiwg/mdtranslator/writers/iso19115_3/classes/class_polygon.rb', line 17

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

Instance Method Details

#writeXML(hGeoObject, hProperties, objId) ⇒ Object



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
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/adiwg/mdtranslator/writers/iso19115_3/classes/class_polygon.rb', line 22

def writeXML(hGeoObject, hProperties, objId)

   # classes used
   geoPropClass = FeatureProperties.new(@xml, @hResponseObj)

   # polygon attributes
   attributes = {}

   # polygon attributes - gml:id (required)
   if objId.nil?
      @hResponseObj[:writerMissingIdCount] = @hResponseObj[:writerMissingIdCount].succ
      objId = 'polygon' + @hResponseObj[:writerMissingIdCount]
   else
      objId.gsub!(/[^0-9a-zA-Z]/, '')
   end
   attributes['gml:id'] = objId

   # polygon attributes - srsDimension
   s = AdiwgCoordinates.getDimension(hGeoObject[:coordinates])
   if !s.nil?
      attributes[:srsDimension] = s
   end

   # polygon attributes - srsName (GeoJSON is WGS84)
   attributes[:srsName] = 'WGS84'

   @xml.tag!('gml:Polygon', attributes) do

      # polygon - properties for Feature
      unless hProperties.empty?
         geoPropClass.writeXML(hProperties)
      end
      if hProperties.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('gml:description')
         @xml.tag!('gml:identifier', {'codeSpace' => ''})
         @xml.tag!('gml:name')
      end

      aPolygons = hGeoObject[:coordinates]
      aExterior = aPolygons[0]
      aInterior = aPolygons.drop(1)

      # polygon - exterior ring (required)
      unless aExterior.nil?
         @xml.tag!('gml:exterior') do
            @xml.tag!('gml:LinearRing') do
               aExterior.each do |aCoord|
                  s = aCoord[0].to_s + ' ' + aCoord[1].to_s
                  @xml.tag!('gml:pos', s)
               end
            end
         end
      end

      # polygon - interior rings
      aInterior.each do |aRing|
         @xml.tag!('gml:interior') do
            @xml.tag!('gml:LinearRing') do
               aRing.each do |aCoord|
                  s = aCoord[0].to_s + ' ' + aCoord[1].to_s
                  @xml.tag!('gml:pos', s)
               end
            end
         end
      end

   end # gml:Polygon tag
end