class RGeoServer::Layer
A layer is a published resource (feature type or coverage).
Constants
- OBJ_ATTRIBUTES
- OBJ_DEFAULT_ATTRIBUTES
Public Class Methods
member_xpath()
click to toggle source
# File lib/rgeoserver/layer.rb, line 44 def self.member_xpath "//#{resource_name}" end
new(catalog, options)
click to toggle source
@param [RGeoServer::Catalog] catalog @param [Hash] options @option options [String] :name required @option options [String] :default_style @option options [Array<String>] :alternate_styles
Calls superclass method
# File lib/rgeoserver/layer.rb, line 104 def initialize catalog, options super(catalog) _run_initialize_callbacks do if options[:name].instance_of? Layer options[:name] = options[:name].name.to_s end raise GeoServerArgumentError, "Layer requires :name option" unless options.include? :name and options[:name].is_a? String @name = options[:name].to_s.strip ap({:init_name => @name}) if $DEBUG raise NotImplementedError, ":default_style" if options.include? :default_style raise NotImplementedError, ":alternate_styles" if options.include? :alternate_styles #@default_style = options[:default_style] || '' #@alternate_styles = options[:alternate_styles] || [] end @route = route end
resource_name()
click to toggle source
# File lib/rgeoserver/layer.rb, line 36 def self.resource_name @@resource_name end
root_xpath()
click to toggle source
# File lib/rgeoserver/layer.rb, line 40 def self.root_xpath "//#{@@route}/#{@@resource_name}" end
Public Instance Methods
create_route()
click to toggle source
No direct layer creation
# File lib/rgeoserver/layer.rb, line 53 def create_route nil end
get_alternate_styles(&block)
click to toggle source
# File lib/rgeoserver/layer.rb, line 168 def get_alternate_styles &block self.class.list Style, @catalog, @alternate_styles, {:layer => self}, false, &block end
get_default_style(&block)
click to toggle source
message()
click to toggle source
# File lib/rgeoserver/layer.rb, line 61 def message builder = Nokogiri::XML::Builder.new do |xml| xml.layer { xml.name @name xml.path path xml.type_ layer_type xml.enabled @enabled xml.queryable @queryable xml.defaultStyle { xml.name default_style } xml.styles { alternate_styles.each { |s| xml.style { xml.name s } } } unless alternate_styles.empty? xml.resource(:class => resource.class.resource_name){ xml.name resource.name } unless resource.nil? xml.metadata { metadata.each_pair { |k,v| xml.entry(:key => k) { xml.text v } } } xml.attribution { xml.title attribution['title'] unless attribution['title'].empty? xml.logoWidth attribution['logo_width'] xml.logoHeight attribution['logo_height'] } if !attribution['logo_width'].nil? && !attribution['logo_height'].nil? } end return builder.doc.to_xml end
prefixed_name()
click to toggle source
Return full name of resource with namespace prefix
# File lib/rgeoserver/layer.rb, line 208 def prefixed_name return "#{workspace.name}:#{name}" if self.respond_to?(:workspace) raise "Workspace is not defined for this resource" end
profile_xml_to_hash(profile_xml)
click to toggle source
# File lib/rgeoserver/layer.rb, line 172 def profile_xml_to_hash profile_xml doc = profile_xml_to_ng profile_xml name = doc.at_xpath('//name/text()').text.strip link = doc.at_xpath('//resource//atom:link/@href', "xmlns:atom"=>"http://www.w3.org/2005/Atom").text.strip workspace, _, store = link.match(/workspaces\/(.*?)\/(.*?)\/(.*?)\/(.*?)\/#{name}.xml$/).to_a[1,3] h = { "name" => name, "path" => doc.at_xpath('//path/text()').to_s, "default_style" => doc.at_xpath('//defaultStyle/name/text()').to_s, "alternate_styles" => doc.xpath('//styles/style/name/text()').collect{ |s| s.to_s}, # Types can be: VECTOR, RASTER, REMOTE, WMS "type" => doc.at_xpath('//type/text()').to_s, "enabled" => doc.at_xpath('//enabled/text()').to_s, "queryable" => doc.at_xpath('//queryable/text()').to_s, "attribution" => { "title" => doc.at_xpath('//attribution/title/text()').to_s, "logo_width" => doc.at_xpath('//attribution/logoWidth/text()').to_s, "logo_height" => doc.at_xpath('//attribution/logoHeight/text()').to_s }, "resource" => { "type" => doc.at_xpath('//resource/@class').to_s, "name" => doc.at_xpath('//resource/name/text()').to_s, "store" => store, "workspace" => workspace }, "metadata" => doc.xpath('//metadata/entry').inject({}){ |h2, e| h2.merge(e['key']=> e.text.to_s) } }.freeze h end
resource()
click to toggle source
# File lib/rgeoserver/layer.rb, line 131 def resource @resource ||= begin unless profile['resource'].empty? data_type = profile['resource']['type'] workspace = profile['resource']['workspace'] name = profile['resource']['name'] store = profile['resource']['store'] case data_type when 'coverage' return RGeoServer::Coverage.new @catalog, :workspace => workspace, :coverage_store => store, :name => name when 'featureType' ap({:catalog => @catalog, :workspace => workspace, :data_store => store, :name => name}) if $DEBUG begin ft = RGeoServer::FeatureType.new @catalog, :workspace => workspace, :data_store => store, :name => name ap({:featureType => ft, :route => ft.route}) if $DEBUG rescue Exception => e ap({:errormsg => "#{e}", :error => e, :trace => e.backtrace}) if $DEBUG end return ft else raise GeoServerArgumentError, 'Unknown resource type: #{data_type}' end else nil end rescue Exception => e nil end end
resource=(r)
click to toggle source
# File lib/rgeoserver/layer.rb, line 123 def resource= r if r.is_a?(RGeoServer::Coverage) || r.is_a?(RGeoServer::FeatureType) @resource = r else raise GeoServerArgumentError, 'Unknown resource type: #{r.class}' end end
route()
click to toggle source
# File lib/rgeoserver/layer.rb, line 48 def route @@route end
seed(operation, options)
click to toggle source
@param operation @option operation :issue seed @option operation :truncate seed @option operation :status of the seeding thread @param options for seed message. Read the documentation
# File lib/rgeoserver/layer.rb, line 235 def seed operation, options op = operation.to_sym sub_path = "seed/#{prefixed_name}.xml" case op when :issue @catalog.do_url sub_path, :post, _build_seed_request(:seed, options), {}, @catalog.gwc_client when :truncate @catalog.do_url sub_path, :post, _build_seed_request(:truncate, options), {}, @catalog.gwc_client when :status raise NotImplementedError, "#{op}" end end
update_params(name_route = @name)
click to toggle source
# File lib/rgeoserver/layer.rb, line 57 def update_params name_route = @name { :layer => name_route } end
workspace()
click to toggle source
# File lib/rgeoserver/layer.rb, line 203 def workspace resource.workspace end
Private Instance Methods
_build_seed_request(operation, options)
click to toggle source
@param options for seed message, requiring
options[:srs][:number] options[:bounds][:coords] options[:gridSetId] options[:zoomStart] options[:zoomStop] options[:gridSetId] options[:gridSetId]
# File lib/rgeoserver/layer.rb, line 258 def _build_seed_request operation, options builder = Nokogiri::XML::Builder.new do |xml| xml.seedRequest { xml.name prefixed_name xml.srs { xml.number options[:srs][:number] } unless options[:srs].nil? #&& options[:srs].is_a?(Hash) xml.bounds { xml.coords { options[:bounds][:coords].each { |dbl| xml.double dbl } } } unless options[:bounds].nil? xml.type_ operation [:gridSetId, :zoomStart, :zoomStop, :threadCount].each { |p| eval "xml.#{p.to_s} options[p]" unless options[p].nil? } xml.format_ options[:tileFormat] unless options[:tileFormat].nil? xml.parameters { options[:parameters].each_pair { |k,v| xml.entry { xml.string k.upcase xml.string v } } } if options[:parameters].is_a?(Hash) } end ap({:build_seed_request => builder.doc}) if $DEBUG return builder.doc.to_xml end