Class: GrassGis::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/grassgis/location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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

Raises:


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!(options = {})
  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 = options[:epsg]
  limits = options[:limits]
  desc = options[: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 = options[: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

Returns:

  • (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_pathObject


49
50
51
# File 'lib/grassgis/location.rb', line 49

def permanent_path
  mapset_path('PERMANENT')
end

#to_sObject


13
14
15
# File 'lib/grassgis/location.rb', line 13

def to_s
  @location
end