[GRASS-SVN] r56893 - in grass/trunk/lib/python/pygrass: gis vector
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jun 23 13:00:43 PDT 2013
Author: zarch
Date: 2013-06-23 13:00:42 -0700 (Sun, 23 Jun 2013)
New Revision: 56893
Modified:
grass/trunk/lib/python/pygrass/gis/region.py
grass/trunk/lib/python/pygrass/vector/basic.py
Log:
Add '_repr_html_' to Region class and Bbox
Modified: grass/trunk/lib/python/pygrass/gis/region.py
===================================================================
--- grass/trunk/lib/python/pygrass/gis/region.py 2013-06-23 19:51:12 UTC (rev 56892)
+++ grass/trunk/lib/python/pygrass/gis/region.py 2013-06-23 20:00:42 UTC (rev 56893)
@@ -9,6 +9,7 @@
import grass.script as grass
from grass.pygrass.errors import GrassError
+from grass.pygrass.shell.conversion import dict2html
class Region(object):
@@ -168,7 +169,7 @@
@property
def zone(self):
"""Return the zone of projection
-
+
>>> reg = Region()
>>> reg.zone
0
@@ -178,19 +179,28 @@
@property
def proj(self):
"""Return a code for projection
-
+
>>> reg = Region()
>>> reg.proj
99
- """
+ """
return self.c_region.contents.proj
+ @property
+ def cells(self):
+ """Return the number of cells"""
+ return self.rows * self.cols
+
#----------MAGIC METHODS----------
def __repr__(self):
return 'Region(n=%g, s=%g, e=%g, w=%g, nsres=%g, ewres=%g)' % (
self.north, self.south, self.east, self.west,
self.nsres, self.ewres)
+ def _repr_html_(self):
+ return dict2html(dict(self.items()), keys=self.keys(),
+ border='1', kdec='b')
+
def __unicode__(self):
return grass.pipe_command("g.region", flags="p").communicate()[0]
@@ -205,22 +215,14 @@
return False
return True
- def iteritems(self):
- return [('projection', self.proj),
- ('zone', self.zone),
- ('north', self.north),
- ('south', self.south),
- ('west', self.west),
- ('east', self.east),
- ('top', self.top),
- ('bottom', self.bottom),
- ('nsres', self.nsres),
- ('ewres', self.ewres),
- ('tbres', self.tbres),
- ('rows', self.rows),
- ('cols', self.cols),
- ('cells', self.rows * self.cols)]
+ def keys(self):
+ return ['proj', 'zone', 'north', 'south', 'west', 'east',
+ 'top', 'bottom', 'nsres', 'ewres', 'tbres', 'rows',
+ 'cols', 'cells']
+ def items(self):
+ return [(k, self.__getattribute__(k)) for k in self.keys()]
+
#----------METHODS----------
def zoom(self, raster_name):
"""Shrink region until it meets non-NULL data from this raster map:"""
Modified: grass/trunk/lib/python/pygrass/vector/basic.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/basic.py 2013-06-23 19:51:12 UTC (rev 56892)
+++ grass/trunk/lib/python/pygrass/vector/basic.py 2013-06-23 20:00:42 UTC (rev 56893)
@@ -8,7 +8,9 @@
import grass.lib.vector as libvect
from collections import Iterable
+from grass.pygrass.shell.conversion import dict2html
+
class Bbox(object):
"""Instantiate a Bounding Box class that contains
a ctypes pointer to the C struct bound_box, that could be used
@@ -109,6 +111,13 @@
return "Bbox({n}, {s}, {e}, {w})".format(n=self.north, s=self.south,
e=self.east, w=self.west)
+ def _repr_html_(self):
+ return dict2html(dict(self.items()), keys=self.keys(),
+ border='1', kdec='b')
+
+ def keys(self):
+ return ['north', 'south', 'west', 'east', 'top', 'bottom']
+
def contains(self, point):
"""Return True if the object is contained by the BoundingBox. ::
@@ -125,17 +134,15 @@
self.c_bbox))
def items(self):
- return [('north', self.north), ('south', self.south),
- ('east', self.east), ('west', self.west),
- ('top', self.top), ('bottom', self.bottom)]
+ return [(k, self.__getattribute__(k)) for k in self.keys()]
- def nsewtb(self, is3d=False):
+ def nsewtb(self, tb=True):
"""Return a list
- If is3d parameter is False return only:
+ If tb parameter is False return only:
north, south, east, west
"""
- if is3d:
+ if tb:
return (self.north, self.south, self.east, self.west,
self.top, self.bottom)
else:
More information about the grass-commit
mailing list