Ejemplo n.º 1
0
def getbbox(coord, localrange):
    """ 
    >>> getbbox("Point 56.1, -3.0", 100)
    (55.19961041787985, -4.614338821845118, 57.00038958212015, -1.3856611781548822)

    """
    pt_lat, pt_long = IS_GEOLOCATION.parse_geopoint(coord)
    # pt_lat = 56.100
    # pt_long = -3.0
    minlat, minlong, maxlat, maxlong = boundingBox(pt_lat, pt_long, localrange)

    return minlat, minlong, maxlat, maxlong
Ejemplo n.º 2
0
def new_location():

    stdclass = "btn btn-primary btn-xs btn-group-xs"
    # This allows creation and editing of a locations by their owner
    fields = ['location_name', 'description', 'address1', 'address2', 'address3', 'address4', 'addrcode',
              'continent', 'country', 'subdivision', 'coord']

    buttons = [TAG.button('Submit', _type="submit"),
               TAG.INPUT(_TYPE='BUTTON', _id="geocode", _class=stdclass, _onclick="", _VALUE="Get Co-ordinates"),
               TAG.INPUT(_TYPE='BUTTON', _id="rev_geocode", _class=stdclass, _onclick="", _VALUE="Get Address")]

    locationid = request.args(0, default=None)
    if locationid is not None:
        record = db.locn(locationid)
        form = SQLFORM(db.locn, record, fields=fields)
    else:
        form = SQLFORM(db.locn, fields=fields, buttons=buttons)

    if form.validate():
        if locationid:
            if form.deleted:
                db(db.location.id == locationid).delete()
                response.flash = 'Location deleted'
                redirect(URL('location', 'index'))
            else:
                record.update_record(**dict(form.vars))
                response.flash = 'Location updated'
                redirect(URL('location', 'index'))
        else:
            # write values into separate fields for indexed bb queries on non spatial databases
            form.vars.geoy, form.vars.geox = IS_GEOLOCATION.parse_geopoint(form.vars.coord)
            form.vars.id = db.locn.insert(**dict(form.vars))
            session.flash = 'Location Created'
            redirect(URL('accept_location', args=[form.vars.id]))
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill out the form'
    return dict(form=form)