Skip to content

Commit 4a5578b

Browse files
committed
Update intersect.py
1 parent e2e90aa commit 4a5578b

File tree

7 files changed

+37
-25
lines changed

7 files changed

+37
-25
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,10 @@ jobs:
5454
pytest tests/test_sitemap_process.py
5555
pytest tests/test_sparql_provider.py
5656
pytest tests/test_xml_formatter.py
57+
- name: Failed Tests
58+
if: failure()
59+
run: |
60+
echo "Tests failed. Collecting logs..."
61+
docker ps -a
62+
docker logs pygeoapi-plugins-pygeoapi-1
63+
pip3 freeze

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ ADD . /pygeoapi_plugins
77
RUN /venv/bin/python3 -m pip install -r /pygeoapi_plugins/requirements.txt \
88
&& /venv/bin/python3 -m pip install -e /pygeoapi_plugins
99

10-
RUN /venv/bin/python3 -m pip install GDAL>=3.12.0
11-
1210
ENTRYPOINT [ "/entrypoint.sh" ]

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ services:
33
build:
44
context: .
55
ports:
6-
- 5000:80
6+
- 5555:80

docker/pygeoapi.config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ server:
22
bind:
33
host: 0.0.0.0
44
port: 80
5-
url: http://localhost:5000
5+
url: http://localhost:5555
66
mimetype: application/json; charset=UTF-8
77
encoding: utf-8
88
gzip: false

pygeoapi_plugins/process/intersect.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
from osgeo import gdal, ogr
3333
from typing import Tuple
3434
from zipfile import ZipFile
35+
from pyproj import CRS
3536

36-
37+
from pygeoapi.crs import DEFAULT_CRS, transform_bbox
3738
from pygeoapi.config import get_config
3839
from pygeoapi.plugin import load_plugin
3940
from pygeoapi.process.base import BaseProcessor, ProcessorExecuteError
@@ -226,20 +227,19 @@ def get_layer(
226227

227228
ds = gdal.OpenEx(url, gdal.OF_VECTOR)
228229
if ds is None:
229-
raise ProcessorExecuteError("GDAL could not open feature.")
230+
raise ProcessorExecuteError('GDAL could not open feature.')
230231

231232
layer = ds.GetLayer()
232-
(minx, maxx, miny, maxy) = ds.GetExtentWGS84LongLat()
233-
233+
srs = layer.GetSpatialRef()
234234
elif file:
235235
if not isinstance(file, bytes):
236236
file = bytes(file, 'utf-8')
237237

238238
# Use /vsistdin/ to read bytes in-memory
239239
if file[:2] == b'PK':
240-
ext = ".zip"
240+
ext = '.zip'
241241
elif file[:4] == b'PAR1':
242-
ext = ".parquet"
242+
ext = '.parquet'
243243
else:
244244
ext = ''
245245

@@ -258,19 +258,26 @@ def get_layer(
258258

259259
ds = gdal.OpenEx(tmp_path, gdal.OF_VECTOR)
260260
if ds is None:
261-
raise ProcessorExecuteError("GDAL could not open feature from bytes (temp file fallback).") # noqa
261+
raise ProcessorExecuteError('GDAL could not open feature from bytes (temp file fallback).') # noqa
262262

263263
layer = ds.GetLayer()
264-
(minx, maxx, miny, maxy) = ds.GetExtentWGS84LongLat()
264+
srs = layer.GetSpatialRef()
265265
else:
266-
raise ProcessorExecuteError("No input provided.")
266+
raise ProcessorExecuteError('No input provided.')
267267

268268
union = ogr.Geometry(ogr.wkbGeometryCollection)
269269
for feat in layer:
270270
geom = feat.GetGeometryRef()
271271
union.AddGeometry(geom)
272272

273+
(minx, maxx, miny, maxy) = layer.GetExtent()
273274
bbox = (minx, miny, maxx, maxy)
275+
276+
if srs:
277+
bbox = transform_bbox(
278+
bbox, CRS(srs.ExportToWkt()), CRS('EPSG:4326')
279+
)
280+
274281
return (union, bbox)
275282

276283
def __repr__(self):

tests/test_intersect_process.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,27 @@ def test_execute_raises_when_missing_collection(process_def, bytes_data):
7878
[
7979
(
8080
"http://geoconnex.us/ref/states/08",
81-
(-109.060253, 36.992426, -102.041524, 41.003443999999995),
81+
[-109.060253, 36.992426, -102.041524, 41.003443999999995],
8282
contextlib.nullcontext(),
8383
),
8484
(
8585
"https://reference.geoconnex.us/collections/states/items",
86-
(-179.148909, -14.548699, 179.77847011250077, 71.365162),
86+
[-179.148909, -14.548699, 179.77847011250077, 71.365162],
8787
contextlib.nullcontext(),
8888
),
8989
(
9090
"https://www.hydroshare.org/resource/3295a17b4cc24d34bd6a5c5aaf753c50/data/contents/hu02.gpkg",
91-
(-179.2294679909685, -14.42442, 179.85648417282215, 71.439451),
91+
[-179.2294676, -14.42442, 179.8564841, 71.439451],
9292
contextlib.nullcontext(),
9393
),
9494
(
9595
"https://github.com/geopython/pygeoapi/raw/refs/heads/master/tests/data/dutch_addresses_shape_28992.zip",
96-
(
96+
[
97+
52.04308374228452,
9798
5.670269218772358,
98-
52.04259660083967,
99+
52.12327124702764,
99100
5.829358202203319,
100-
52.12375952869009,
101-
),
101+
],
102102
contextlib.nullcontext(),
103103
),
104104
(
@@ -109,16 +109,16 @@ def test_execute_raises_when_missing_collection(process_def, bytes_data):
109109
("https://example.com", None, pytest.raises(Exception)), # Error case - bad URL
110110
],
111111
)
112-
def test_get_bbox_partial(process_def, url, bounds, ctx):
112+
def test_get_bbox(process_def, url, bounds, ctx):
113113
proc = intersect.IntersectionProcessor(process_def)
114114
with ctx:
115115
_, bbox = proc.get_layer(url=url, as_bbox=True)
116-
assert bbox == bounds
116+
assert pytest.approx(bbox) == bounds
117117

118118
with ctx:
119119
content = requests.get(url).content
120-
_, bbox, _ = proc.get_layer(file=content, as_bbox=True)
121-
assert bbox == bounds
120+
_, bbox= proc.get_layer(file=content, as_bbox=True)
121+
assert pytest.approx(bbox) == bounds
122122

123123

124124
@pytest.mark.parametrize(

tests/test_sitemap_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
from pygeoapi.util import url_join
3737

38-
PYGEOAPI_URL = 'http://localhost:5000'
38+
PYGEOAPI_URL = 'http://localhost:5555'
3939
PROCESS_URL = url_join(PYGEOAPI_URL, 'processes/sitemap-generator/execution')
4040
HTTP = Session()
4141

0 commit comments

Comments
 (0)