Class: NSWTopo::Projection
- Inherits:
-
Object
- Object
- NSWTopo::Projection
- Extended by:
- Forwardable
- Defined in:
- lib/nswtopo/gis/projection.rb
Instance Attribute Summary collapse
-
#wkt2 ⇒ Object
(also: #to_s, #to_str)
readonly
Returns the value of attribute wkt2.
Class Method Summary collapse
- .azimuthal_equidistant(lon_0, lat_0) ⇒ Object
- .epsg(epsg) ⇒ Object
- .from(**params) ⇒ Object
- .oblique_mercator(lonc, lat_0, alpha:, **params) ⇒ Object
- .transverse_mercator(lon_0, lat_0, **params) ⇒ Object
- .utm(zone, south: true) ⇒ Object
- .utm_geometry(zone) ⇒ Object
- .utm_zones(collection) ⇒ Object
- .wgs84 ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(value) ⇒ Projection
constructor
A new instance of Projection.
- #metres? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ Projection
Returns a new instance of Projection.
3 4 5 6 |
# File 'lib/nswtopo/gis/projection.rb', line 3 def initialize(value) @wkt2 = Projection === value ? value.wkt2 : OS.gdalsrsinfo("-o", "wkt2", "--single-line", value).chomp.strip raise "no georeferencing found: %s" % value if @wkt2.empty? end |
Instance Attribute Details
#wkt2 ⇒ Object (readonly) Also known as: to_s, to_str
Returns the value of attribute wkt2.
8 9 10 |
# File 'lib/nswtopo/gis/projection.rb', line 8 def wkt2 @wkt2 end |
Class Method Details
.azimuthal_equidistant(lon_0, lat_0) ⇒ Object
52 53 54 |
# File 'lib/nswtopo/gis/projection.rb', line 52 def self.azimuthal_equidistant(lon_0, lat_0) from proj: "aeqd", datum: "WGS84", lon_0: lon_0, lat_0: lat_0 end |
.epsg(epsg) ⇒ Object
32 33 34 |
# File 'lib/nswtopo/gis/projection.rb', line 32 def self.epsg(epsg) new("EPSG:#{epsg}") end |
.from(**params) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/nswtopo/gis/projection.rb', line 36 def self.from(**params) params.map do |key, value| "+#{key}=#{value}" end.then do |args| new args.join(?\s) end end |
.oblique_mercator(lonc, lat_0, alpha:, **params) ⇒ Object
48 49 50 |
# File 'lib/nswtopo/gis/projection.rb', line 48 def self.oblique_mercator(lonc, lat_0, alpha:, **params) from proj: "omerc", datum: "WGS84", lonc: lonc, lat_0: lat_0, gamma: 0, alpha: alpha, **params end |
.transverse_mercator(lon_0, lat_0, **params) ⇒ Object
44 45 46 |
# File 'lib/nswtopo/gis/projection.rb', line 44 def self.transverse_mercator(lon_0, lat_0, **params) from proj: "tmerc", datum: "WGS84", lon_0: lon_0, lat_0: lat_0, **params end |
.utm(zone, south: true) ⇒ Object
24 25 26 |
# File 'lib/nswtopo/gis/projection.rb', line 24 def self.utm(zone, south: true) new("EPSG:32%1d%02d" % [south ? 7 : 6, zone]) end |
.utm_geometry(zone) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/nswtopo/gis/projection.rb', line 64 def self.utm_geometry(zone) longitudes = [31, 30].map { |offset| (zone - offset) * 6.0 } latitudes = [-80.0, 84.0] ring = longitudes.product(latitudes).values_at(0,2,3,1,0) GeoJSON.polygon [ring], projection: Projection.wgs84 end |
.utm_zones(collection) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/nswtopo/gis/projection.rb', line 56 def self.utm_zones(collection) collection.reproject_to_wgs84.bounds.first.map do |longitude| (longitude / 6).floor + 31 end.then do |min, max| min..max end end |
.wgs84 ⇒ Object
28 29 30 |
# File 'lib/nswtopo/gis/projection.rb', line 28 def self.wgs84 new("EPSG:4326") end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
12 13 14 |
# File 'lib/nswtopo/gis/projection.rb', line 12 def ==(other) super || wkt2 == other.wkt2 end |
#metres? ⇒ Boolean
20 21 22 |
# File 'lib/nswtopo/gis/projection.rb', line 20 def metres? OS.gdalsrsinfo("-o", "proj4", "--single-line", @wkt2).chomp.split.any?("+units=m") end |