Class: RGeo::CoordSys::SRSDatabase::SrOrg
- Inherits:
-
Object
- Object
- RGeo::CoordSys::SRSDatabase::SrOrg
- Defined in:
- lib/rgeo/coord_sys/srs_database/sr_org.rb
Overview
A spatial reference database implementation that fetches data from the spatialreference.org website.
Instance Attribute Summary collapse
-
#catalog ⇒ Object
readonly
The spatialreference.org catalog used by this database.
Instance Method Summary collapse
-
#clear_cache ⇒ Object
Clear the cache if one exists.
-
#get(ident_) ⇒ Object
Retrieve the Entry from a spatialreference.org catalog given an integer ID.
-
#initialize(catalog_, opts_ = {}) ⇒ SrOrg
constructor
Create a database backed by the given catalog of the spatialreference.org website.
Constructor Details
#initialize(catalog_, opts_ = {}) ⇒ SrOrg
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.
27 28 29 30 |
# File 'lib/rgeo/coord_sys/srs_database/sr_org.rb', line 27 def initialize(catalog_, opts_ = {}) @catalog = catalog_.to_s.downcase @cache = opts_[:cache] ? {} : nil end |
Instance Attribute Details
#catalog ⇒ Object (readonly)
The spatialreference.org catalog used by this database.
33 34 35 |
# File 'lib/rgeo/coord_sys/srs_database/sr_org.rb', line 33 def catalog @catalog end |
Instance Method Details
#clear_cache ⇒ Object
Clear the cache if one exists.
56 57 58 |
# File 'lib/rgeo/coord_sys/srs_database/sr_org.rb', line 56 def clear_cache @cache.clear if @cache end |
#get(ident_) ⇒ Object
Retrieve the Entry from a spatialreference.org catalog given an integer ID.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rgeo/coord_sys/srs_database/sr_org.rb', line 38 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_.is_a?(::Net::HTTPSuccess) response_ = http_.request_get("/ref/#{@catalog}/#{ident_}/proj4/") proj4_ = response_.body if response_.is_a?(::Net::HTTPSuccess) end result_ = Entry.new(ident_, coord_sys: coord_sys_.strip, proj4: proj4_.strip) @cache[ident_] = result_ if @cache result_ end |