-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_duplicates.py
More file actions
34 lines (25 loc) · 900 Bytes
/
Copy pathremove_duplicates.py
File metadata and controls
34 lines (25 loc) · 900 Bytes
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
29
30
31
32
33
34
""" remove Duplicates
Remove all duplicate vertices from a shapely (MultiPolygon)
author: Ignace Pelckmans
(University of Antwerp, Belgium)
"""
import numpy as np
from shapely.geometry import MultiPolygon, Polygon
def removeDuplicates(mpol):
"""
Function to remove duplicate vertices from a shapely (Multi)Polygon
Args:
mpol: (Required) shapely (Multi)Polygon
Returns:
Numpy array with dimensions (n x 2) representing x- and y-coordinates of the polygon's vertices without the excessive points
"""
# check if it is a Polygon or a MultiPolygon
if type(mpol) == Polygon:
mpol = MultiPolygon([mpol])
mpol = mpol.simplify(0)
# if the input was a Polygon, return a Polgyon
if type(mpol) == Polygon:
return pols[0]
# if the input was a MultiPolygon, return a MultiPolygon
else:
return MultiPolygon(pols)