root/Shapely/trunk/examples/geoms.py

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

Update readme with link to the manual, fix undefined variables in example

  • Property svn:eol-style set to native
Line 
1 from numpy import asarray
2 import pylab
3 from shapely.geometry import Point, LineString, Polygon
4
5 polygon = Polygon(((-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0), (1.0, -1.0)))
6
7 point_r = Point(-1.5, 1.2)
8 point_g = Point(-1.0, 1.0)
9 point_b = Point(-0.5, 0.5)
10
11 line_r = LineString(((-0.5, 0.5), (0.5, 0.5)))
12 line_g = LineString(((1.0, -1.0), (1.8, 0.5)))
13 line_b = LineString(((-1.8, -1.2), (1.8, 0.5)))
14
15 def plot_point(g, o, l):
16     pylab.plot([g.x], [g.y], o, label=l)
17
18 def plot_line(g, o):
19     a = asarray(g)
20     pylab.plot(a[:,0], a[:,1], o)
21
22 def fill_polygon(g, o):
23     a = asarray(g.exterior)
24     pylab.fill(a[:,0], a[:,1], o, alpha=0.5)
25
26 def fill_multipolygon(g, o):
27     for g in g.geoms:
28         fill_polygon(g, o)
29
30 if __name__ == "__main__":
31     from numpy import asarray
32     import pylab
33    
34     fig = pylab.figure(1, figsize=(4, 3), dpi=150)
35     #pylab.axis([-2.0, 2.0, -1.5, 1.5])
36     pylab.axis('tight')
37
38     a = asarray(polygon.exterior)
39     pylab.fill(a[:,0], a[:,1], 'c')
40
41     plot_point(point_r, 'ro', 'b')
42     plot_point(point_g, 'go', 'c')
43     plot_point(point_b, 'bo', 'd')
44
45     plot_line(line_r, 'r')
46     plot_line(line_g, 'g')
47     plot_line(line_b, 'b')
48
49     pylab.show()
50
51
Note: See TracBrowser for help on using the browser.