-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (50 loc) · 1.92 KB
/
main.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import click
from geopandas import GeoDataFrame
from shapely.geometry import Polygon
from utils import spike_process, spike_utils
@click.command()
@click.argument("filename", type=click.Path(exists=True))
@click.option("--angle", default=1.0, help="""
Maximum angle, in degrees, used to evaluate spikes. Defaults to 1.0º.""")
@click.option("--distance", default=100000.0, help="""
Minimum distance, in meters, used to evaluate spikes. Defaults to 100 000m
""")
@click.option("-o", "--output", required=True, help="""
Name of the output destination file""")
def main(filename: str, angle: float, distance: float, output: str):
"""
A python command-line tool used to remove spikes from polygons stored in
Geopackage format.
"""
data = spike_utils.load_geopackage(filename)
if not spike_utils.validate_crs(data):
raise (
"""
The input file doesn't have a valid coordinate seference
system or it does not have a
geographic coordinate seference system.
"""
)
geod = spike_utils.extract_crs_geod(data)
processor = spike_process.GeometryProcessor(angle, distance)
results = []
for entry in data.itertuples():
geometry = entry.geometry
exterior = processor.process_sequence(geod, geometry.exterior.coords)
interiors = []
for interior_ring in geometry.interiors:
processed_interior_ring = processor.process_sequence(
geod,
interior_ring.coords,
)
interiors.append(processed_interior_ring)
results.append((entry.name, Polygon(exterior, interiors)))
cleaned_data = GeoDataFrame(
results,
columns=["name", "geometry"],
crs=data.crs
)
spike_utils.save_geopackage(output, cleaned_data)
if __name__ == '__main__':
"""""The main entery where the application is run from"""
main()