|
@@ -1046,7 +1046,7 @@ def del_temp_region():
|
|
|
"""!Unsets WIND_OVERRIDE and removes any region named by it."""
|
|
|
try:
|
|
|
name = os.environ.pop('WIND_OVERRIDE')
|
|
|
- run_command("g.remove", quiet=True, region=name)
|
|
|
+ run_command("g.remove", quiet=True, flags="f", type="region", name=name)
|
|
|
except:
|
|
|
pass
|
|
|
|
|
@@ -1079,108 +1079,14 @@ def find_file(name, element='cell', mapset=None):
|
|
|
mapset=mapset)
|
|
|
return parse_key_val(s)
|
|
|
|
|
|
-# interface to g.list
|
|
|
-
|
|
|
-
|
|
|
-def list_grouped(type, check_search_path=True):
|
|
|
- """!List elements grouped by mapsets.
|
|
|
-
|
|
|
- Returns the output from running g.list, as a dictionary where the
|
|
|
- keys are mapset names and the values are lists of maps in that
|
|
|
- mapset. Example:
|
|
|
-
|
|
|
- @code
|
|
|
- >>> list_grouped('rast')['PERMANENT'] # doctest: +ELLIPSIS
|
|
|
- [..., 'lakes', ..., 'slope', ...
|
|
|
-
|
|
|
- @endcode
|
|
|
-
|
|
|
- @param type element type (rast, vect, rast3d, region, ...)
|
|
|
- @param check_search_path True to add mapsets for the search path with no
|
|
|
- found elements
|
|
|
-
|
|
|
- @return directory of mapsets/elements
|
|
|
- """
|
|
|
- if type == 'raster' or type == 'cell':
|
|
|
- verbose(_('Element type should be "rast" and not "%s"') % type)
|
|
|
- type = 'rast'
|
|
|
- dashes_re = re.compile("^----+$")
|
|
|
- mapset_re = re.compile("<(.*)>")
|
|
|
- result = {}
|
|
|
- if check_search_path:
|
|
|
- for mapset in mapsets(search_path=True):
|
|
|
- result[mapset] = []
|
|
|
-
|
|
|
- mapset = None
|
|
|
- for line in read_command("g.list", type=type).splitlines():
|
|
|
- if line == "":
|
|
|
- continue
|
|
|
- if dashes_re.match(line):
|
|
|
- continue
|
|
|
- m = mapset_re.search(line)
|
|
|
- if m:
|
|
|
- mapset = m.group(1)
|
|
|
- if mapset not in result.keys():
|
|
|
- result[mapset] = []
|
|
|
- continue
|
|
|
- if mapset:
|
|
|
- result[mapset].extend(line.split())
|
|
|
|
|
|
- return result
|
|
|
-
|
|
|
-
|
|
|
-def _concat(xs):
|
|
|
- result = []
|
|
|
- for x in xs:
|
|
|
- result.extend(x)
|
|
|
- return result
|
|
|
-
|
|
|
-
|
|
|
-def list_pairs(type):
|
|
|
- """!List of elements as tuples.
|
|
|
-
|
|
|
- Returns the output from running g.list, as a list of (map, mapset)
|
|
|
- pairs. Example:
|
|
|
-
|
|
|
- @code
|
|
|
- >>> list_pairs('rast') # doctest: +ELLIPSIS
|
|
|
- [..., ('lakes', 'PERMANENT'), ..., ('slope', 'PERMANENT'), ...
|
|
|
-
|
|
|
- @endcode
|
|
|
-
|
|
|
- @param type element type (rast, vect, rast3d, region, ...)
|
|
|
-
|
|
|
- @return list of tuples (map, mapset)
|
|
|
- """
|
|
|
- return _concat([[(map, mapset) for map in maps]
|
|
|
- for mapset, maps in list_grouped(type).iteritems()])
|
|
|
+# interface to g.list
|
|
|
|
|
|
|
|
|
-def list_strings(type):
|
|
|
+def list_strings(type, pattern=None, mapset=None, flag=''):
|
|
|
"""!List of elements as strings.
|
|
|
|
|
|
Returns the output from running g.list, as a list of qualified
|
|
|
- names. Example:
|
|
|
-
|
|
|
- @code
|
|
|
- >>> list_strings('rast') # doctest: +ELLIPSIS
|
|
|
- [..., 'lakes@PERMANENT', ..., 'slope@PERMANENT', ...
|
|
|
-
|
|
|
- @endcode
|
|
|
-
|
|
|
- @param type element type
|
|
|
-
|
|
|
- @return list of strings ('map@@mapset')
|
|
|
- """
|
|
|
- return ["%s@%s" % pair for pair in list_pairs(type)]
|
|
|
-
|
|
|
-# interface to g.mlist
|
|
|
-
|
|
|
-
|
|
|
-def mlist_strings(type, pattern=None, mapset=None, flag=''):
|
|
|
- """!List of elements as strings.
|
|
|
-
|
|
|
- Returns the output from running g.mlist, as a list of qualified
|
|
|
names.
|
|
|
|
|
|
@param type element type (rast, vect, rast3d, region, ...)
|
|
@@ -1195,7 +1101,7 @@ def mlist_strings(type, pattern=None, mapset=None, flag=''):
|
|
|
verbose(_('Element type should be "rast" and not "%s"') % type)
|
|
|
type = 'rast'
|
|
|
result = list()
|
|
|
- for line in read_command("g.mlist",
|
|
|
+ for line in read_command("g.list",
|
|
|
quiet=True,
|
|
|
flags='m' + flag,
|
|
|
type=type,
|
|
@@ -1206,10 +1112,10 @@ def mlist_strings(type, pattern=None, mapset=None, flag=''):
|
|
|
return result
|
|
|
|
|
|
|
|
|
-def mlist_pairs(type, pattern=None, mapset=None, flag=''):
|
|
|
+def list_pairs(type, pattern=None, mapset=None, flag=''):
|
|
|
"""!List of elements as pairs
|
|
|
|
|
|
- Returns the output from running g.mlist, as a list of
|
|
|
+ Returns the output from running g.list, as a list of
|
|
|
(name, mapset) pairs
|
|
|
|
|
|
@param type element type (rast, vect, rast3d, region, ...)
|
|
@@ -1224,10 +1130,10 @@ def mlist_pairs(type, pattern=None, mapset=None, flag=''):
|
|
|
mapset, flag)]
|
|
|
|
|
|
|
|
|
-def mlist_grouped(type, pattern=None, check_search_path=True, flag=''):
|
|
|
+def list_grouped(type, pattern=None, check_search_path=True, flag=''):
|
|
|
"""!List of elements grouped by mapsets.
|
|
|
|
|
|
- Returns the output from running g.mlist, as a dictionary where the
|
|
|
+ Returns the output from running g.list, as a dictionary where the
|
|
|
keys are mapset names and the values are lists of maps in that
|
|
|
mapset. Example:
|
|
|
|
|
@@ -1255,7 +1161,7 @@ def mlist_grouped(type, pattern=None, check_search_path=True, flag=''):
|
|
|
result[mapset] = []
|
|
|
|
|
|
mapset = None
|
|
|
- for line in read_command("g.mlist", quiet=True, flags="m" + flag,
|
|
|
+ for line in read_command("g.list", quiet=True, flags="m" + flag,
|
|
|
type=type, pattern=pattern).splitlines():
|
|
|
try:
|
|
|
name, mapset = line.split('@')
|