コード例 #1
0
ファイル: makepoly.py プロジェクト: avl/SwFlightPlanner
def poly(points): 
    last=None
    poly_coords=[]
    for coord in points:
        merc=mapper.latlon2merc(mapper.from_str(coord),13)
        if merc==last: continue
        last=merc
        poly_coords.append(Vertex(int(merc[0]),int(merc[1])))
    if len(poly_coords)>=3:
        return Polygon(vvector(poly_coords))
    return None
コード例 #2
0
def poly(points):
    last = None
    poly_coords = []
    for coord in points:
        merc = mapper.latlon2merc(mapper.from_str(coord), 13)
        if merc == last: continue
        last = merc
        poly_coords.append(Vertex(int(merc[0]), int(merc[1])))
    if len(poly_coords) >= 3:
        return Polygon(vvector(poly_coords))
    return None
コード例 #3
0
ファイル: androidstuff.py プロジェクト: avl/SwFlightPlanner
             writeByte(0)
         """
         Format is: (key
         [{'ends': [{'pos': '61.8552555556,24.7619638889', 'thr': u'08'},
 {'pos': '61.8568416667,24.8112611111', 'thr': u'26'}]}
         """
         if versionnum>=7:
             runways=point.get('runways',[])
             writeByte(len(runways))
             #if runways: print "Writing runways,",runways
             for runway in runways:     
                 runway=dict(runway)               
                 for end in runway['ends']:
                     end=dict(end)
                     writeUTF(end['thr'])
                     lat,lon=mapper.from_str(end['pos'])
                     writeFloat(lat)
                     writeFloat(lon)
                 if versionnum>=9:
                     if runway.get('surface',''):
                         writeByte(1)
                         writeUTF(runway.get('surface',''))
                     else:
                         writeByte(0)
                         
         if versionnum>=9:
             if point.get('remark',''):
                 writeByte(1)
                 writeUTF(point['remark'])
             else:
                 writeByte(0)
コード例 #4
0
ファイル: userdata.py プロジェクト: dimme/SwFlightPlanner
class UserData(object):
    def have_any(self):
        return not self.empty

    def __init__(self, user, orders=None):
        #print "Loading userdata for ",user
        self.user = user
        self.log = []
        self.points = dict()
        self.spaces = dict()
        self.pointslookup = dict()
        self.spaceslookup = dict()
        self.empty = True

        zoomlevel = 13
        pointtypes = ['obstacles', 'airfields', 'sigpoints']
        spacestypes = ['airspaces', 'firs']

        for pointtype in pointtypes:
            self.points[pointtype] = []
        for spacetype in spacestypes:
            self.spaces[spacetype] = []

        if orders == None:
            orders = []
            for csets in meta.Session.query(CustomSets).filter(
                    CustomSets.user == user).all():
                customs = list(
                    meta.Session.query(CustomSet).filter(
                        sa.and_(CustomSet.user == user,
                                CustomSet.setname == csets.setname,
                                CustomSet.version == csets.active)).all())
                orders.extend(customs)

        for custom in orders:
            try:
                #print "Found custom set:",custom.setname
                ##print "Found active custom set:",custom.setname,custom.version
                #print "Data:"
                #print "------------------"
                #print custom.data
                #print "Cont1"
                data = json.loads(u"".join([
                    x for x in custom.data.split("\n")
                    if not x.strip().startswith("#")
                ]).encode('utf8'))
                if type(data) != dict:
                    raise Exception(
                        "Top level must be object, that is, file must start with '{'"
                    )
                #print "Cont2"
                for pointtype in pointtypes:
                    if pointtype in data:
                        out = []
                        for point in data[pointtype]:
                            #print "val point"
                            if validate_point(point, pointtype, self.log):
                                out.append(point)
                            #print "aft val point"

                        if pointtype == 'airfields':
                            #print "val airf"
                            validate_airfield_space(point, self.log,
                                                    self.spaces['airspaces'])
                            #print "aft val airf"

                        self.points[pointtype].extend(out)
                        data.pop(pointtype)
                #print "Cont3"
                for spacetype in spacestypes:
                    if spacetype in data:
                        out = []
                        for space in data[spacetype]:
                            if validate_space(space, spacetype, self.log):
                                out.append(space)
                        self.spaces[spacetype].extend(out)
                        data.pop(spacetype)
                #print "Cont4"
                if len(data.keys()):
                    for key in data.keys():
                        self.log.append("Unknown top-level key: %s" % (key, ))

                #print "Cont5"
            except Exception, cause:
                print "Problem parsing custom", traceback.format_exc()
                self.log.append(traceback.format_exc())

        if len(self.log) == 0:
            #print "About to start bsptreein"
            for pointtype in pointtypes:
                bspitems = []
                for item in self.points[pointtype]:
                    #print "Adding BspTree item of type: ",pointtype,"item:",item
                    bspitems.append(
                        BspTree.Item(
                            mapper.latlon2merc(mapper.from_str(item['pos']),
                                               13), item))
                self.pointslookup[pointtype] = BspTree(bspitems)
                if bspitems:
                    self.empty = False

        airspaces = self.spaces.get('airspaces', [])
        firs = [space for space in airspaces if space['type'] == 'FIR']
        regular_airspaces = [
            space for space in airspaces if space['type'] != 'FIR'
        ]
        self.spaces['airspaces'] = regular_airspaces
        self.spaces['firs'] = firs

        if len(self.log) == 0:

            for spacetype in spacestypes:
                bbitems = []
                for space in self.spaces[spacetype]:
                    poly_coords = []
                    bb = BoundingBox(1e30, 1e30, -1e30, -1e30)
                    for coord in space['points']:
                        print "Coord:", coord
                        x, y = mapper.latlon2merc(mapper.from_str(coord),
                                                  zoomlevel)
                        bb.x1 = min(bb.x1, x)
                        bb.x2 = max(bb.x2, x)
                        bb.y1 = min(bb.y1, y)
                        bb.y2 = max(bb.y2, y)
                        poly_coords.append(Vertex(int(x), int(y)))
                    if len(poly_coords) < 3:
                        continue
                    poly = Polygon(vvector(poly_coords))
                    #print "Item:",space
                    bbitems.append(BBTree.TItem(bb, (poly, space)))
                self.spaceslookup[spacetype] = BBTree(bbitems, 0.5)
                if bbitems:
                    self.empty = False

        self.date = datetime.utcnow()
コード例 #5
0
ファイル: androidstuff.py プロジェクト: dimme/SwFlightPlanner
                writeByte(0)
            """
            Format is: (key
            [{'ends': [{'pos': '61.8552555556,24.7619638889', 'thr': u'08'},
    {'pos': '61.8568416667,24.8112611111', 'thr': u'26'}]}
            """
            if versionnum >= 7:
                runways = point.get('runways', [])
                writeByte(len(runways))
                #if runways: print "Writing runways,",runways
                for runway in runways:
                    runway = dict(runway)
                    for end in runway['ends']:
                        end = dict(end)
                        writeUTF(end['thr'])
                        lat, lon = mapper.from_str(end['pos'])
                        writeFloat(lat)
                        writeFloat(lon)
                    if versionnum >= 9:
                        if runway.get('surface', ''):
                            writeByte(1)
                            writeUTF(runway.get('surface', ''))
                        else:
                            writeByte(0)

            if versionnum >= 9:
                if point.get('remark', ''):
                    writeByte(1)
                    writeUTF(point['remark'])
                else:
                    writeByte(0)