From fc0e42dedea68fa22b1543ba3c0f508ec2f9ac73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Mon, 1 Apr 2019 13:12:59 +0200 Subject: [PATCH] Normalize latitude in horde-members-api --- horde-members-api/app.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/horde-members-api/app.py b/horde-members-api/app.py index f046074..5e32a5b 100644 --- a/horde-members-api/app.py +++ b/horde-members-api/app.py @@ -117,6 +117,10 @@ def member2feature(member): } +def normalize(x, y): + return x % 180 if x > 0 else x % -180, y + + class MemberResource(flask_restful.Resource): @flask_restful.marshal_with(member_fields) def get(self, id): @@ -136,8 +140,7 @@ class MemberResource(flask_restful.Resource): if not member: member = Member(id=id, created_at=now) member.nick = args['nick'] - member.x = args['x'] - member.y = args['y'] + member.x, member.y = normalize(args['x'], args['y']) member.updated_at = now db.session.add(member) db.session.commit() @@ -196,8 +199,7 @@ class MembersResource(flask_restful.Resource): if not member: member = Member(created_at=now) member.user = args['nick'] - member.x = args['x'] - member.y = args['y'] + member.x, member.y = normalize(args['x'], args['y']) member.updated_at = now db.session.add(member) db.session.commit() @@ -238,7 +240,7 @@ class FeaturesResource(flask_restful.Resource): if not member: member = Member(created_at=now) member.nick = properties_args['nick'] - member.x, member.y = geometry_args['coordinates'] + member.x, member.y = normalize(*geometry_args['coordinates']) member.updated_at = now db.session.add(member) db.session.commit()