[GRASS-SVN] r53978 - in grass/trunk/lib/python/pygrass: . raster vector
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Nov 23 04:03:32 PST 2012
Author: lucadelu
Date: 2012-11-23 04:03:32 -0800 (Fri, 23 Nov 2012)
New Revision: 53978
Added:
grass/trunk/lib/python/pygrass/functions.py
Removed:
grass/trunk/lib/python/pygrass/env.py
Modified:
grass/trunk/lib/python/pygrass/__init__.py
grass/trunk/lib/python/pygrass/raster/__init__.py
grass/trunk/lib/python/pygrass/raster/abstract.py
grass/trunk/lib/python/pygrass/vector/abstract.py
Log:
rename env.py to functions.py
Modified: grass/trunk/lib/python/pygrass/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/__init__.py 2012-11-23 11:52:49 UTC (rev 53977)
+++ grass/trunk/lib/python/pygrass/__init__.py 2012-11-23 12:03:32 UTC (rev 53978)
@@ -9,13 +9,13 @@
import os as _os
import sys as _sys
-_pygrasspath = _os.path.dirname(_os.path.realpath( __file__ )).split(_os.sep)
+_pygrasspath = _os.path.dirname(_os.path.realpath(__file__)).split(_os.sep)
-_sys.path.append(_os.path.join(_os.sep,*_pygrasspath[:-1]))
+_sys.path.append(_os.path.join(_os.sep, *_pygrasspath[:-1]))
import region
import raster
import vector
import modules
import errors
-import env
\ No newline at end of file
+import functions
\ No newline at end of file
Deleted: grass/trunk/lib/python/pygrass/env.py
===================================================================
--- grass/trunk/lib/python/pygrass/env.py 2012-11-23 11:52:49 UTC (rev 53977)
+++ grass/trunk/lib/python/pygrass/env.py 2012-11-23 12:03:32 UTC (rev 53978)
@@ -1,95 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Created on Tue Jun 26 12:38:48 2012
-
- at author: pietro
-"""
-
-import fnmatch
-
-import grass.lib.gis as libgis
-import grass.lib.raster as libraster
-from grass.script import core as grasscore
-
-
-def looking(filter_string, obj):
- """
- >>> import grass.lib.vector as libvect
- >>> sorted(looking('*by_box*', libvect)) # doctest: +NORMALIZE_WHITESPACE
- ['Vect_select_areas_by_box', 'Vect_select_isles_by_box',
- 'Vect_select_lines_by_box', 'Vect_select_nodes_by_box']
-
- """
- word_list = [i for i in dir(obj)]
- word_list.sort()
- return fnmatch.filter(word_list, filter_string)
-
-
-def remove(**kargs):
- grasscore.run_command('g.remove', **kargs)
-
-
-def rename(oldname, newname, maptype):
- grasscore.run_command('g.rename',
- **{maptype: '{old},{new}'.format(old=oldname,
- new=newname), })
-
-
-def copy(existingmap, newmap, maptype):
- grasscore.run_command('g.copy',
- **{maptype: '{old},{new}'.format(old=existingmap,
- new=newmap), })
-
-
-def get_mapset_raster(mapname, mapset=''):
- return libgis.G_find_raster(mapname, '')
-
-
-def get_mapset_vector(mapname, mapset=''):
- return libgis.G_find_vector(mapname, '')
-
-
-def exist(mapname, mapset=''):
- mapset = get_mapset_raster(mapname, mapset)
- if mapset != '':
- return True
- else:
- mapset = get_mapset_vector(mapname, mapset)
- if mapset:
- return True
- return False
-
-
-def clean_map_name(name):
- name.strip()
- for char in ' @#^?°,;%&/':
- name = name.replace(char, '')
- return name
-
-
-def coor2pixel((east, north), region):
- """Convert coordinates into a pixel row and col ::
-
- >>> from pygrass.region import Region
- >>> reg = Region()
- >>> coor2pixel((reg.west, reg.north), reg)
- (0.0, 0.0)
- >>> coor2pixel((reg.east, reg.south), reg) == (reg.cols, reg.rows)
- True
- """
- return (libraster.Rast_northing_to_row(north, region.c_region),
- libraster.Rast_easting_to_col(east, region.c_region))
-
-
-def pixel2coor((col, row), region):
- """Convert row and col of a pixel into a coordinates ::
-
- >>> from pygrass.region import Region
- >>> reg = Region()
- >>> pixel2coor((0, 0), reg) == (reg.north, reg.west)
- True
- >>> pixel2coor((reg.cols, reg.rows), reg) == (reg.east, reg.south)
- True
- """
- return (libraster.Rast_row_to_northing(row, region.c_region),
- libraster.Rast_col_to_easting(col, region.c_region))
\ No newline at end of file
Copied: grass/trunk/lib/python/pygrass/functions.py (from rev 53975, grass/trunk/lib/python/pygrass/env.py)
===================================================================
--- grass/trunk/lib/python/pygrass/functions.py (rev 0)
+++ grass/trunk/lib/python/pygrass/functions.py 2012-11-23 12:03:32 UTC (rev 53978)
@@ -0,0 +1,95 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Tue Jun 26 12:38:48 2012
+
+ at author: pietro
+"""
+
+import fnmatch
+
+import grass.lib.gis as libgis
+import grass.lib.raster as libraster
+from grass.script import core as grasscore
+
+
+def looking(filter_string, obj):
+ """
+ >>> import grass.lib.vector as libvect
+ >>> sorted(looking('*by_box*', libvect)) # doctest: +NORMALIZE_WHITESPACE
+ ['Vect_select_areas_by_box', 'Vect_select_isles_by_box',
+ 'Vect_select_lines_by_box', 'Vect_select_nodes_by_box']
+
+ """
+ word_list = [i for i in dir(obj)]
+ word_list.sort()
+ return fnmatch.filter(word_list, filter_string)
+
+
+def remove(**kargs):
+ grasscore.run_command('g.remove', **kargs)
+
+
+def rename(oldname, newname, maptype):
+ grasscore.run_command('g.rename',
+ **{maptype: '{old},{new}'.format(old=oldname,
+ new=newname), })
+
+
+def copy(existingmap, newmap, maptype):
+ grasscore.run_command('g.copy',
+ **{maptype: '{old},{new}'.format(old=existingmap,
+ new=newmap), })
+
+
+def get_mapset_raster(mapname, mapset=''):
+ return libgis.G_find_raster(mapname, '')
+
+
+def get_mapset_vector(mapname, mapset=''):
+ return libgis.G_find_vector(mapname, '')
+
+
+def exist(mapname, mapset=''):
+ mapset = get_mapset_raster(mapname, mapset)
+ if mapset != '':
+ return True
+ else:
+ mapset = get_mapset_vector(mapname, mapset)
+ if mapset:
+ return True
+ return False
+
+
+def clean_map_name(name):
+ name.strip()
+ for char in ' @#^?°,;%&/':
+ name = name.replace(char, '')
+ return name
+
+
+def coor2pixel((east, north), region):
+ """Convert coordinates into a pixel row and col ::
+
+ >>> from pygrass.region import Region
+ >>> reg = Region()
+ >>> coor2pixel((reg.west, reg.north), reg)
+ (0.0, 0.0)
+ >>> coor2pixel((reg.east, reg.south), reg) == (reg.cols, reg.rows)
+ True
+ """
+ return (libraster.Rast_northing_to_row(north, region.c_region),
+ libraster.Rast_easting_to_col(east, region.c_region))
+
+
+def pixel2coor((col, row), region):
+ """Convert row and col of a pixel into a coordinates ::
+
+ >>> from pygrass.region import Region
+ >>> reg = Region()
+ >>> pixel2coor((0, 0), reg) == (reg.north, reg.west)
+ True
+ >>> pixel2coor((reg.cols, reg.rows), reg) == (reg.east, reg.south)
+ True
+ """
+ return (libraster.Rast_row_to_northing(row, region.c_region),
+ libraster.Rast_col_to_easting(col, region.c_region))
\ No newline at end of file
Modified: grass/trunk/lib/python/pygrass/raster/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/__init__.py 2012-11-23 11:52:49 UTC (rev 53977)
+++ grass/trunk/lib/python/pygrass/raster/__init__.py 2012-11-23 12:03:32 UTC (rev 53978)
@@ -24,7 +24,7 @@
#
from pygrass.errors import OpenError, must_be_open
from pygrass.region import Region
-import pygrass.env as env
+from pygrass import functions
#
# import raster classes
@@ -661,7 +661,7 @@
"""
if not region:
region = Region()
- x, y = env.coor2pixel(point.coords(), region)
+ x, y = functions.coor2pixel(point.coords(), region)
return self[x][y]
Modified: grass/trunk/lib/python/pygrass/raster/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/abstract.py 2012-11-23 11:52:49 UTC (rev 53977)
+++ grass/trunk/lib/python/pygrass/raster/abstract.py 2012-11-23 12:03:32 UTC (rev 53978)
@@ -21,7 +21,7 @@
#
# import pygrass modules
#
-import pygrass.env as env
+import pygrass as functions
from pygrass.region import Region
from pygrass.errors import must_be_open
@@ -122,7 +122,7 @@
def _set_name(self, newname):
"""Private method to change the Raster name"""
#import pdb; pdb.set_trace()
- cleanname = env.clean_map_name(newname)
+ cleanname = functions.clean_map_name(newname)
if self.exist():
self.rename(cleanname)
self._name = cleanname
@@ -212,7 +212,7 @@
call the C function `G_find_raster`."""
if self.name:
- self.mapset = env.get_mapset_raster(self.name, self.mapset)
+ self.mapset = functions.get_mapset_raster(self.name, self.mapset)
else:
return False
if self.mapset:
@@ -258,7 +258,7 @@
def rename(self, newname):
"""Rename the map"""
if self.exist():
- env.rename(self.name, newname, 'rast')
+ functions.rename(self.name, newname, 'rast')
self._name = newname
def set_from_rast(self, rastname='', mapset=''):
@@ -292,7 +292,7 @@
"""
if not region:
region = Region()
- x, y = env.coor2pixel(point.coords(), region)
+ x, y = functions.coor2pixel(point.coords(), region)
line = self.get_row(int(x))
return line[int(y)]
Modified: grass/trunk/lib/python/pygrass/vector/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/abstract.py 2012-11-23 11:52:49 UTC (rev 53977)
+++ grass/trunk/lib/python/pygrass/vector/abstract.py 2012-11-23 12:03:32 UTC (rev 53978)
@@ -9,16 +9,15 @@
import grass.lib.vector as libvect
from vector_type import MAPTYPE
-import pygrass.env as env
+from pygrass import functions
from pygrass.errors import GrassError, OpenError, must_be_open
from table import DBlinks
-
-
#=============================================
# VECTOR ABSTRACT CLASS
#=============================================
+
class Info(object):
"""Basic vector info.
To get access to the vector info the map must be opened. ::
@@ -201,7 +200,7 @@
def rename(self, newname):
"""Rename the map"""
if self.exist():
- env.rename(self.name, newname, 'vect')
+ functions.rename(self.name, newname, 'vect')
self._name = newname
def is_3D(self):
@@ -209,7 +208,7 @@
def exist(self):
if self._name:
- self.mapset = env.get_mapset_vector(self._name, self.mapset)
+ self.mapset = functions.get_mapset_vector(self._name, self.mapset)
else:
return False
if self.mapset:
@@ -271,7 +270,7 @@
"""Remove vector map"""
if self.is_open():
self.close()
- env.remove(vect=self.name)
+ functions.remove(vect=self.name)
def build(self):
"""Close the vector map and build vector Topology"""
More information about the grass-commit
mailing list