A spatial reference database implementation that fetches data from internet URLs.
Create a URL-based spatial reference database.
Options:
:cache
If set to true, lookup results are cached so if the same URL is requested again, the result is served from cache rather than issuing another HTTP request. Default is false.
# File lib/rgeo/coord_sys/srs_database/url_reader.rb, line 62 def initialize(opts_={}) @cache = opts_[:cache] ? {} : nil end
Clear the cache if one is present.
# File lib/rgeo/coord_sys/srs_database/url_reader.rb, line 96 def clear_cache @cache.clear if @cache end
Retrieve the given URL and return an Entry. Returns nil if the URL cannot be read as an OGC WKT or Proj4 coordinate system
# File lib/rgeo/coord_sys/srs_database/url_reader.rb, line 71 def get(ident_) ident_ = ident_.to_s return @cache[ident_] if @cache && @cache.include?(ident_) uri_ = ::URI.parse(ident_) result_ = nil ::Net::HTTP.start(uri_.host, uri_.port) do |http_| request_ = uri_.path request_ = "#{request_}?#{uri_.query}" if uri_.query response_ = http_.request_get(request_) if response_.kind_of?(::Net::HTTPSuccess) response_ = response_.body.strip if response_[0,1] == '+' result_ = Entry.new(ident_, :proj4 => response_) else result_ = Entry.new(ident_, :coord_sys => response_) end end end @cache[ident_] = result_ if @cache result_ end