File: make_valid_geometrycollection.py

package info (click to toggle)
python-shapely 2.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,564 kB
  • sloc: python: 18,650; ansic: 6,615; makefile: 88; sh: 62
file content (28 lines) | stat: -rw-r--r-- 740 bytes parent folder | download | duplicates (3)
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
28
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
from shapely.validation import make_valid
from shapely.plotting import plot_polygon, plot_line

from figures import SIZE, BLUE, RED, set_limits


invalid_poly = Polygon([(0, 2), (0, 1), (2, 0), (0, 0), (0, 2)])
valid_poly = make_valid(invalid_poly)

fig = plt.figure(1, figsize=SIZE, dpi=90)

invalid_ax = fig.add_subplot(121)

plot_polygon(invalid_poly, ax=invalid_ax, add_points=False, color=BLUE)

set_limits(invalid_ax, -1, 3, -1, 3)


valid_ax = fig.add_subplot(122)

plot_polygon(valid_poly.geoms[0], ax=valid_ax, add_points=False, color=BLUE)
plot_line(valid_poly.geoms[1], ax=valid_ax, add_points=False, color=RED)

set_limits(valid_ax, -1, 3, -1, 3)

plt.show()