Skip to content

Commit 104807e

Browse files
authored
Fix error for CSV/GeoJSON provider when the bbox parameter has 6 coordinates (#2187)
* Fix error for CSV provider when the bbox parameter has 6 coordinates * Fix error for GeoJSON provider when the bbox parameter has 6 coordinates Fix error for GeoJSON provider when the bbox parameter has 6 coordinates * Add one more test for the CSW provider that uses the same function giving error
1 parent 3029598 commit 104807e

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

pygeoapi/provider/csv_.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# =================================================================
22
#
33
# Authors: Tom Kralidis <[email protected]>
4+
# Francesco Bartoli <[email protected]>
45
#
56
# Copyright (c) 2025 Tom Kralidis
7+
# Copyright (c) 2025 Francesco Bartoli
68
#
79
# Permission is hereby granted, free of charge, to any person
810
# obtaining a copy of this software and associated documentation
@@ -138,6 +140,9 @@ def _load(self, offset=0, limit=10, resulttype='results',
138140

139141
if bbox:
140142
LOGGER.debug('processing bbox parameter')
143+
if len(bbox) > 4:
144+
LOGGER.debug("bbox reduced to 4 elements")
145+
bbox = bbox[:4]
141146
data_ = filter(
142147
lambda f: all(
143148
[self._intersects(f, bbox)]), data_)

pygeoapi/provider/geojson.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ def _load(self, bbox=[], skip_geometry=None, properties=[],
127127
# filter by bbox if set
128128
if bbox:
129129
LOGGER.debug('processing bbox parameter')
130+
if len(bbox) > 4:
131+
LOGGER.debug("bbox reduced to 4 elements")
132+
bbox = bbox[:4]
130133
data['features'] = [f for f in data['features'] if \
131134
self._intersects(f['geometry'], bbox)] # noqa
132135

tests/provider/test_csv__provider.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def test_query(config):
140140
results = p.query(bbox=[-75, 45, -64, 55])
141141
assert len(results['features'][0]['properties']) == 2
142142

143+
results = p.query(bbox=[-75, 45, -64, 55, 0, 0])
144+
assert len(results['features'][0]['properties']) == 2
145+
143146

144147
def test_get_invalid_property(config):
145148
"""Testing query for an invalid property name"""

tests/provider/test_csw_provider.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# =================================================================
22
#
33
# Authors: Tom Kralidis <[email protected]>
4+
# Francesco Bartoli <[email protected]>
45
#
56
# Copyright (c) 2025 Tom Kralidis
7+
# Copyright (c) 2025 Francesco Bartoli
68
#
79
# Permission is hereby granted, free of charge, to any person
810
# obtaining a copy of this software and associated documentation
@@ -109,6 +111,9 @@ def test_query(config):
109111
results = p.query(bbox=[-10, 40, 0, 60])
110112
assert len(results['features']) == 2
111113

114+
results = p.query(bbox=[-10, 40, 0, 60, 0, 0])
115+
assert len(results['features']) == 2
116+
112117
results = p.query(properties=[('title', 'Maecenas enim')])
113118
assert len(results['features']) == 1
114119

tests/provider/test_geojson_provider.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ def test_query(fixture, config):
104104
assert results['numberMatched'] == 1
105105
assert results['numberReturned'] == 1
106106

107+
results = p.query(bbox=[120, 10, 126, 11, 0, 0])
108+
assert len(results['features']) == 1
109+
assert results['numberMatched'] == 1
110+
assert results['numberReturned'] == 1
111+
107112

108113
def test_get(fixture, config):
109114
p = GeoJSONProvider(config)

0 commit comments

Comments
 (0)