root/Shapely/trunk/tests/IterOps.txt

Revision 758 (checked in by seang, 1 year ago)

Add iterator utilities

  • Property svn:eol-style set to native
Line 
1 Test operator iterations
2 ========================
3
4   >>> from shapely.geometry import Polygon
5   >>> from shapely.geometry import Point
6   >>> coords = ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0))
7   >>> polygon = Polygon(coords)
8   >>> points = [Point(0.5, 0.5), Point(2.0, 2.0)]
9  
10   >>> from shapely import iterops
11  
12   List of the points contained by the polygon
13   >>> list(iterops.contains(polygon, points, True)) # doctest: +ELLIPSIS
14   [<shapely.geometry.point.Point object at ...>]
15
16   'True' is the default value
17   >>> list(iterops.contains(polygon, points)) # doctest: +ELLIPSIS
18   [<shapely.geometry.point.Point object at ...>]
19
20   Test a false value
21   >>> list(iterops.contains(polygon, points, False)) # doctest: +ELLIPSIS
22   [<shapely.geometry.point.Point object at ...>]
23
24   If the provided iterator yields tuples, the second value will be yielded
25   >>> list(iterops.contains(polygon, [(p, p.wkt) for p in points], False))
26   ['POINT (2.0000000000000000 2.0000000000000000)']
27
28   Just to demonstrate that the important thing is that the second parameter
29   is an iterator:
30   >>> list(iterops.contains(polygon, iter((p, p.wkt) for p in points)))
31   ['POINT (0.5000000000000000 0.5000000000000000)']
Note: See TracBrowser for help on using the browser.