Class: NSWTopo::Projection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/nswtopo/gis/projection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string_or_path) ⇒ Projection



3
4
5
6
# File 'lib/nswtopo/gis/projection.rb', line 3

def initialize(string_or_path)
  @proj4 = OS.gdalsrsinfo("-o", "proj4", string_or_path).chomp.strip
  raise "no georeferencing found: %s" % string_or_path if @proj4.empty?
end

Instance Attribute Details

#proj4Object (readonly) Also known as: to_s, to_str

Returns the value of attribute proj4.



14
15
16
# File 'lib/nswtopo/gis/projection.rb', line 14

def proj4
  @proj4
end

Class Method Details

.azimuthal_equidistant(lon, lat) ⇒ Object



38
39
40
# File 'lib/nswtopo/gis/projection.rb', line 38

def self.azimuthal_equidistant(lon, lat)
  new("+proj=aeqd +lon_0=#{lon} +lat_0=#{lat} +k_0=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
end

.transverse_mercator(lon, lat) ⇒ Object



34
35
36
# File 'lib/nswtopo/gis/projection.rb', line 34

def self.transverse_mercator(lon, lat)
  new("+proj=tmerc +lon_0=#{lon} +lat_0=#{lat} +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
end

.utm(zone, south = true) ⇒ Object



26
27
28
# File 'lib/nswtopo/gis/projection.rb', line 26

def self.utm(zone, south = true)
  new("+proj=utm +zone=#{zone}#{' +south' if south} +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
end

.utm_hull(zone) ⇒ Object



50
51
52
53
54
# File 'lib/nswtopo/gis/projection.rb', line 50

def self.utm_hull(zone)
  longitudes = [31, 30].map { |offset| (zone - offset) * 6.0 }
  latitudes = [-80.0, 84.0]
  longitudes.product(latitudes).values_at(0,2,3,1)
end

.utm_zones(collection) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/nswtopo/gis/projection.rb', line 42

def self.utm_zones(collection)
  collection.reproject_to_wgs84.bounds.first.map do |longitude|
    (longitude / 6).floor + 31
  end.yield_self do |min, max|
    min..max
  end
end

.wgs84Object



30
31
32
# File 'lib/nswtopo/gis/projection.rb', line 30

def self.wgs84
  new("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



18
19
20
# File 'lib/nswtopo/gis/projection.rb', line 18

def ==(other)
  proj4 == other.proj4
end