Update an existing ROI
Description: Update an existing ROI in dataset
URI: /datasets/ROI/<name>
http method: PUT
@app.route('/datasets/ROI/<string:name>', methods=['PUT'])
def modify_roi(name):
if not request.json or 'rid' not in request.json:
return('',400)
cur = conn.cursor()
constraint = []
rid = str(request.json['rid'])
if 'density' in request.json:
constraint.append("density = "+str(request.json['density']))
if 'score' in request.json:
constraint.append("score = "+str(request.json['score']))
if 'range' in request.json:
bound = request.json['range']
try:
range = "'"+str(bound['east'])+","+str(bound['north'])+","+str(bound['west'])+","+str(bound['south'])+"'"
except KeyError:
return('',400)
constraint.append("range = "+range)
query = "UPDATE roi."+name+" SET "+",".join(constraint)+" where rid = "+rid+";"
try:
cur.execute(query)
conn.commit()
cur.close()
except psycopg2.Error as e:
conn.rollback()
cur.close()
return(e.pgerror,400)
return('',200)