Exemple #1
0
def linematch(uid):
    """This function is used to show and handle the linematching options and process.

    GET request: Renders and returns a site showing linematching options.

    POST request: Gets the linematching options from the user and creates an object of the LinematchOptions class
    which holds the user's chosen and default options. The linematch_datasets function from the OSMDeviationfinder class
    is called with the LinematchOptions object as parameter. The linematch_datasets function uses 'yield' to return the
    progress, this is used to stream the progress to the client.
    """
    uid = uid.encode("ISO-8859-1")
    dm = DevMap.query.filter_by(uid=uid).first()
    if request.method == "POST":
        devfinder = OSMDeviationfinder(connectioninfo)
        devfinder.db_source = ogr.Open(devfinder.dbconnectioninfo_ogr, 1)

        linematch_options = LinematchOptions(uid)

        linematch_options.keepcolumns_t2 = {"osm_id": "varchar"}

        if "searchradius" in request.form:
            linematch_options.searchradius = request.form["searchradius"]
        if "maxpotentialmatches" in request.form:
            linematch_options.maxpotentialmatches = request.form["maxpotentialmatches"]
        if "minmatchingfeatlen" in request.form:
            linematch_options.minmatchingfeatlen = request.form["minmatchingfeatlen"]
        if "maxlengthdiffratio" in request.form:
            linematch_options.maxlengthdiffratio = request.form["maxlengthdiffratio"]
        if "maxanglediff" in request.form:
            linematch_options.maxanglediff = request.form["maxanglediff"]
        if "posdiffsegmentlength" in request.form:
            linematch_options.posdiffsegmentlength = request.form["posdiffsegmentlength"]
        if "hausdorffsegmentlength" in request.form:
            linematch_options.hausdorffsegmentlength = request.form["hausdorffsegmentlength"]
        if "maxazimuthdiff" in request.form:
            linematch_options.maxazimuthdiff = request.form["maxazimuthdiff"]
        if "maxmeanposdifftolengthratio" in request.form:
            linematch_options.maxmeanposdifftolength = request.form["maxmeanposdifftolengthratio"]
        if "minmeanposdifftolengthratio" in request.form:
            linematch_options.minmeanposdifftolength = request.form["minmeanposdifftolengthratio"]
        if "exportdevvec" in request.form:
            linematch_options.deviationvectorlayer = True
        else:
            linematch_options.deviationvectorlayer = False
        dm.searchradius2 = linematch_options.searchradius
        dm.minmatchingfeatlen = linematch_options.minmatchingfeatlen
        dm.maxlengthdiffratio = linematch_options.maxlengthdiffratio
        dm.maxanglediff = linematch_options.maxanglediff
        dm.maxpotentialmatches = linematch_options.maxpotentialmatches
        dm.posdiffsegmentlength = linematch_options.posdiffsegmentlength
        dm.hausdorffsegmentlength = linematch_options.hausdorffsegmentlength
        dm.maxazimuthdiff = linematch_options.maxazimuthdiff
        dm.maxmeanposdevtolength = linematch_options.maxmeanposdevtolength
        dm.minmeanposdevtolength = linematch_options.minmeanposdevtolength
        dm.maxabsolutmeanposdev = linematch_options.maxabsolutmeanposdev
        dm.maxdeviation = linematch_options.maxdeviation
        db.session.add(dm)
        db.session.commit()
        return Response(devfinder.linematch_datasets(linematch_options), mimetype="text/html")

    return render_template("linematch.html", uid=uid, dm=dm)
Exemple #2
0
def results(uid):
    """This function is used to show and handle the result generation options and process.

    GET request: Renders and returns a site showing result generation options.

    POST request: Gets the result generation options from the user and creates an object of the ResultOptions class
    which holds the user's chosen and default options. The create_results function from the OSMDeviationfinder class
    is called with the ResultOptions object as parameter. The create_results function uses 'yield' to return the
    progress, this is used to stream the progress to the client.
    """
    uid = uid.encode("ISO-8859-1")
    if request.method == "POST":
        devfinder = OSMDeviationfinder(connectioninfo)
        devfinder.db_source = ogr.Open(devfinder.dbconnectioninfo_ogr, 1)

        result_options = ResultOptions(uid)

        dm = DevMap.query.filter_by(uid=uid).first()
        if (
            current_user.is_authenticated()
            and dm.owner == current_user
            or dm.owner == User.query.filter_by(username="******").first()
        ):

            if "maxdevgrid" in request.form:
                result_options.maxdevgrid = True
            if "posdevlines" in request.form:
                result_options.posdevlines = True
            if "posdevlinedist" in request.form:
                result_options.posdevlinedist = request.form["posdevlinedist"]
            if "absdevgrid" in request.form:
                result_options.absdevgrid = True
            if "matchingrategrid" in request.form:
                result_options.matchingrategrid = True
            if "gridcellsize" in request.form:
                result_options.gridcellsize = request.form["gridcellsize"]
            if "unmatchedref" in request.form:
                result_options.unmatchedref = True
            if "unmatchedrefminlen" in request.form:
                result_options.unmatchedrefminlen = request.form["unmatchedrefminlen"]
            if "unmatchedosm" in request.form:
                result_options.unmatchedosm = True
            if "unmatchedosmminlen" in request.form:
                result_options.unmatchedosmminlen = request.form["unmatchedosmminlen"]
            if "matchedref" in request.form:
                result_options.matchedref = True
            if "matchedrefminlen" in request.form:
                result_options.matchedrefminlen = request.form["matchedrefminlen"]
            if "matchedosm" in request.form:
                result_options.matchedosm = True
            if "matchedosmminlen" in request.form:
                result_options.matchedosmminlen = request.form["matchedosmminlen"]
            if "minlevenshtein" in request.form:
                result_options.minlevenshtein = True
            if "minlev" in request.form:
                result_options.minlev = request.form["minlev"]
            if "maxlevenshtein" in request.form:
                result_options.maxlevenshtein = True
            if "maxlev" in request.form:
                result_options.maxlev = request.form["maxlev"]

            # Keep track of created results
            dm.posdevlines = result_options.posdevlines
            dm.maxdevgrid = result_options.maxdevgrid
            dm.absdevgrid = result_options.absdevgrid
            dm.matchingrategrid = result_options.matchingrategrid
            dm.gridcellsize = result_options.gridcellsize
            dm.unmatchedref = result_options.unmatchedref
            dm.unmatchedosm = result_options.unmatchedosm
            dm.matchedref = result_options.matchedref
            dm.matchedosm = result_options.matchedosm
            dm.minlevenshtein = result_options.minlevenshtein
            dm.maxlevenshtein = result_options.maxlevenshtein

            db.session.add(dm)
            db.session.commit()
        return Response(devfinder.create_results(result_options), mimetype="text/html")
    else:
        return render_template("results.html", uid=uid)
Exemple #3
0
def harmonize(uid):
    """This function is used to show and handle the harmonization options and process.

    GET request: Renders and returns a site showing harmonization options.

    POST request: Gets the harmonization options from the user and creates an object of the HarmonizeOptions class
    which holds the user's chosen and default options. The harmonize_datasets function from the OSMDeviationfinder class
    is called with the HarmonizeOptions object as parameter. The harmonize_datasets function uses 'yield' to return the
    progress, this is used to stream the progress to the client.
    """
    uid = uid.encode("ISO-8859-1")
    devfinder = OSMDeviationfinder(connectioninfo)
    dm = DevMap.query.filter_by(uid=uid).first()
    if request.method == "POST":
        devfinder.db_source = ogr.Open(devfinder.dbconnectioninfo_ogr, 1)

        harmonization_options = HarmonizeOptions(uid)

        #: Keep column osm_id while processing
        harmonization_options.keepcolumns_t2 = {"osm_id": "varchar"}

        if "azimuthdifftolerance" in request.form:
            harmonization_options.azimuthdifftolerance = request.form["azimuthdifftolerance"]
        if "maxcheckpointanglediff" in request.form:
            harmonization_options.maxcheckpointanglediff = request.form["maxcheckpointanglediff"]
        if "searchradius" in request.form:
            harmonization_options.searchradius = request.form["searchradius"]
        if "presplitref" in request.form:
            harmonization_options.presplitref = True
        if "presplitosm" in request.form:
            harmonization_options.presplitosm = True
        if "harmonize" in request.form:
            harmonization_options.harmonize = True
        if "cleanref" in request.form:
            harmonization_options.cleanref = True
        if "cleanosm" in request.form:
            harmonization_options.cleanosm = True
        if "cleandistance" in request.form:
            harmonization_options.cleanosmradius = request.form["cleandistance"]
            harmonization_options.cleanrefradius = request.form["cleandistance"]
        if "streetnamecol" in request.form:
            harmonization_options.streetnamecol = request.form["streetnamecol"]
        if harmonization_options.streetnamecol == "NoNameCol":
            devfinder.create_nonamecolumn("odf_" + uid + "_ref")
        dm.basetable = harmonization_options.basetable
        dm.harmonize = harmonization_options.harmonize
        dm.reftable = harmonization_options.reftable
        dm.osmtable = harmonization_options.osmtable
        dm.streetnamecol = harmonization_options.streetnamecol
        dm.outsuffix = harmonization_options.outsuffix
        dm.keepcolumns_t1 = harmonization_options.keepcolumns_t1
        dm.keepcolumns_t2 = harmonization_options.keepcolumns_t2
        dm.cleanref = harmonization_options.cleanref
        dm.cleanosm = harmonization_options.cleanosm
        dm.cleanrefradius = harmonization_options.cleanrefradius
        dm.cleanosmradius = harmonization_options.cleanosmradius
        dm.presplitref = harmonization_options.presplitref
        dm.presplitosm = harmonization_options.presplitosm
        dm.searchradius = harmonization_options.searchradius
        dm.azimuthdifftolerance = harmonization_options.azimuthdifftolerance
        dm.maxcheckpointanglediff = harmonization_options.maxcheckpointanglediff
        dm.max_roads_countdiff = harmonization_options.max_roads_countdiff
        dm.max_azdiff = harmonization_options.max_azdiff
        dm.max_distancediff = harmonization_options.max_distancediff
        db.session.add(dm)
        db.session.commit()
        return Response(devfinder.harmonize_datasets(harmonization_options), mimetype="text/html")
    namecolumns = devfinder.get_textcolumns("odf_" + uid + "_ref")
    return render_template("harmonize.html", uid=uid, namecolumns=namecolumns, dm=dm)