~qeef/damn-client.py

ref: c8312dc6d79098d1dcb773585a1c0f77ca66a67e damn-client.py/intersecting_areas.py -rwxr-xr-x 1.4 KiB
c8312dc6Jiri Vlasak Add osm static maps generator script 4 months ago
                                                                                
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
#!/usr/bin/env python3
"""This script checks the intersecting areas.

Use the list of the damn servers URIs, separated by commas, as the first and
only argument.
"""
import sys
from shapely.geometry import shape
from shapely.ops import unary_union
from damn_client.api import DamnAPI

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print(__doc__)
        sys.exit(1)
    servers = {}
    for uri in sys.argv[1].split(","):
        servers[uri] = DamnAPI(uri)
    assert len(servers) > 0
    for uri, s in servers.items():
        s.get_geometries()
        for a in s.areas.values():
            a["shape"] = []
            for f in a["featurecollection"]["features"]:
                a["shape"].append(shape(f["geometry"]))
            a["shape"] = unary_union(a["shape"])
    for test_uri, test_s in servers.items():
        print("testing {}:".format(test_uri))
        for test_area in test_s.areas.values():
            test_aid = test_area["aid"]
            test_shape = test_area["shape"]
            for uri, s in servers.items():
                for a in s.areas.values():
                    if (
                        test_aid != a["aid"]
                        and test_shape.intersects(a["shape"])
                    ):
                        print("- {} intersects with {} of {}".format(
                            test_aid,
                            a["aid"],
                            uri,
                        ))