示例#1
0
def _write_boat_area(pier, stg_manager, coords_transform: co.Transformation):
    if len(pier.nodes) < 3:
        return
    # Guess a possible position for realistic boat placement
    linear_ring = shg.LinearRing(pier.nodes)
    centroid = linear_ring.centroid
    # Simplify
    ring = linear_ring.convex_hull.buffer(
        40, cap_style=CAP_STYLE.square,
        join_style=JOIN_STYLE.bevel).simplify(20)
    for p in ring.exterior.coords:
        line_coords = [[centroid.x, centroid.y], p]
        target_vector = shg.LineString(line_coords)
        coords = linear_ring.coords
        for i in range(len(coords) - 1):
            segment = LineString(coords[i:i + 2])
            if segment.length > 20 and segment.intersects(target_vector):
                direction = math.degrees(
                    math.atan2(segment.coords[0][0] - segment.coords[1][0],
                               segment.coords[0][1] - segment.coords[1][1]))
                parallel = segment.parallel_offset(10, 'right')
                boat_position = parallel.interpolate(segment.length / 2)
                try:
                    pos_global = coords_transform.to_global(
                        (boat_position.x, boat_position.y))
                    _write_model(segment.length, stg_manager, pos_global,
                                 direction, pier.elevation)
                except AttributeError as reason:
                    logging.error(reason)
class Flight:
    def __init__(self, flight_json):
        self.flight_json = flight_json
        self.id = flight_json['id']
        self.properties = flight_json['properties']
        self.line = LineString(flight_json['geometry']['coordinates'])

    # return true if the flight starts inside the specified FIR
    def starts_in_fir(self, fir):
        return fir.polygon.contains(Point(self.line.coords[0]))

    # return true if the flight ends inside the specified FIR
    def ends_in_fir(self, fir):
        return fir.polygon.contains(Point(self.line.coords[-1]))

    # return true if the flight crosses the specified FIR at least once
    def crosses_fir(self, fir):
        return self.line.intersects(fir.polygon)

    # return the amount of times the flight crosses the specified FIR
    def times_crosses_fir(self, fir):
        ntimes = 0
        isinside = False
        for coord in self.line.coords:
            if fir.polygon.contains(Point(coord)):
                if not isinside:
                    ntimes += 1
                    isinside = True
            else:
                isinside = False
        return ntimes

    # return true if the flight is domestic given the roi as fir
    def is_domestic(self, fir):
        return self.starts_in_fir(fir) and self.ends_in_fir(fir)

    # return true if the flight is a fly-through given the roi as fir
    def is_flythrough(self, fir):
        return (not self.starts_in_fir(fir) and not self.ends_in_fir(fir))