Class: RGeoServer::CoverageStore

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

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

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

Constructor Details

#initialize(catalog, options) ⇒ CoverageStore

Returns a new instance of CoverageStore.

Parameters:



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_xpathObject



64
65
66
# File 'lib/rgeoserver/coveragestore.rb', line 64

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

.resource_nameObject



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

def self.resource_name
  @@resource_name
end

.rootObject



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

def self.root
  @@root
end

.root_xpathObject



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

#messageObject



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

<coverageStore> <name>antietam_1867</name> <description> Map shows the U.S. Civil War battle of Antietam. It indicates fortifications, roads, railroads, houses, names of residents, fences, drainage, vegetation, and relief by hachures. </description> <type>GeoTIFF</type> <enabled>true</enabled> <workspace> <name>druid</name> <atom:link xmlns:atom=“www.w3.org/2005/Atom” rel=“alternate” href=“localhost:8080/geoserver/rest/workspaces/druid.xml” type=“application/xml”/> </workspace> <__default>false</__default> <url> file:///var/geoserver/current/staging/rumsey/g3881015alpha.tif </url> <coverages> <atom:link xmlns:atom=“www.w3.org/2005/Atom” rel=“alternate” href=“localhost:8080/geoserver/rest/workspaces/druid/coveragestores/antietam_1867/coverages.xml” type=“application/xml”/> </coverages> </coverageStore>



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 # Assume correct workspace
  }
  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

#routeObject



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

Parameters:

  • path (String)
    • location of upload data

  • upload_method (Symbol) (defaults to: :file)

    – only valid for :file

  • data_type (Symbol) (defaults to: :geotiff)

    – currently only supported for :geotiff

Raises:



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 that we post
    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