Class: RGeoServer::LayerGroup
Overview
A layer group is a grouping of layers and styles that can be accessed as a single layer in a WMS GetMap request. A Layer group is often referred to as a “base map”.
Constant Summary
collapse
- OBJ_ATTRIBUTES =
{:catalog => 'catalog', :name => 'name', :workspace => 'workspace', :layers => 'layers', :styles => 'styles', :bounds => 'bounds', :metadata => 'metadata' }
- OBJ_DEFAULT_ATTRIBUTES =
{:catalog => nil, :name => nil, :workspace => nil, :layers => [], :styles => [], :bounds => {'minx'=>nil, 'miny' =>nil, 'maxx'=>nil, 'maxy'=>nil, 'crs' =>nil}, :metadata => {} }
- @@xml_list_node =
"layerGroups"
- @@xml_node =
"layerGroup"
- @@route =
"layergroups"
- @@resource_name =
"layerGroup"
Instance Attribute Summary
Attributes inherited from ResourceInfo
#catalog
Class Method Summary
collapse
Instance Method Summary
collapse
#clear, #create_method, #delete, list, #new?, #profile=, #profile_xml_to_ng, #refresh, #save, #to_s, update_attribute_accessors, #update_method, #update_params
Constructor Details
#initialize(catalog, options) ⇒ LayerGroup
Returns a new instance of LayerGroup.
70
71
72
73
74
75
76
77
|
# File 'lib/rgeoserver/layergroup.rb', line 70
def initialize catalog, options
super(catalog)
_run_initialize_callbacks do
@name = options[:name].strip
@workspace = options[:workspace]
end
@route = route
end
|
Class Method Details
.member_xpath ⇒ Object
26
27
28
|
# File 'lib/rgeoserver/layergroup.rb', line 26
def self.member_xpath
"//#{@@xml_node}"
end
|
.resource_name ⇒ Object
18
19
20
|
# File 'lib/rgeoserver/layergroup.rb', line 18
def self.resource_name
@@resource_name
end
|
.root_xpath ⇒ Object
22
23
24
|
# File 'lib/rgeoserver/layergroup.rb', line 22
def self.root_xpath
"//#{@@xml_list_node}/#{@@xml_node}"
end
|
Instance Method Details
#bounds ⇒ Object
136
137
138
|
# File 'lib/rgeoserver/layergroup.rb', line 136
def bounds
@bounds = valid_bounds? ? @bounds : profile['bounds']
end
|
#layers ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/rgeoserver/layergroup.rb', line 111
def layers
@layers =
unless new?
begin
unless profile['layers'].empty?
return profile['layers'].map{ |s| RGeoServer::Layer.new @catalog, :name => s }
else
nil
end
rescue Exception => e
nil
end
else
@layers || []
end
end
|
#layers=(ll) ⇒ Object
102
103
104
105
106
107
108
109
|
# File 'lib/rgeoserver/layergroup.rb', line 102
def layers= ll
if ll.inject(true){ |t,l| t && l.is_a?(RGeoServer::Layer) }
layers_will_change! unless ll == layers
@layers = ll
else
raise 'Unknown list of layers'
end
end
|
#message ⇒ Object
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
|
# File 'lib/rgeoserver/layergroup.rb', line 34
def message
builder = Nokogiri::XML::Builder.new do |xml|
xml.layerGroup {
xml.name @name
xml.workspace {
xml.name workspace.name
} unless workspace.nil?
xml.layers {
layers.each { |l|
xml.layer {
xml.name l.name
}
}
} unless layers.nil?
xml.styles {
styles.each { |s|
xml.style {
xml.name s.name
}
}
} unless styles.nil?
xml.bounds {
xml.minx bounds['minx'] if bounds['minx']
xml.maxx bounds['maxx'] if bounds['miny']
xml.miny bounds['miny'] if bounds['maxx']
xml.maxy bounds['maxy'] if bounds['maxy']
xml.crs bounds['crs'] if bounds['crs']
} if valid_bounds?
}
end
return builder.doc.to_xml
end
|
#profile ⇒ Hash
Retrieve the resource profile as a hash and cache it
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/rgeoserver/layergroup.rb', line 169
def profile
if @profile && !@profile.empty?
return @profile
end
@profile =
begin
h = unless @workspace
profile_xml_to_hash(@catalog.search @route => @name )
else
profile_xml_to_hash(@catalog.search workspaces: @workspace, @route => @name )
end
@new = false
h
rescue RestClient::ResourceNotFound
@new = true
{}
end.freeze
end
|
#profile_xml_to_hash(profile_xml) ⇒ Object
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/rgeoserver/layergroup.rb', line 190
def profile_xml_to_hash profile_xml
doc = profile_xml_to_ng profile_xml
name = doc.at_xpath('//name/text()').to_s
h = {
"name" => name,
"workspace" => doc.xpath('//workspace/name/text()').to_s,
"layers" => doc.xpath('//layers/layer/name/text()').collect{|l| l.to_s},
"styles" => doc.xpath('//styles/style/name/text()').collect{|s| s.to_s},
"bounds" => {
"minx" => doc.at_xpath('//bounds/minx/text()').to_s.to_f,
"maxx" => doc.at_xpath('//bounds/maxx/text()').to_s.to_f,
"miny" => doc.at_xpath('//bounds/miny/text()').to_s.to_f,
"maxy" => doc.at_xpath('//bounds/maxy/text()').to_s.to_f,
"crs" => doc.at_xpath('//bounds/crs/text()').to_s
},
"metadata" => doc.xpath('//metadata/entry').inject({}){ |h, e| h.merge(e['key']=> e.text.to_s) }
}.freeze
h
end
|
#recalculate_bounds ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/rgeoserver/layergroup.rb', line 145
def recalculate_bounds
bbox = BoundingBox.new
layers.each do |layer|
case layer.resource
when RGeoServer::FeatureType
b = layer.resource.latlon_bounds
bbox.add b['minx'], b['miny']
bbox.add b['maxx'], b['maxy']
else
raise NotImplementedError, 'The bounds calculation for coverage resource was not implemented.'
end
end
@bounds =
{'minx' => bbox.min[0], 'miny' => bbox.min[1],
'maxx' => bbox.max[0], 'maxy' => bbox.max[1],
'crs' => @bounds['crs']}
bounds
end
|
#route ⇒ Object
30
31
32
|
# File 'lib/rgeoserver/layergroup.rb', line 30
def route
@@route
end
|
#styles ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/rgeoserver/layergroup.rb', line 89
def styles
@styles ||= begin
unless profile['styles'].empty?
return profile['styles'].each{ |s| RGeoServer::Style.new @catalog, :name => s.name }
else
nil
end
rescue Exception => e
nil
end
end
|
#styles=(sl) ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'lib/rgeoserver/layergroup.rb', line 80
def styles= sl
if sl.inject(true){|t,s| t && s.is_a?(RGeoServer::Style)}
styles_will_change! unless sl == styles
@styles = sl
else
raise 'Unknown list of styles'
end
end
|
#valid_bounds? ⇒ Boolean
140
141
142
143
|
# File 'lib/rgeoserver/layergroup.rb', line 140
def valid_bounds?
@bounds &&
![@bounds['minx'], @bounds['miny'], @bounds['maxx'], @bounds['maxy'], @bounds['crs']].compact.empty?
end
|
#workspace ⇒ Object
128
129
130
131
132
133
134
|
# File 'lib/rgeoserver/layergroup.rb', line 128
def workspace
if new?
return @workspace
else
return RGeoServer::Workspace.new @catalog, name: profile['workspace']
end
end
|