Skip to content

Commit e010783

Browse files
committed
back out of coordinate updates
1 parent 8663198 commit e010783

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

pycsw/core/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ def bbox_from_polygons(bboxs):
19951995
multi_pol = MultiPolygon(
19961996
[loads(bbox) for bbox in bboxs]
19971997
)
1998-
bstr = ",".join([str(b) for b in multi_pol.bounds])
1998+
bstr = ",".join([f"{b:.2f}" for b in multi_pol.bounds])
19991999
return util.bbox2wktpolygon(bstr)
20002000
except Exception as err:
20012001
raise RuntimeError('Cannot aggregate polygons: %s' % str(err)) from err

pycsw/core/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,13 @@ def bbox2wktpolygon(bbox):
240240
241241
"""
242242

243+
precision = int(os.environ.get('COORDINATE_PRECISION', 2))
243244
if bbox.startswith('ENVELOPE'):
244245
bbox = wktenvelope2bbox(bbox)
245-
246-
minx, miny, maxx, maxy = [float(coord) for coord in bbox.split(",")]
247-
248-
return 'POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))' \
246+
minx, miny, maxx, maxy = [f"{float(coord):.{precision}f}" for coord in bbox.split(",")]
247+
wktGeometry = 'POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))' \
249248
% (minx, miny, minx, maxy, maxx, maxy, maxx, miny, minx, miny)
249+
return wktGeometry
250250

251251

252252
def transform_mappings(queryables, typename):

tests/unittests/test_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))",
4242
"POLYGON ((2 2, 2 3, 3 3, 3 2, 2 2))",
4343
],
44-
"POLYGON((0.0 0.0, 0.0 3.0, 3.0 3.0, 3.0 0.0, 0.0 0.0))"
44+
"POLYGON((0.00 0.00, 0.00 3.00, 3.00 3.00, 3.00 0.00, 0.00 0.00))"
4545
),
4646
])
4747
def test_bbox_from_polygons(bboxes, expected):

tests/unittests/test_util.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,13 @@ def test_wkt2geom(wkt, bounds, expected):
141141
@pytest.mark.parametrize("bbox, expected", [
142142
(
143143
"0.0, 10.0, 30.0, 15.0",
144-
"POLYGON((0.0 10.0, 0.0 15.0, 30.0 15.0, "
145-
"30.0 10.0, 0.0 10.0))"
144+
"POLYGON((0.00 10.00, 0.00 15.00, 30.00 15.00, "
145+
"30.00 10.00, 0.00 10.00))"
146146
),
147147
(
148148
"-10.0, 10.0, 30.0, 15.0",
149-
"POLYGON((-10.0 10.0, -10.0 15.0, 30.0 15.0, "
150-
"30.0 10.0, -10.0 10.0))"
151-
),
152-
(
153-
"25.0815883093, 62.1306897126, 27.1935425597, 63.129387237",
154-
"POLYGON((25.0815883093 62.1306897126, 25.0815883093 63.129387237, "
155-
"27.1935425597 63.129387237, 27.1935425597 62.1306897126, "
156-
"25.0815883093 62.1306897126))"
149+
"POLYGON((-10.00 10.00, -10.00 15.00, 30.00 15.00, "
150+
"30.00 10.00, -10.00 10.00))"
157151
)
158152
])
159153
def test_bbox2wktpolygon(bbox, expected):

0 commit comments

Comments
 (0)