class RGeoServer::DataStore
A data store is a source of spatial data that is vector based. It can be a file in the case of a Shapefile, a database in the case of PostGIS, or a server in the case of a remote Web Feature Service.
Constants
- OBJ_ATTRIBUTES
- OBJ_DEFAULT_ATTRIBUTES
Attributes
message[RW]
Public Class Methods
member_xpath()
click to toggle source
# File lib/rgeoserver/datastore.rb, line 64 def self.member_xpath "//#{resource_name}" end
new(catalog, options)
click to toggle source
@param [RGeoServer::Catalog] catalog @param [RGeoServer::Workspace|String] options `:workspace` @param [String] options `:name`
Calls superclass method
# File lib/rgeoserver/datastore.rb, line 99 def initialize catalog, options super({}) _run_initialize_callbacks do @catalog = catalog workspace = options[:workspace] || 'default' if workspace.instance_of? String @workspace = catalog.get_workspace(workspace) elsif workspace.instance_of? Workspace @workspace = workspace else raise ArgumentError, "Not a valid workspace: #{workspace}" end @name = options[:name].strip @route = route end end
resource_name()
click to toggle source
# File lib/rgeoserver/datastore.rb, line 56 def self.resource_name @@resource_name end
root()
click to toggle source
# File lib/rgeoserver/datastore.rb, line 52 def self.root @@root end
root_xpath()
click to toggle source
# File lib/rgeoserver/datastore.rb, line 60 def self.root_xpath "//#{root}/#{resource_name}" end
Public Instance Methods
featuretypes(&block)
click to toggle source
# File lib/rgeoserver/datastore.rb, line 117 def featuretypes &block self.class.list FeatureType, catalog, profile['featureTypes'] || [], {:workspace => @workspace, :data_store => self}, true, &block end
profile_xml_to_hash(profile_xml)
click to toggle source
# File lib/rgeoserver/datastore.rb, line 163 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, "enabled" => doc.at_xpath('//enabled/text()').to_s, 'type' => doc.at_xpath('//type/text()').to_s, "connection_parameters" => doc.xpath('//connectionParameters/entry').inject({}){ |x, e| x.merge(e['key']=> e.text.to_s) } } # XXX: assume that we know the workspace for <workspace>...</workspace> doc.xpath('//featureTypes/atom:link[@rel="alternate"]/@href', "xmlns:atom"=>"http://www.w3.org/2005/Atom" ).each do |l| h["featureTypes"] = begin response = catalog.do_url l.text # lazy loading: only loads featuretype names Nokogiri::XML(response).xpath('//name/text()').collect{ |a| a.text.strip } rescue RestClient::ResourceNotFound [] end.freeze end h end
route()
click to toggle source
# File lib/rgeoserver/datastore.rb, line 68 def route @@route % @workspace.name end
update_route()
click to toggle source
# File lib/rgeoserver/datastore.rb, line 72 def update_route "#{route}/#{@name}" end
upload(path, upload_method = :file, data_type = :shapefile, publish = false)
click to toggle source
@param [String] path - location of upload data @param [Symbol] upload_method – flag for :file, :url, or :external @param [Symbol] data_type – currently only :shapefile @param [Boolean] publish – only valid for :file
# File lib/rgeoserver/datastore.rb, line 136 def upload path, upload_method = :file, data_type = :shapefile, publish = false ap({ :path => path, :upload_method => upload_method, :data_type => data_type, :publish => publish, :self => self}) if $DEBUG raise DataStoreAlreadyExists, @name unless new? raise DataTypeNotExpected, data_type unless [:shapefile].include? data_type ext = 'shp' case upload_method when :file then # local file that we post local_file = File.expand_path(path) unless local_file =~ %r{\.zip$} and File.exist? local_file raise ArgumentError, "Shapefile upload must be ZIP file: #{local_file}" end puts "Uploading #{File.size(local_file)} bytes from file #{local_file}..." catalog.client["#{route}/#{name}/file.#{ext}"].put File.read(local_file), :content_type => 'application/zip' refresh when :external then # remote file that we reference catalog.client["#{route}/#{name}/external.#{ext}"].put path, :content_type => 'text/plain' when :url then catalog.client["#{route}/#{name}/url.#{ext}"].put path, :content_type => 'text/plain' else raise NotImplementedError, "Unsupported upload method #{upload_method}" end self end
upload_external(remote_file, publish = {})
click to toggle source
# File lib/rgeoserver/datastore.rb, line 124 def upload_external remote_file, publish = {} puts "Uploading external file #{remote_file} #{publish}" upload remote_file, :external, data_type, publish end
upload_file(local_file, publish = {})
click to toggle source
# File lib/rgeoserver/datastore.rb, line 121 def upload_file local_file, publish = {} upload local_file, :file, data_type, publish end
upload_url(url, publish = {})
click to toggle source
# File lib/rgeoserver/datastore.rb, line 128 def upload_url url, publish = {} upload url, :url, data_type, publish end