Exemple #1
0
def load_definow_aeds():
    bounds = util.get_bounds()
    out = {}
    url = "http://definow.org/de/map/node"
    print("Downloading URL '%s'..." % url)
    r = requests.post(url)
    if r.status_code != 200:
        return
    exp = r'"rmt":"([0-9]+)\\/0","latitude":"([\.0-9]+)","longitude":"([\.0-9]+)",'
    for item in re.findall(exp, r.text):
        #print item
        y = float(item[1])
        x = float(item[2])
        definow_id = int(item[0])
        position = Point([x, y])
        if not bounds.contains(position):
            continue
        out[str(definow_id)] = {
            "id": definow_id,
            "x": x,
            "y": y
        }
    # write CSV version
    with open("definow.csv", "wb") as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(["id", "x", "y"])
        for aedid in out.keys():
            writer.writerow([
                str(out[aedid]["id"]),
                str(out[aedid]["x"]),
                str(out[aedid]["y"])
            ])
    return out
Exemple #2
0
def generate_nearest_neighbor(pop_pts, fac_pts):
    """
    Nearest Neighbor via QuadTree.  
    Faster than "naive" approach for large number of
    facilities (i.e. > 1000)
    arguments:
          pop_pts: an iterable of x,y pairs 
          fac_pts: iterable of x,y pairs

    return: A list of pop_pt index, fac_pt index, & distance
            representing facilities closest to pop pts & the distance between 
            
    """
    edges = []
    bounds =  util.get_bounds(pop_pts + fac_pts)
    qt = quad_tree.QuadTree(10, bounds[:2], bounds[2:], 
            lambda x: x['pt'], True)

    for n in range(0, len(fac_pts)):
        fac_dict = {'id': n, 'pt': fac_pts[n]}
        qt.add(fac_dict)

    for m in range(0, len(pop_pts)):
        pop_pt = pop_pts[m]
        fac_dict = qt.find_nearest(pop_pt)
        dist = util.compute_spherical_distance(pop_pt, fac_dict['pt'])
        edge = [m, fac_dict['id'], dist]
        edges.append(edge)

    return edges
Exemple #3
0
def load_definow_aeds():
    bounds = util.get_bounds()
    out = {}
    url = "http://definow.org/de/map/node"
    print("Downloading URL '%s'..." % url)
    r = requests.post(url)
    if r.status_code != 200:
        return
    exp = r'"rmt":"([0-9]+)\\/0","latitude":"([\.0-9]+)","longitude":"([\.0-9]+)",'
    for item in re.findall(exp, r.text):
        #print item
        y = float(item[1])
        x = float(item[2])
        definow_id = int(item[0])
        position = Point([x, y])
        if not bounds.contains(position):
            continue
        out[str(definow_id)] = {"id": definow_id, "x": x, "y": y}
    # write CSV version
    with open("definow.csv", "wb") as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(["id", "x", "y"])
        for aedid in out.keys():
            writer.writerow([
                str(out[aedid]["id"]),
                str(out[aedid]["x"]),
                str(out[aedid]["y"])
            ])
    return out
Exemple #4
0
def load_osm_aeds():
    xml = """<osm-script output="json" timeout="25">
      <query type="node">
        <has-kv k="emergency" v="defibrillator"/>
        <bbox-query n="51.2" e="7.2" s="50.8" w="6.7" />
      </query>
      <print mode="meta"/>
    </osm-script>"""
    bounds = util.get_bounds()
    out = {}
    r = requests.post("http://overpass-api.de/api/interpreter", data=xml)
    for item in r.json()["elements"]:
        position = Point([item["lon"], item["lat"]])
        if bounds.contains(position):
            out[str(item["id"])] = item
    return out
Exemple #5
0
def load_osm_aeds():
    xml = """<osm-script output="json" timeout="25">
      <query type="node">
        <has-kv k="emergency" v="defibrillator"/>
        <bbox-query n="51.2" e="7.2" s="50.8" w="6.7" />
      </query>
      <print mode="meta"/>
    </osm-script>"""
    bounds = util.get_bounds()
    out = {}
    r = requests.post("http://overpass-api.de/api/interpreter", data=xml)
    for item in r.json()["elements"]:
        position = Point([item["lon"], item["lat"]])
        if bounds.contains(position):
            out[str(item["id"])] = item
    return out
Exemple #6
0
def CIO(goals,
        world,
        p,
        single=False,
        start_stage=0,
        traj_data=None,
        gif_tag=''):
    if single:
        # FOR TESTING A SINGLE traj
        S = world.traj_func(world, goals, p, traj_data)
        S = add_noise(S)
        visualize_result(world, goals, p, 'initial' + gif_tag + '.gif', S)
        tot_cost = L(S, goals, world, p, start_stage)
        print_final(*function_costs)
        return {}

    S = world.traj_func(world, goals, p, traj_data)
    if start_stage == 0:
        S = add_noise(S)
    visualize_result(world, goals, p, 'initial' + gif_tag + '.gif', S)
    tot_cost = L(S, goals, world, p)
    print_final(*function_costs)

    bounds = get_bounds(world, p)
    ret_info = {}
    x_init = S
    for stage in range(start_stage, len(p.stage_weights)):
        print('BEGINNING PHASE:', stage)
        p.print_stage_weights(stage)
        res = minimize(fun=L,
                       x0=x_init,
                       args=(goals, world, p, stage),
                       method='L-BFGS-B',
                       bounds=bounds,
                       options={'eps': 10**-3})
        x_final = res['x']
        nit = res['nit']
        final_cost = res['fun']

        visualize_result(world, goals, p,
                         'stage_{}'.format(stage) + gif_tag + '.gif', x_final)
        print_final(*function_costs)
        all_final_costs = function_costs
        ret_info[stage] = world.s0, x_final, final_cost, nit, all_final_costs
        x_init = x_final
    return ret_info
Exemple #7
0
    def get_image(self, feat, radius=0.02, scale=30):
        moves = [(radius, radius), (radius, -radius), (-radius, -radius),
                 (-radius, radius)]
        feat = ee.Feature(feat)
        region = self.get_image_region(feat)
        data = feat.getInfo()

        type = data['geometry']['type']
        coords = data['geometry']['coordinates']
        if type == 'Point':
            bounds = [[coords[0] + r0, coords[1] + r1] for r0, r1 in moves]
        elif type == 'Polygon':
            bounds = coords
        else:
            xmin, ymin, xmax, ymax = get_bounds(
                [c[0] for c in data['geometry']['coordinates']])
            bounds = [[xmin, ymax], [xmax, ymax], [xmax, ymin], [xmin, ymin]]

        image = ee.Image(region)
        params = {'region': bounds, 'scale': scale}
        return image, params
Exemple #8
0
def load_aedkataster_aeds():
    bounds = util.get_bounds()
    out = {}
    url = "http://aed-kataster.net/nw.html"
    print("Downloading URL '%s'..." % url)
    r = requests.post(url)
    if r.status_code != 200:
        return
    exp = r'GLatLng\(([\.0-9]+),([\.0-9]+)\);\s+SobiCatOverMap\.addOverlay\(\s+createSobiMarker\(\s+MarkerPoint,\s+\'<div><a href="[^\?]+\?sobi2Task=sobi2Details&amp;sobi2Id=([0-9]+)">'
    for item in re.findall(exp, r.text):
        #print item
        y = float(item[0])
        x = float(item[1])
        aedk_id = int(item[2])
        position = Point([x, y])
        if bounds.contains(position):
            out[str(aedk_id)] = {
                "id": aedk_id,
                "x": x,
                "y": y
            }
    return out
Exemple #9
0
 def get_bounds(self):
     return get_bounds(list(self.blocks.keys()))