[GRASS-dev] wxGUI data catalog
Pietro
peter.zamb at gmail.com
Tue May 6 01:47:25 PDT 2014
Hi Martin,
On Thu, May 1, 2014 at 7:18 PM, Martin Landa <landa.martin at gmail.com> wrote:
> Later could be added support for copying maps between
> different locations (including automated reprojection)
I would love to have this functionality somewhere on the python
library, maybe we could add a "copy" method to the Location class, see
more below.
> pyGRASS:
>
> cur_mapset = str(Mapset())
> Mapset(dst_mapset).current()
> g.copy(rast = '%s@%s,%s' % (src_map, src_mapset, dst_name)) # *
> Mapset(cur_mapset).current()
>
> * this could be replaced by something more fancy by modifying pyGRASS
Perhaps I could add a new method "copy" to Mapset If could be useful
to someone, something like:
{{{
def copy(self, data_type, data_name, dst_mapset, dst_name=''):
"""Copies available data files in the current mapset search path
to the user's current mapset.
Parameters
----------
data_type : string
String with the data type that must be copied ('rast', rast3d',
'vect', 'oldvect', 'asciivect', 'icon', 'labels', 'sites',
'region', 'region3d', 'group', 'view3d').
data_name : string
Name of the data that you want to copy.
dst_mapset : string
Name of the destination mapset.
dst_name : string, optional
Name of the copy.
"""
from grass.pygrass.modules.shortcuts import general as g
# set the destination mapset as current
Mapset(dst_mapset).current()
# copy the data from origin to destination
g.copy(**{data_type: '%s@%s,%s' % (data_name, self.name,
dst_name if dst_name else data_name)})
# set the origin as current
self.current()
}}}
In this way you should be able to do the same operation with:
{{{
Mapset().copy('rast', src_map, dst_mapset, dst_name)
}}}
and should be possible to implement something similar for the location.
{{{
Location().copy(data_type, data_name, src_mapset, dst_location,
dst_mapset, dst_name)
}}}
> Personally I incline to promote pyGRASS as interface for user scripts,
> but in wxGUI I still prefer to use GRASS Scripting Library to call
> GRASS commands on the background.
+1, or using pygrass through Soeren's RPC interface.
Pietro
More information about the grass-dev
mailing list