[GRASS-SVN] r54940 - grass/trunk/lib/python/pygrass/vector

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 5 09:37:52 PST 2013


Author: zarch
Date: 2013-02-05 09:37:51 -0800 (Tue, 05 Feb 2013)
New Revision: 54940

Modified:
   grass/trunk/lib/python/pygrass/vector/geometry.py
Log:
Add intersaction and fix some docstring

Modified: grass/trunk/lib/python/pygrass/vector/geometry.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/geometry.py	2013-02-05 17:29:28 UTC (rev 54939)
+++ grass/trunk/lib/python/pygrass/vector/geometry.py	2013-02-05 17:37:51 UTC (rev 54940)
@@ -71,6 +71,21 @@
     pass
 
 
+def intersects(lineA, lineB, with_z=False):
+    """Return a list of points ::
+
+        >>> lineA = Line([(0, 0), (4, 0)])
+        >>> lineB = Line([(2, 2), (2, -2)])
+        >>> intersects(lineA, lineB)
+        Line([Point(2.000000, 0.000000)])
+    """
+    line = Line()
+    if libvect.Vect_line_get_intersections(lineA.c_points, lineB.c_points,
+                                           line.c_points, int(with_z)):
+        return line
+    else:
+        return []
+
 #=============================================
 # GEOMETRY
 #=============================================
@@ -121,11 +136,16 @@
     def __getitem__(self, *args):
         """Return the value stored in the attribute table. ::
 
-            >>> attrs = Attrs(v_id, table)
-            >>> attrs['LABEL']
-            .
+            >>> from grass.pygrass.vector import VectorTopo
+            >>> schools = VectorTopo('schools')
+            >>> schools.open('r')
+            >>> school = schools[1]
+            >>> attrs = Attrs(school.line, schools.table)
+            >>> attrs['TAG']
+            u'568'
 
-        .."""
+
+        """
         #SELECT {cols} FROM {tname} WHERE {condition};
         cols = args if isinstance(args[0], str) else args[0]
         cur = self.table.execute(sql.SELECT_WHERE.format(cols=','.join(cols),
@@ -137,10 +157,17 @@
     def __setitem__(self, key, value):
         """Set value of a given column of a table attribute. ::
 
-            >>> attrs = Attrs(v_id, table)
-            >>> attrs['LABEL'] = 'New Label'
-
-        .."""
+            >>> from grass.pygrass.vector import VectorTopo
+            >>> from grass.pygrass.functions import copy
+            >>> copy('schools', 'schools', 'vect')
+            >>> schools = VectorTopo('schools')
+            >>> schools.open('r')
+            >>> school = schools[1]
+            >>> attrs = Attrs(school.line, schools.table)
+            >>> attrs['TAG'] = 'New Label'
+            >>> attrs['TAG']
+            'New Label'
+        """
         if self.writable:
             #UPDATE {tname} SET {new_col} = {old_col} WHERE {condition}
             values = '%s=%r' % (key, value)
@@ -185,10 +212,12 @@
     >>> geo1 = Geo(c_points=points, c_cats=cats)
     """
     def __init__(self, v_id=None, c_mapinfo=None, c_points=None, c_cats=None,
-                 table=None, writable=False):
+                 table=None, writable=False, is2D=True):
         self.id = v_id  # vector id
         self.line = self.id
         self.c_mapinfo = c_mapinfo
+        self.is2D = is2D
+        self.gtype = None
 
         # set c_points
         if c_points is None:
@@ -220,7 +249,6 @@
                                self.c_cats, self.id)
 
 
-
 class Point(Geo):
     """Instantiate a Point object that could be 2 or 3D, default
     parameters are 0.
@@ -247,11 +275,10 @@
 
     ..
     """
-    def __init__(self, x=0, y=0, z=None, is2D=True, **kargs):
+    def __init__(self, x=0, y=0, z=None, **kargs):
         super(Point, self).__init__(**kargs)
         if self.id is not None:
             self.read()
-            self.is2D = is2D
         else:
             self.is2D = True if z is None else False
             z = z if z is not None else 0
@@ -441,13 +468,12 @@
 
     ..
     """
-    def __init__(self, points=None, is2D=True, **kargs):
+    def __init__(self, points=None, **kargs):
         super(Line, self).__init__(**kargs)
         if points is not None:
             for pnt in points:
                 self.append(pnt)
 
-        self.is2D = is2D
         # geometry type
         self.gtype = libvect.GV_LINE
 
@@ -967,7 +993,6 @@
 class Node(object):
     pass
 
-
 class Boundary(Line):
     """
     """



More information about the grass-commit mailing list