How to use the traffic.core.airspace.ExtrudedPolygon function in traffic

To help you get started, we’ve selected a few traffic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xoolive / traffic / traffic / data / eurocontrol / ddr / airspaces.py View on Github external
def read_sls(self, filename: Path) -> None:
        logging.info(f"Reading SLS file {filename}")
        with filename.open("r") as fh:
            for line in fh.readlines():
                name, _, polygon, lower, upper = line.split()
                self.elements[name].append(
                    Airspace(
                        name,
                        [
                            ExtrudedPolygon(
                                self.polygons[polygon],
                                float(lower),
                                float(upper),
                            )
github xoolive / traffic / traffic / core / airspace.py View on Github external
def cascaded_union_with_alt(polyalt: AirspaceList) -> AirspaceList:
    altitudes = set(alt for _, *low_up in polyalt for alt in low_up)
    slices = sorted(altitudes)
    if len(slices) == 1 and slices[0] is None:
        simple_union = cascaded_union([p for p, *_ in polyalt])
        return [ExtrudedPolygon(simple_union, float("-inf"), float("inf"))]
    results: List[ExtrudedPolygon] = []
    for low, up in zip(slices, slices[1:]):
        matched_poly = [
            p
            for (p, low_, up_) in polyalt
            if low_ <= low <= up_ and low_ <= up <= up_
        ]
        new_poly = ExtrudedPolygon(cascaded_union(matched_poly), low, up)
        if len(results) > 0 and new_poly.polygon.equals(results[-1].polygon):
            merged = ExtrudedPolygon(new_poly.polygon, results[-1].lower, up)
            results[-1] = merged
        else:
            results.append(new_poly)
    return results
github xoolive / traffic / traffic / core / airspace.py View on Github external
def cascaded_union_with_alt(polyalt: AirspaceList) -> AirspaceList:
    altitudes = set(alt for _, *low_up in polyalt for alt in low_up)
    slices = sorted(altitudes)
    if len(slices) == 1 and slices[0] is None:
        simple_union = cascaded_union([p for p, *_ in polyalt])
        return [ExtrudedPolygon(simple_union, float("-inf"), float("inf"))]
    results: List[ExtrudedPolygon] = []
    for low, up in zip(slices, slices[1:]):
        matched_poly = [
            p
            for (p, low_, up_) in polyalt
            if low_ <= low <= up_ and low_ <= up <= up_
        ]
        new_poly = ExtrudedPolygon(cascaded_union(matched_poly), low, up)
        if len(results) > 0 and new_poly.polygon.equals(results[-1].polygon):
            merged = ExtrudedPolygon(new_poly.polygon, results[-1].lower, up)
            results[-1] = merged
        else:
            results.append(new_poly)
    return results
github xoolive / traffic / traffic / data / airspaces / eurofirs.py View on Github external
import json
from pathlib import Path

from shapely.geometry import shape

from ...core.airspace import Airspace, ExtrudedPolygon

with Path(__file__).absolute().with_name("eurofirs.json").open("r") as fh:
    fir = json.load(fh)

eurofirs = {
    elt["properties"]["IDENT"]: Airspace(
        name=elt["properties"]["NAME"][:-4],  # Remove " FIR" at the end
        elements=[
            ExtrudedPolygon(
                shape(elt["geometry"]),
                int(elt["properties"]["LOWERLIMIT"]),
                int(elt["properties"]["UPPERLIMIT"]),
            )
        ],
        type_=elt["properties"]["TYPE"],
        designator=elt["properties"]["IDENT"],
        properties=elt["properties"],
    )
    for elt in fir["features"]
}
github xoolive / traffic / traffic / data / airspaces / eurocontrol_aixm.py View on Github external
for lr in sub.findall(
                                "aixm:horizontalProjection/aixm:Surface/"
                                "gml:patches/gml:PolygonPatch/gml:exterior/"
                                "gml:LinearRing",
                                self.ns,
                            ):
                                self.append_coords(lr, block_poly)

                    break  # only one timeslice

            if upper == float("inf") and lower == float("-inf"):
                polygons += cascaded_union_with_alt(block_poly)
            else:
                polygons.append(
                    ExtrudedPolygon(
                        cascaded_union([p for (p, *_) in block_poly]),
                        lower,
                        upper,
                    )
                )

        return cascaded_union_with_alt(polygons)
github xoolive / traffic / traffic / core / airspace.py View on Github external
def cascaded_union_with_alt(polyalt: AirspaceList) -> AirspaceList:
    altitudes = set(alt for _, *low_up in polyalt for alt in low_up)
    slices = sorted(altitudes)
    if len(slices) == 1 and slices[0] is None:
        simple_union = cascaded_union([p for p, *_ in polyalt])
        return [ExtrudedPolygon(simple_union, float("-inf"), float("inf"))]
    results: List[ExtrudedPolygon] = []
    for low, up in zip(slices, slices[1:]):
        matched_poly = [
            p
            for (p, low_, up_) in polyalt
            if low_ <= low <= up_ and low_ <= up <= up_
        ]
        new_poly = ExtrudedPolygon(cascaded_union(matched_poly), low, up)
        if len(results) > 0 and new_poly.polygon.equals(results[-1].polygon):
            merged = ExtrudedPolygon(new_poly.polygon, results[-1].lower, up)
            results[-1] = merged
        else:
            results.append(new_poly)
    return results
github xoolive / traffic / traffic / core / airspace.py View on Github external
def from_json(cls, json: Dict[str, Any]):
        return cls(
            name=json["name"],
            type_=json["type"],
            elements=[
                ExtrudedPolygon(
                    polygon=shape(layer["polygon"]),
                    upper=layer["upper"],
                    lower=layer["lower"],
                )
                for layer in json["shapes"]
            ],