예제 #1
0
def point_update(request):
    # first try to load the point that should be updated
    try:
        # try to cast the given id to an integer
        id = int(request.matchdict['id'])
    except ValueError:
        raise HTTPBadRequest()

    try:
        # load the point with the given id
        point = DBSession.query(Point).filter(Point.id == id).one()
    except NoResultFound:
        raise HTTPNotFound()

    # get the new values
    title = request.POST.get('title', '')
    description = request.POST.get('description', '')
    try:
        # try to get the input parameters
        lon = float(request.POST.get('lon'))
        lat = float(request.POST.get('lat'))
    except ValueError:
        raise HTTPBadRequest()

    # then set the new values on the point
    point.title = title
    point.description = description
    point.geom = from_shape(PointShape(lon, lat), srid=4326)
    # the point will automatically be flushed (updated in the database)

    return to_geojson(point)
예제 #2
0
def points(request):
    points = DBSession.query(Point).all()
    points_geojson = [to_geojson(point) for point in points]

    return {
        'type': 'FeatureCollection',
        'features': points_geojson
    }
예제 #3
0
def point_add(request):
    title = request.POST.get('title', '')
    description = request.POST.get('description', '')
    try:
        # try to get the input parameters
        lon = float(request.POST.get('lon'))
        lat = float(request.POST.get('lat'))
    except ValueError:
        raise HTTPBadRequest()

    point = Point(
        title=title,
        description=description,
        date=datetime.now(),
        geom=from_shape(PointShape(lon, lat), srid=4326))

    DBSession.add(point)

    # flush the session so that the point gets its id
    DBSession.flush()

    return to_geojson(point)
예제 #4
0
def point(request):
    try:
        # try to cast the given id to an integer
        id = int(request.matchdict['id'])
    except ValueError:
        raise HTTPBadRequest()

    try:
        # load the point with the given id
        point = DBSession.query(Point).filter(Point.id == id).one()
    except NoResultFound:
        raise HTTPNotFound()

    return to_geojson(point)