Class: RGeoServer::Style

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

Overview

A style describes how a resource (feature type or coverage) should be symbolized or rendered by a Web Map Service. In GeoServer styles are specified with SLD

Constant Summary collapse

OBJ_ATTRIBUTES =
{:catalog => 'catalog', :name => 'name', :sld_version => 'sldVersion', :filename => 'filename', :sld_doc => 'sld_doc' }
OBJ_DEFAULT_ATTRIBUTES =
{:catalog => nil, :name => nil, :sld_version => nil, :filename => '', :sld_doc => nil }
@@route =
"styles"
@@resource_name =
"style"
@@sld_namespace =
"http://www.opengis.net/sld"

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) ⇒ Style

Returns a new instance of Style.

Parameters:



64
65
66
67
68
69
70
# File 'lib/rgeoserver/style.rb', line 64

def initialize catalog, options
  super(catalog)
  _run_initialize_callbacks do
    @name = options[:name].strip
  end        
  @route = route
end

Class Method Details

.member_xpathObject



24
25
26
# File 'lib/rgeoserver/style.rb', line 24

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

.resource_nameObject



16
17
18
# File 'lib/rgeoserver/style.rb', line 16

def self.resource_name
  @@resource_name
end

.root_xpathObject



20
21
22
# File 'lib/rgeoserver/style.rb', line 20

def self.root_xpath
  "//#{@@route}/#{@@resource_name}"
end

Instance Method Details

#create_optionsObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/rgeoserver/style.rb', line 37

def create_options
  {
    :headers => {
      :accept => :xml,
      :content_type=> "application/vnd.ogc.sld+xml"
    },
    :format => :xml,
    :name => @name
  }
end

#layers(&block) ⇒ Object

Obtain all layers that use this style. WARNING: This will be slow and inneficient when the list of all layers is too long.



74
75
76
77
78
79
80
# File 'lib/rgeoserver/style.rb', line 74

def layers &block
  return to_enum(:layers).to_a unless block_given?
  @catalog.get_layers do |l|
    lyrs = [l.profile['default_style']]+l.profile['alternate_styles']
    yield l if lyrs.include? @name
  end 
end

#messageObject



58
59
60
# File 'lib/rgeoserver/style.rb', line 58

def message
  @sld_doc
end

#profile_xml_to_hash(profile_xml) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/rgeoserver/style.rb', line 82

def profile_xml_to_hash profile_xml
  doc = profile_xml_to_ng profile_xml
  h = {
    'name' => doc.at_xpath('//name').text.strip, 
    'sld_version' => doc.at_xpath('//sldVersion/version/text()').to_s,
    'filename' => doc.at_xpath('//filename/text()').to_s,
    'sld_doc' => begin
      Nokogiri::XML(@catalog.search({:styles => @name}, options={:format => :sld})).to_xml
    rescue RestClient::ResourceNotFound
      nil 
    end
  }.freeze 
  h 
end

#routeObject



28
29
30
# File 'lib/rgeoserver/style.rb', line 28

def route
  @@route  
end

#sld_namespaceObject



32
33
34
# File 'lib/rgeoserver/style.rb', line 32

def sld_namespace
  @@sld_namespace
end

#update_optionsObject



48
49
50
51
52
53
54
55
56
# File 'lib/rgeoserver/style.rb', line 48

def update_options
  {
    :headers => {
      :accept => :xml,
      :content_type=> "application/vnd.ogc.sld+xml"
    },
    :format => :sld
  }
end