class RGeo::CoordSys::SRSDatabase::SrOrg

A spatial reference database implementation that fetches data from the spatialreference.org website.

Attributes

catalog[R]

The spatialreference.org catalog used by this database.

Public Class Methods

new(catalog_, opts_={}) click to toggle source

Create a database backed by the given catalog of the spatialreference.org website. Catalogs currently supported by spatialreference.org are “epsg”, “esri”, “iau2000” and “sr-org”.

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/sr_org.rb, line 64
def initialize(catalog_, opts_={})
  @catalog = catalog_.to_s.downcase
  @cache = opts_[:cache] ? {} : nil
end

Public Instance Methods

clear_cache() click to toggle source

Clear the cache if one exists.

# File lib/rgeo/coord_sys/srs_database/sr_org.rb, line 96
def clear_cache
  @cache.clear if @cache
end
get(ident_) click to toggle source

Retrieve the Entry from a spatialreference.org catalog given an integer ID.

# File lib/rgeo/coord_sys/srs_database/sr_org.rb, line 77
def get(ident_)
  ident_ = ident_.to_s
  return @cache[ident_] if @cache && @cache.include?(ident_)
  coord_sys_ = nil
  proj4_ = nil
  ::Net::HTTP.start('spatialreference.org') do |http_|
    response_ = http_.request_get("/ref/#{@catalog}/#{ident_}/ogcwkt/")
    coord_sys_ = response_.body if response_.kind_of?(::Net::HTTPSuccess)
    response_ = http_.request_get("/ref/#{@catalog}/#{ident_}/proj4/")
    proj4_ = response_.body if response_.kind_of?(::Net::HTTPSuccess)
  end
  result_ = Entry.new(ident_, :coord_sys => coord_sys_.strip, :proj4 => proj4_.strip)
  @cache[ident_] = result_ if @cache
  result_
end