Exemple #1
0
def osm_download(uid):
    """Function to download osm data.

    GET request: The osmdownload site is returned, which shows the bounding polygon for the selected layer and a form to
    choose the osm highway-types which should not be downloaded.

    POST request: The selected options in the request form and the bounding polygon coordinates are transformed to
    overpass query language. This data is used to call the osm_from_overpass function from the OSMDeviationfinder class,
    which will make an OverpassAPI query and dowload the returned osm data and yield the progress of the download back,
    which will be streamed to the client.
    """
    uid = uid.encode("ISO-8859-1")
    if request.method == "POST":
        fdir = os.path.join(app.config["UPLOAD_FOLDER"], uid)
        f = os.path.join(fdir, str(uid) + ".osm")
        typesquery = ""
        for i in request.form:
            typesquery = typesquery + '["highway"!="' + i + '"]'
        dm = DevMap.query.filter_by(uid=uid).first()
        bbox = json.dumps(dm.boundsxy)
        bbox = bbox[bbox.find("[[") : bbox.find("]]") + 2].replace("[", "").replace("]", "").replace(",", "")
        devfinder = OSMDeviationfinder(connectioninfo)
        return Response(devfinder.osm_from_overpass(bbox, typesquery, f, uid), mimetype="text/html")
    return render_template("osmdownload.html", uid=uid)