From 6274efc2906665200ff9f102700d00b5dfc1faac Mon Sep 17 00:00:00 2001 From: RoryPTB <47696929+RoryPTB@users.noreply.github.com> Date: Wed, 11 Sep 2024 17:22:58 +0200 Subject: [PATCH] fix: ensure estimated polygon from circle follows right-hand rule --- src/cap2geojson/convert.py | 4 + tests/output/circle_estimation.json | 172 ++++++++++++++-------------- 2 files changed, 90 insertions(+), 86 deletions(-) diff --git a/src/cap2geojson/convert.py b/src/cap2geojson/convert.py index b2f4968..19acfb2 100644 --- a/src/cap2geojson/convert.py +++ b/src/cap2geojson/convert.py @@ -6,6 +6,7 @@ import xmltodict from pyproj import Transformer from shapely.geometry import Point +from shapely.geometry.polygon import orient from shapely.ops import transform as transform_bufr from typing import Generator, Union @@ -109,6 +110,9 @@ def get_circle_coords( # Transform the buffer back to WGS84 coordinates circle = transform_bufr(aeqd_to_wgs84.transform, buffer) + # Ensure the coordinates follow the right-hand rule (counter-clockwise) + circle = orient(circle, sign=1.0) + # Extract the coordinates from the transformed buffer for coord in circle.exterior.coords: yield [round(coord[0], 5), round(coord[1], 5)] diff --git a/tests/output/circle_estimation.json b/tests/output/circle_estimation.json index 64c1872..714de7d 100644 --- a/tests/output/circle_estimation.json +++ b/tests/output/circle_estimation.json @@ -5,127 +5,127 @@ ], [ 5.06274, - 2.99383 + 3.00617 ], [ 5.06183, - 2.98772 + 3.01228 ], [ - 5.06032, - 2.98172 + 5.06033, + 3.01827 ], [ 5.05824, - 2.97591 + 3.02409 ], [ - 5.05559, - 2.97032 + 5.0556, + 3.02967 ], [ - 5.05241, - 2.96502 + 5.05242, + 3.03497 ], [ 5.04873, - 2.96006 + 3.03994 ], [ - 5.04457, - 2.95548 + 5.04458, + 3.04451 ], [ 5.03999, - 2.95134 + 3.04866 ], [ 5.03502, - 2.94766 + 3.05234 ], [ - 5.02971, - 2.94448 + 5.02972, + 3.05552 ], [ - 5.02412, - 2.94184 + 5.02413, + 3.05816 ], [ 5.0183, - 2.93976 + 3.06024 ], [ 5.0123, - 2.93826 + 3.06174 ], [ 5.00618, - 2.93735 + 3.06265 ], [ 5.0, - 2.93705 + 3.06295 ], [ 4.99382, - 2.93735 + 3.06265 ], [ 4.9877, - 2.93826 + 3.06174 ], [ 4.9817, - 2.93976 + 3.06024 ], [ - 4.97588, - 2.94184 + 4.97587, + 3.05816 ], [ - 4.97029, - 2.94448 + 4.97028, + 3.05552 ], [ 4.96498, - 2.94766 + 3.05234 ], [ 4.96001, - 2.95134 + 3.04866 ], [ - 4.95543, - 2.95548 + 4.95542, + 3.04451 ], [ 4.95127, - 2.96006 + 3.03994 ], [ - 4.94759, - 2.96502 + 4.94758, + 3.03497 ], [ - 4.94441, - 2.97032 + 4.9444, + 3.02967 ], [ 4.94176, - 2.97591 + 3.02409 ], [ - 4.93968, - 2.98172 + 4.93967, + 3.01827 ], [ 4.93817, - 2.98772 + 3.01228 ], [ 4.93726, - 2.99383 + 3.00617 ], [ 4.93696, @@ -133,127 +133,127 @@ ], [ 4.93726, - 3.00617 + 2.99383 ], [ 4.93817, - 3.01228 + 2.98772 ], [ - 4.93967, - 3.01827 + 4.93968, + 2.98172 ], [ 4.94176, - 3.02409 + 2.97591 ], [ - 4.9444, - 3.02967 + 4.94441, + 2.97032 ], [ - 4.94758, - 3.03497 + 4.94759, + 2.96502 ], [ 4.95127, - 3.03994 + 2.96006 ], [ - 4.95542, - 3.04451 + 4.95543, + 2.95548 ], [ 4.96001, - 3.04866 + 2.95134 ], [ 4.96498, - 3.05234 + 2.94766 ], [ - 4.97028, - 3.05552 + 4.97029, + 2.94448 ], [ - 4.97587, - 3.05816 + 4.97588, + 2.94184 ], [ 4.9817, - 3.06024 + 2.93976 ], [ 4.9877, - 3.06174 + 2.93826 ], [ 4.99382, - 3.06265 + 2.93735 ], [ 5.0, - 3.06295 + 2.93705 ], [ 5.00618, - 3.06265 + 2.93735 ], [ 5.0123, - 3.06174 + 2.93826 ], [ 5.0183, - 3.06024 + 2.93976 ], [ - 5.02413, - 3.05816 + 5.02412, + 2.94184 ], [ - 5.02972, - 3.05552 + 5.02971, + 2.94448 ], [ 5.03502, - 3.05234 + 2.94766 ], [ 5.03999, - 3.04866 + 2.95134 ], [ - 5.04458, - 3.04451 + 5.04457, + 2.95548 ], [ 5.04873, - 3.03994 + 2.96006 ], [ - 5.05242, - 3.03497 + 5.05241, + 2.96502 ], [ - 5.0556, - 3.02967 + 5.05559, + 2.97032 ], [ 5.05824, - 3.02409 + 2.97591 ], [ - 5.06033, - 3.01827 + 5.06032, + 2.98172 ], [ 5.06183, - 3.01228 + 2.98772 ], [ 5.06274, - 3.00617 + 2.99383 ], [ 5.06304,