-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotpoly.py
27 lines (24 loc) · 1004 Bytes
/
plotpoly.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from matplotlib import pyplot
from matplotlib.path import Path
from matplotlib.patches import PathPatch
from numpy import asarray, concatenate, ones
from shapely.geometry import *
def ring_coding(ob):
# The codes will be all "LINETO" commands, except for "MOVETO"s at the
# beginning of each subpath
n = len(ob.coords)
codes = ones(n, dtype=Path.code_type) * Path.LINETO
codes[0] = Path.MOVETO
return codes
def pathify(polygon):
# Convert coordinates to path vertices. Objects produced by Shapely's
# analytic methods have the proper coordinate order, no need to sort.
vertices = concatenate(
[asarray(polygon.exterior)]
+ [asarray(r) for r in polygon.interiors])
codes = concatenate(
[ring_coding(polygon.exterior)]
+ [ring_coding(r) for r in polygon.interiors])
return Path(vertices, codes)
#path = pathify(polygon)
#patch = PathPatch(path, facecolor='#cccccc', edgecolor='#999999')