Class: RGeoServer::Coverage

Inherits:
ResourceInfo show all
Defined in:
lib/rgeoserver/coverage.rb

Overview

A coverage is a raster based data set which originates from a coverage store.

Constant Summary collapse

OBJ_ATTRIBUTES =
{
  :catalog => "catalog", 
  :workspace => "workspace", 
  :coverage_store => "coverage_store", 
  :enabled => "enabled",
  :name => "name", 
  :title => "title", 
  :abstract => "abstract", 
  :keywords => "keywords", 
  :metadata => "metadata", 
  :metadata_links => "metadataLinks" 
}
OBJ_DEFAULT_ATTRIBUTES =
{
  :catalog => nil, 
  :workspace => nil, 
  :coverage_store => nil, 
  :enabled => "true",
  :name => nil, 
  :title => nil, 
  :abstract => nil,  
  :keywords => [],  
  :metadata => {},  
  :metadata_links => [] 
}
@@metadata_types =
{
  'ISO19139' => 'application/vnd.iso.19139+xml',
  'TC211' => 'application/vnd.iso.19139+xml'
}
@@route =
"workspaces/%s/coveragestores/%s/coverages"
@@root =
"coverages"
@@resource_name =
"coverage"

Instance Attribute Summary

Attributes inherited from ResourceInfo

#catalog

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ResourceInfo

#clear, #create_method, #delete, list, #new?, #profile, #profile=, #profile_xml_to_ng, #refresh, #save, #to_s, update_attribute_accessors, #update_method, #update_params

Constructor Details

#initialize(catalog, options) ⇒ Coverage

Returns a new instance of Coverage.

Parameters:



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
# File 'lib/rgeoserver/coverage.rb', line 96

def initialize catalog, options 
  super(catalog)
  _run_initialize_callbacks do
    workspace = options[:workspace] || 'default'
    if workspace.instance_of? String
      @workspace = @catalog.get_workspace(workspace)
    elsif workspace.instance_of? Workspace
      @workspace = workspace
    else
      raise "Not a valid workspace"
    end
    coverage_store = options[:coverage_store]
    if coverage_store.instance_of? String
      @coverage_store = CoverageStore.new @catalog, :workspace => @workspace, :name => coverage_store
    elsif coverage_store.instance_of? CoverageStore
      @coverage_store = coverage_store
    else
      raise "Not a valid coverage store"
    end

    @name = options[:name]
    @enabled = options[:enabled] || true
    @route = route
  end
end

Class Method Details

.member_xpathObject



48
49
50
# File 'lib/rgeoserver/coverage.rb', line 48

def self.member_xpath
  "//#{resource_name}"
end

.resource_nameObject



52
53
54
# File 'lib/rgeoserver/coverage.rb', line 52

def self.resource_name
  @@resource_name
end

.rootObject



44
45
46
# File 'lib/rgeoserver/coverage.rb', line 44

def self.root
  @@root
end

Instance Method Details

#messageObject



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
# File 'lib/rgeoserver/coverage.rb', line 65

def message
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.coverage {
      xml.nativeName @name if new? # on new only
      xml.name @name
      xml.title @title if title_changed? || new?
      xml.abstract @abstract if abstract_changed? || new?
      xml.enabled @enabled
      xml.metadataLinks {
        @metadata_links.each do |m|
          raise ArgumentError, "Malformed metadata_links" unless m.is_a? Hash
          xml.metadataLink {
            xml.type_ to_mimetype(m['metadataType'])
            xml.metadataType m['metadataType']
            xml.content m['content']
          }
        end
      } unless @metadata_links.empty?
      xml.keywords {
        @keywords.each do |k|
          xml.keyword RGeoServer::Metadata::to_keyword(k)
        end
      } if @keywords and new? or keywords_changed?
      
    }
  end
  @message = builder.doc.to_xml 
end

#profile_xml_to_hash(profile_xml) ⇒ Hash

Returns extraction from GeoServer XML for this coverage.

Returns:

  • (Hash)

    extraction from GeoServer XML for this coverage



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
# File 'lib/rgeoserver/coverage.rb', line 123

def profile_xml_to_hash profile_xml
  doc = profile_xml_to_ng profile_xml
  h = {
    "coverage_store" => @coverage_store.name,
    "workspace" => @workspace.name,
    "name" => doc.at_xpath('//name').text.strip,
    "nativeName" => doc.at_xpath('//nativeName/text()').to_s,
    "nativeCRS" => doc.at_xpath('//nativeCRS/text()').to_s,
    "title" => doc.at_xpath('//title/text()').to_s,
    "srs" => doc.at_xpath('//srs/text()').to_s,
    "nativeBoundingBox" => { 
      'minx' => doc.at_xpath('//nativeBoundingBox/minx/text()').to_s,
      'miny' => doc.at_xpath('//nativeBoundingBox/miny/text()').to_s,
      'maxx' => doc.at_xpath('//nativeBoundingBox/maxx/text()').to_s,
      'maxy' => doc.at_xpath('//nativeBoundingBox/maxy/text()').to_s,
      'crs' => doc.at_xpath('//nativeBoundingBox/crs/text()').to_s
    },
    "latLonBoundingBox" => { 
      'minx' => doc.at_xpath('//latLonBoundingBox/minx/text()').to_s,
      'miny' => doc.at_xpath('//latLonBoundingBox/miny/text()').to_s,
      'maxx' => doc.at_xpath('//latLonBoundingBox/maxx/text()').to_s,
      'maxy' => doc.at_xpath('//latLonBoundingBox/maxy/text()').to_s,
      'crs' => doc.at_xpath('//latLonBoundingBox/crs/text()').to_s
    },
    "abstract" => doc.at_xpath('//abstract/text()').to_s, 
    "supportedFormats" => doc.xpath('//supportedFormats/string').collect{ |t| t.to_s },
    "keywords" => doc.at_xpath('//keywords').collect { |kl|
      {
        'keyword' => kl.at_xpath('//string/text()').to_s
      }
    },
    "metadataLinks" => doc.xpath('//metadataLinks/metadataLink').collect{ |m|
      {
        'type' => m.at_xpath('//type/text()').to_s,
        'metadataType' => m.at_xpath('//metadataType/text()').to_s,
        'content' => m.at_xpath('//content/text()').to_s
      }
    },
  }.freeze
  h  
end

#routeObject



56
57
58
# File 'lib/rgeoserver/coverage.rb', line 56

def route
  @@route % [@workspace.name , @coverage_store.name]
end

#to_mimetype(type, default = 'text/xml') ⇒ Object



60
61
62
63
# File 'lib/rgeoserver/coverage.rb', line 60

def to_mimetype(type, default = 'text/xml')
  return @@metadata_types[type.upcase] if @@metadata_types.include?(type.upcase) 
  default
end