Beispiel #1
0
def get_nest_points():
    nests = []
    try:
        nests = load_pickle('nests', raise_exception=True)
    except (FileNotFoundError, TypeError, KeyError):
        parks = get_all_parks()
        for s in get_spawnpoint_markers():
            spawn_point = Point(s['lat'], s['lon'])
            cell = Polygon(get_s2_cell_as_polygon(s['lat'], s['lon'],
                                                  20))  # s2 lvl 20
            for p in parks:
                coords = p['coords']
                # osm polygon can be a line
                if len(coords) == 2:
                    shape = LineString(coords)
                    if shape.within(cell.centroid):
                        nests.append(s)
                        break
                if len(coords) > 2:
                    shape = Polygon(coords)
                    if shape.contains(cell.centroid):
                        nests.append(s)
                        break
        dump_pickle('nests', nests)
    return nests
Beispiel #2
0
def get_all_parks():
    parks = []
    try:
        parks = load_pickle('parks', raise_exception=True)
    except (FileNotFoundError, TypeError, KeyError):
        # all osm parks at 07/17/2016
        api = overpy.Overpass()
        request = '[timeout:620][date:"2016-07-17T00:00:00Z"];(way["leisure"="park"];way["landuse"="recreation_ground"];way["leisure"="recreation_ground"];way["leisure"="pitch"];way["leisure"="garden"];way["leisure"="golf_course"];way["leisure"="playground"];way["landuse"="meadow"];way["landuse"="grass"];way["landuse"="greenfield"];way["natural"="scrub"];way["natural"="heath"];way["natural"="grassland"];way["landuse"="farmyard"];way["landuse"="vineyard"];way["natural"="plateau"];way["leisure"="nature_reserve"];way["natural"="moor"];way["landuse"="farmland"];way["landuse"="orchard"];);out;>;out skel qt;'
        request = '[bbox:{},{},{},{}]{}'.format(south, west, north, east, request)
        response = api.query(request)
        for w in response.ways:
            parks.append({
                'type': 'park',
                'coords': [[float(c.lat), float(c.lon)] for c in w.nodes]
            })
        dump_pickle('parks', parks)

    return parks
Beispiel #3
0
def get_ex_gyms():
    ex_gyms = []
    parks = get_all_parks()
    try:
        ex_gyms = load_pickle('ex_gyms', raise_exception=True)
    except (FileNotFoundError, TypeError, KeyError):
        for g in get_gym_markers():
            g['id'] = 'ex-' + g['id']
            gym_point = Point(g['lat'], g['lon'])
            cell = Polygon(get_s2_cell_as_polygon(g['lat'], g['lon'],
                                                  level=20))  # s2 lvl 20
            sponsor_value = 'park'
            if g['sponsor'] == 7:
                sponsor_value = 'starbucks'
                ex_gyms.append({
                    'id': g['id'],
                    'external_id': g['external_id'],
                    'fort_id': g['fort_id'],
                    'name': g['gym_name'],
                    'lat': g['lat'],
                    'lon': g['lon'],
                    'sponsor': sponsor_value
                })
            if g['sponsor'] == 9:
                sponsor_value = 'sprint'
                ex_gyms.append({
                    'id': g['id'],
                    'external_id': g['external_id'],
                    'fort_id': g['fort_id'],
                    'name': g['gym_name'],
                    'lat': g['lat'],
                    'lon': g['lon'],
                    'sponsor': sponsor_value
                })
            for p in parks:
                coords = p['coords']
                # osm polygon can be a line
                if len(coords) == 2:
                    shape = LineString(coords)
                    if shape.within(cell.centroid):
                        ex_gyms.append({
                            'id': g['id'],
                            'external_id': g['external_id'],
                            'fort_id': g['fort_id'],
                            'name': g['gym_name'],
                            'lat': g['lat'],
                            'lon': g['lon'],
                            'sponsor': sponsor_value
                        })
                if len(coords) > 2:
                    shape = Polygon(coords)
                    if shape.contains(cell.centroid):
                        ex_gyms.append({
                            'id': g['id'],
                            'external_id': g['external_id'],
                            'fort_id': g['fort_id'],
                            'name': g['gym_name'],
                            'lat': g['lat'],
                            'lon': g['lon'],
                            'sponsor': sponsor_value
                        })

        dump_pickle('ex_gyms', ex_gyms)
    return ex_gyms