I took this as reference, Moving raster to different mapset GRASS GIS, and I use pyscripter to use GRASS module g.copy from outside,
import os
import sys
#set up GRASS environment variables
sys.path.append(os.path.join(os.environ['GISBASE'], 'etc', 'python'))
import grass.script as g
import grass.script.setup as gsetup
gisbase = os.environ['GISBASE']
gisdb = 'C:\Users\Heinz\Documents\grassdata'
location = 'newLocation'
mapset = 'watershed_analysis'
gsetup.init(gisbase, gisdb, location, mapset)
#copy raster data
g.run_command('g.copy', rast = 'hc@TC, hc')
#check result
print g.read_command('g.list', _type = 'rast')
The output is raster files in mapset PERMANENT, thus not what I want. (current mapset is watershed_analysis)
*** Remote Interpreter Reinitialized ***
>>>
----------------------------------------------
raster files available in mapset <PERMANENT>:
hc
----------------------------------------------
Seems I don't successfully copy the raster file to the mapset I want.
How to fix this problem? I am using GRASS 6.4.3, python 2.7.6 under Windows 8.1 x64.
Update#1 @gene, I do the same thing in the python shell of the GRASS layer manager,
Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>import grass.script as g
>>>g.run_command('g.copy', rast = 'acc@TC, acc@watershed_analysis')
0
>>>g.read_command('g.list', _type = 'rast')
----------------------------------------------
raster files available in mapset <PERMANENT>:
hc
----------------------------------------------
g.read_command('g.mlist', _type = 'rast')
hc
In the output above, I want to copy the file acc from mapset TC to current mapset watershed_analysis, but the output still tells me about another mapset. (g.list and g.mlist outputs the same except the later one wouldn't tell me the info of mapset.)
And I go to check results in the file of this mapset, there are no new file copied to it. Maybe there are problems in my script.
Update#2 If I tried the module in GRASS GUI, here's result,
No output but the error message,
Traceback (most recent call last):
File "C:\OSGeo4W\apps\grass\grass-6.4.3\etc\wxpython\gui_c
ore\forms.py", line 655, in OnRun
self.goutput.RunCmd(cmd, onDone = self.OnDone)
File "C:\OSGeo4W\apps\grass\grass-6.4.3\etc\wxpython\gui_c
ore\goutput.py", line 554, in RunCmd
task = GUI(show = None).ParseCommand(command)
File "C:\OSGeo4W\apps\grass\grass-6.4.3\etc\wxpython\gui_c
ore\forms.py", line 1871, in ParseCommand
blackList = _blackList)
File "C:\OSGeo4W\apps\grass\grass-6.4.3\etc\python\grass\s
cript\task.py", line 470, in parse_interface
tree = etree.fromstring(get_interface_description(name))
File
"C:\OSGeo4W\apps\Python27\lib\xml\etree\ElementTree.py",
line 1300, in XML
parser.feed(text)
File
"C:\OSGeo4W\apps\Python27\lib\xml\etree\ElementTree.py",
line 1642, in feed
self._raiseerror(v)
File
"C:\OSGeo4W\apps\Python27\lib\xml\etree\ElementTree.py",
line 1506, in _raiseerror
raise err
xml.etree.ElementTree
.
ParseError
:
unknown encoding: line 1, column 30
I don't know if I did something wrong in inputs.