[GRASS-SVN] r54599 - grass/trunk/lib/python/pygrass/vector
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 11 08:39:19 PST 2013
Author: zarch
Date: 2013-01-11 08:39:18 -0800 (Fri, 11 Jan 2013)
New Revision: 54599
Modified:
grass/trunk/lib/python/pygrass/vector/geometry.py
Log:
Modify __getitem__ method of Attrs class to support multiple values and update the docstring of the Point class and a method to return Cats object of an Area
Modified: grass/trunk/lib/python/pygrass/vector/geometry.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/geometry.py 2013-01-11 16:39:09 UTC (rev 54598)
+++ grass/trunk/lib/python/pygrass/vector/geometry.py 2013-01-11 16:39:18 UTC (rev 54599)
@@ -118,7 +118,7 @@
self.cond = "%s=%d" % (self.table.key, self.line)
self.writable = writable
- def __getitem__(self, key):
+ def __getitem__(self, *args):
"""Return the value stored in the attribute table. ::
>>> attrs = Attrs(v_id, table)
@@ -127,10 +127,12 @@
.."""
#SELECT {cols} FROM {tname} WHERE {condition};
- cur = self.table.execute(sql.SELECT_WHERE.format(cols=key,
+ cols = args if isinstance(args[0], str) else args[0]
+ cur = self.table.execute(sql.SELECT_WHERE.format(cols=','.join(cols),
tname=self.table.name,
condition=self.cond))
- return cur.fetchone()[0]
+ results = cur.fetchone()
+ return results[0] if len(cols) == 1 else results
def __setitem__(self, key, value):
"""Set value of a given column of a table attribute. ::
@@ -216,10 +218,6 @@
libvect.Vect_read_line(self.c_mapinfo, self.c_points,
self.c_cats, self.id)
- def write(self):
- """Write the centroid to the Map."""
- libvect.Vect_write_line(self.c_mapinfo, self.gtype,
- self.c_points, self.c_cats)
class Point(Geo):
@@ -927,12 +925,12 @@
>>> centroid = Centroid(x=0, y=10)
>>> centroid
Centoid(0.000000, 10.000000)
- >>> import pygrass
- >>> mun = pygrass.vector.VectorTopo('boundary_municp_sqlite')
- >>> mun.open()
- >>> centroid = Centroid(v_id=5129, c_mapinfo=mun.c_mapinfo)
+ >>> from grass.pygrass.vector import VectorTopo
+ >>> geo = VectorTopo('geology')
+ >>> geo.open()
+ >>> centroid = Centroid(v_id=1, c_mapinfo=mun.c_mapinfo)
>>> centroid
- Centoid(463784.493822, 311023.913274)
+ Centoid(893202.874416, 297339.312795)
..
"""
@@ -944,8 +942,6 @@
elif self.c_mapinfo and self.area_id and self.id is None:
self.id = self.get_centroid_id()
if self.area_id is not None:
- self.cats = Cats(c_mapinfo=self.c_mapinfo, v_id=self.area_id)
- #TODO: why not pass the self.id?
self.read()
# geometry type
@@ -1211,7 +1207,9 @@
int Vect_get_area_cats (const struct Map_info *Map,
int area, struct line_cats *Cats)
"""
- return Cats(self.c_mapinfo, self.id)
+ cats = Cats()
+ libvect.Vect_get_area_cats(self.c_mapinfo, self.id, cats.c_cats)
+ return cats
def get_first_cat(self):
"""Find FIRST category of given field and area.
More information about the grass-commit
mailing list