Class: GrassGis::Location
- Inherits:
-
Object
- Object
- GrassGis::Location
- Defined in:
- lib/grassgis/location.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #create!(options = {}) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(context) ⇒ Location
constructor
A new instance of Location.
- #mapset_path(mapset) ⇒ Object
- #permanent_path ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(context) ⇒ Location
Returns a new instance of Location.
3 4 5 6 7 8 9 |
# File 'lib/grassgis/location.rb', line 3 def initialize(context) @context = context @configuration = @context.configuration @gisdbase = @configuration[:gisdbase] @location = @configuration[:location] @path = File.join(@gisdbase, @location) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/grassgis/location.rb', line 11 def path @path end |
Instance Method Details
#create!(options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/grassgis/location.rb', line 21 def create!( = {}) raise Error, "Location #{@location} already exists" if exists? raise Error, "A file with the same name #{@location} exists" if File.exists?(@path) raise Error, "GRASSDBASE doesn't exist" unless File.directory?(@gisdbase) epsg = [:epsg] limits = [:limits] desc = [:desc] raise Error, "An EPSG code is needed to define a new loaction" unless epsg @context.g.proj '-t', epsg: epsg, location: @location permanent = permanent_path if desc desc_file = File.join(permanent, 'MYNAME') File.write desc_file, desc end if limits w, s, e, n = limits res = [:res] # @context.g.mapset mapset: 'PERMANENT', location: @location @context.change_mapset 'PERMANENT' @context.g.region w: w, s: s, e: e, n: n, res: res FileUtils.cp File.join(permanent, 'WIND'), File.join(permanent, 'DEFAULT_WIND') end end |
#exists? ⇒ Boolean
17 18 19 |
# File 'lib/grassgis/location.rb', line 17 def exists? File.directory?(@path) end |
#mapset_path(mapset) ⇒ Object
45 46 47 |
# File 'lib/grassgis/location.rb', line 45 def mapset_path(mapset) File.join(@path, mapset) end |
#permanent_path ⇒ Object
49 50 51 |
# File 'lib/grassgis/location.rb', line 49 def permanent_path mapset_path('PERMANENT') end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/grassgis/location.rb', line 13 def to_s @location end |