From 9d7379f3f850a15326676d6a58cd5cc88dc36d04 Mon Sep 17 00:00:00 2001 From: Alexey Zakharenkov <35913079+alexey-zakharenkov@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:23:44 +0300 Subject: [PATCH] Repair 'Convex hull' operation --- web/app/borders_api.py | 15 ++++++++++----- web/app/static/borders.js | 9 ++------- web/app/templates/index.html | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/web/app/borders_api.py b/web/app/borders_api.py index 082e1e3..4519c43 100755 --- a/web/app/borders_api.py +++ b/web/app/borders_api.py @@ -863,13 +863,18 @@ def chop_largest_or_farthest(): def draw_hull(): if config.READONLY: abort(405) - name = request.args.get('name').encode('utf-8') - cur = g.conn.cursor() - cur.execute('select ST_NumGeometries(geom) from {} where name = %s;'.format(config.TABLE), (name,)) - res = cur.fetchone() + border_id = int(request.args.get('id')) + cursor = g.conn.cursor() + table = config.TABLE + cursor.execute(f""" + SELECT ST_NumGeometries(geom) FROM {table} WHERE id = %s + """, (border_id,)) + res = cursor.fetchone() if not res or res[0] < 2: return jsonify(status='border should have more than one outer ring') - cur.execute('update {} set geom = ST_ConvexHull(geom) where name = %s;'.format(config.TABLE), (name,)) + cursor.execute(f""" + UPDATE {table} SET geom = ST_ConvexHull(geom) + WHERE id = %s""", (border_id,)) g.conn.commit() return jsonify(status='ok') diff --git a/web/app/static/borders.js b/web/app/static/borders.js index 351793c..79a3ca8 100644 --- a/web/app/static/borders.js +++ b/web/app/static/borders.js @@ -1049,13 +1049,8 @@ function bHull() { if( !selectedId || !(selectedId in borders) ) return; $.ajax(getServer('hull'), { - data: { 'name': selectedId }, - success: function(answer) { - if (answer.status !== 'ok') - alert(answer.status); - else - updateBorders(); - } + data: { 'id': selectedId }, + success: makeAnswerHandler(updateBorders) }); } diff --git a/web/app/templates/index.html b/web/app/templates/index.html index 6c3e558..5780535 100644 --- a/web/app/templates/index.html +++ b/web/app/templates/index.html @@ -122,7 +122,7 @@

-
+