Class: RGeoServer::CoverageStore
Overview
A coverage store is a source of spatial data that is raster based.
Defined Under Namespace
Classes: CoverageStoreAlreadyExists, DataTypeNotExpected
Constant Summary
collapse
- OBJ_ATTRIBUTES =
{
:catalog => 'catalog',
:workspace => 'workspace',
:url => 'url',
:data_type => 'type',
:name => 'name',
:enabled => 'enabled',
:description => 'description'
}
- OBJ_DEFAULT_ATTRIBUTES =
{
:catalog => nil,
:workspace => nil,
:url => '',
:data_type => 'GeoTIFF',
:name => nil,
:enabled => 'true',
:description=>nil
}
- @@route =
"workspaces/%s/coveragestores"
- @@root =
"coverageStores"
- @@resource_name =
"coverageStore"
Instance Attribute Summary
Attributes inherited from ResourceInfo
#catalog
Class Method Summary
collapse
Instance Method Summary
collapse
#clear, #create_method, #delete, list, #new?, #profile, #profile=, #profile_xml_to_ng, #refresh, #save, #to_s, update_attribute_accessors, #update_method
Constructor Details
#initialize(catalog, options) ⇒ CoverageStore
Returns a new instance of CoverageStore.
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/rgeoserver/coveragestore.rb', line 95
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
@name = options[:name].strip
@route = route
end
end
|
Class Method Details
.member_xpath ⇒ Object
64
65
66
|
# File 'lib/rgeoserver/coveragestore.rb', line 64
def self.member_xpath
"//#{resource_name}"
end
|
.resource_name ⇒ Object
56
57
58
|
# File 'lib/rgeoserver/coveragestore.rb', line 56
def self.resource_name
@@resource_name
end
|
.root ⇒ Object
52
53
54
|
# File 'lib/rgeoserver/coveragestore.rb', line 52
def self.root
@@root
end
|
.root_xpath ⇒ Object
60
61
62
|
# File 'lib/rgeoserver/coveragestore.rb', line 60
def self.root_xpath
"//#{root}/#{resource_name}"
end
|
Instance Method Details
#coverages(&block) ⇒ Object
111
112
113
|
# File 'lib/rgeoserver/coveragestore.rb', line 111
def coverages &block
self.class.list Coverage, @catalog, profile['coverages'] || [], {:workspace => @workspace, :coverage_store => self}, true, &block
end
|
#message ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/rgeoserver/coveragestore.rb', line 76
def message
builder = Nokogiri::XML::Builder.new do |xml|
xml.coverageStore {
xml.name @name
xml.workspace {
xml.name @workspace.name
}
xml.enabled @enabled
xml.type_ @data_type if (data_type_changed? || new?)
xml.description @description if (description_changed? || new?)
xml.url @url if (url_changed? || new?) && !@url.nil?
}
end
@message = builder.doc.to_xml
end
|
#profile_xml_to_hash(profile_xml) ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/rgeoserver/coveragestore.rb', line 134
def profile_xml_to_hash profile_xml
doc = profile_xml_to_ng profile_xml
h = {
'name' => doc.at_xpath('//name').text.strip,
'description' => doc.at_xpath('//description/text()').to_s,
'type' => doc.at_xpath('//type/text()').to_s,
'enabled' => doc.at_xpath('//enabled/text()').to_s,
'url' => doc.at_xpath('//url/text()').to_s,
'workspace' => @workspace.name }
doc.xpath('//coverages/atom:link[@rel="alternate"]/@href',
"xmlns:atom"=>"http://www.w3.org/2005/Atom" ).each{ |l|
h['coverages'] = begin
response = @catalog.do_url l.text
Nokogiri::XML(response).xpath('//name/text()').collect{ |a| a.text.strip }
rescue RestClient::ResourceNotFound
[]
end.freeze
}
h
end
|
#route ⇒ Object
68
69
70
|
# File 'lib/rgeoserver/coveragestore.rb', line 68
def route
@@route % @workspace.name
end
|
#update_params(name_route = @name) ⇒ Object
72
73
74
|
# File 'lib/rgeoserver/coveragestore.rb', line 72
def update_params name_route = @name
{ :name => name_route, :workspace => @workspace.name }
end
|
#upload(path, upload_method = :file, data_type = :geotiff) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/rgeoserver/coveragestore.rb', line 159
def upload path, upload_method = :file, data_type = :geotiff
raise CoverageStoreAlreadyExists, @name unless new?
raise DataTypeNotExpected, data_type unless [:geotiff].include? data_type
case upload_method
when :file then local_file = Pathname.new(File.expand_path(path))
unless local_file.extname == '.tif' && local_file.exist?
raise ArgumentError, "GeoTIFF upload must be .tif file: #{local_file}"
end
puts "Uploading #{local_file.size} bytes from file #{local_file}..."
catalog.client["#{route}/#{name}/file.geotiff"].put local_file.read, :content_type => 'image/tiff'
refresh
else
raise NotImplementedError, "Unsupported upload method #{upload_method}"
end
self
end
|