Method: Charta::GML#initialize

Defined in:
lib/charta/gml.rb

#initialize(data, srid = :WGS84) ⇒ GML

Returns a new instance of GML.



16
17
18
19
20
21
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
# File 'lib/charta/gml.rb', line 16

def initialize(data, srid = :WGS84)
  srid ||= :WGS84
  @gml = if data.is_a? String

           Nokogiri::XML(data.to_s.split.join(' ')) do |config|
             config.options = Nokogiri::XML::ParseOptions::NOBLANKS
           end

         else
           # Nokogiri::XML::Document expected
           data
         end
  up = false
  # ensure namespaces are defined
  begin
    @gml.root.add_namespace_definition('xmlns', '')
    NS.each do |k, v|
      if @gml.xpath("//@*[xmlns:#{k}]").empty?
        @gml.root.namespace_definitions << @gml.root.add_namespace_definition(k.to_s, v)
        up = true
      end
    end
  rescue
    false
  end

  @gml = Nokogiri::XML(@gml.to_xml) if up

  boundaries = @gml.css("#{GML_PREFIX}|boundedBy")
  unless boundaries.nil?
    boundaries.each do |node|
      srid = Charta.find_srid(node['srsName']) unless node['srsName'].nil?
    end
  end

  @srid = Charta.find_srid(srid)
end