Skip to content

Commit 07f6d02

Browse files
Merge branch 'main' of https://github.com/geo-engine/geoengine-python into wfs-error-check
2 parents a5b5686 + 8c8b610 commit 07f6d02

File tree

4 files changed

+73
-62
lines changed

4 files changed

+73
-62
lines changed

geoengine/workflow.py

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ def __get_wfs_url(self, bbox: QueryRectangle) -> str:
120120
version="2.0.0",
121121
request='GetFeature',
122122
outputFormat='application/json',
123-
typeNames=f'registry:{self.__workflow_id}',
123+
typeNames=f'{self.__workflow_id}',
124124
bbox=bbox.bbox_str,
125125
time=bbox.time_str,
126126
srsName=bbox.srs,
127127
queryResolution=f'{bbox.resolution[0]},{bbox.resolution[1]}'
128128
)
129129

130130
wfs_url = req.Request(
131-
'GET', url=f'{session.server_url}/wfs', params=params).prepare().url
131+
'GET', url=f'{session.server_url}/wfs/{self.__workflow_id}', params=params).prepare().url
132132

133133
debug(f'WFS URL:\n{wfs_url}')
134134

@@ -206,7 +206,7 @@ def plot_image(self, bbox: QueryRectangle, ax: plt.Axes = None, timeout=3600) ->
206206

207207
session = get_session()
208208

209-
wms_url = f'{session.server_url}/wms'
209+
wms_url = f'{session.server_url}/wms/{str(self)}'
210210

211211
def srs_to_projection(srs: str) -> ccrs.Projection:
212212
fallback = ccrs.PlateCarree()
@@ -225,7 +225,6 @@ def srs_to_projection(srs: str) -> ccrs.Projection:
225225

226226
wms = WebMapService(wms_url,
227227
version='1.3.0',
228-
xml=self.__faux_capabilities(wms_url, str(self), bbox),
229228
auth=Authentication(auth_delegate=session.requests_bearer_auth()),
230229
timeout=timeout)
231230

@@ -312,7 +311,7 @@ def __wms_get_map_request(self,
312311

313312
return req.Request(
314313
'GET',
315-
url=f'{session.server_url}/wms',
314+
url=f'{session.server_url}/wms/{str(self)}',
316315
params=params,
317316
headers=session.auth_header
318317
).prepare()
@@ -327,56 +326,6 @@ def wms_get_map_curl(self, bbox: QueryRectangle, colorizer_min_max: Tuple[float,
327326
headers = " -H ".join(headers)
328327
return command.format(method=wms_request.method, headers=headers, uri=wms_request.url)
329328

330-
@classmethod
331-
def __faux_capabilities(cls, wms_url: str, layer_name: str, bbox: QueryRectangle) -> str:
332-
'''Create an XML file with faux capabilities to list the layer with `layer_name`'''
333-
334-
return '''
335-
<WMS_Capabilities xmlns="http://www.opengis.net/wms" xmlns:sld="http://www.opengis.net/sld" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.3.0" xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd">
336-
<Service>
337-
<Name>WMS</Name>
338-
<Title>Geo Engine WMS</Title>
339-
</Service>
340-
<Capability>
341-
<Request>
342-
<GetCapabilities>
343-
<Format>text/xml</Format>
344-
<DCPType>
345-
<HTTP>
346-
<Get>
347-
<OnlineResource xlink:href="{wms_url}"/>
348-
</Get>
349-
</HTTP>
350-
</DCPType>
351-
</GetCapabilities>
352-
<GetMap>
353-
<Format>image/png</Format>
354-
<DCPType>
355-
<HTTP>
356-
<Get>
357-
<OnlineResource xlink:href="{wms_url}"/>
358-
</Get>
359-
</HTTP>
360-
</DCPType>
361-
</GetMap>
362-
</Request>
363-
<Exception>
364-
<Format>XML</Format>
365-
<Format>INIMAGE</Format>
366-
<Format>BLANK</Format>
367-
</Exception>
368-
<Layer queryable="1">
369-
<Name>{layer_name}</Name>
370-
<Title>{layer_name}</Title>
371-
<CRS>{crs}</CRS>
372-
<BoundingBox CRS="EPSG:4326" minx="-90.0" miny="-180.0" maxx="90.0" maxy="180.0"/>
373-
</Layer>
374-
</Capability>
375-
</WMS_Capabilities>
376-
'''.format(wms_url=wms_url,
377-
layer_name=layer_name,
378-
crs=bbox.srs)
379-
380329
def plot_chart(self, bbox: QueryRectangle) -> VegaLite:
381330
'''
382331
Query a workflow and return the plot chart result as a vega plot
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<WMS_Capabilities xmlns="http://www.opengis.net/wms"
2+
xmlns:sld="http://www.opengis.net/sld"
3+
xmlns:xlink="http://www.w3.org/1999/xlink"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.3.0" xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd">
5+
<Service>
6+
<Name>WMS</Name>
7+
<Title>Geo Engine WMS</Title>
8+
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://localhost"/>
9+
</Service>
10+
<Capability>
11+
<Request>
12+
<GetCapabilities>
13+
<Format>text/xml</Format>
14+
<DCPType>
15+
<HTTP>
16+
<Get>
17+
<OnlineResource xlink:href="http://mock-instance/wms/5b9508a8-bd34-5a1c-acd6-75bb832d2d38"/>
18+
</Get>
19+
</HTTP>
20+
</DCPType>
21+
</GetCapabilities>
22+
<GetMap>
23+
<Format>image/png</Format>
24+
<DCPType>
25+
<HTTP>
26+
<Get>
27+
<OnlineResource xlink:href="http://mock-instance/wms/5b9508a8-bd34-5a1c-acd6-75bb832d2d38"/>
28+
</Get>
29+
</HTTP>
30+
</DCPType>
31+
</GetMap>
32+
</Request>
33+
<Exception>
34+
<Format>XML</Format>
35+
<Format>INIMAGE</Format>
36+
<Format>BLANK</Format>
37+
</Exception>
38+
<Layer queryable="1">
39+
<Name>5b9508a8-bd34-5a1c-acd6-75bb832d2d38</Name>
40+
<Title>Workflow 5b9508a8-bd34-5a1c-acd6-75bb832d2d38</Title>
41+
<EX_GeographicBoundingBox>
42+
<westBoundLongitude>-180</westBoundLongitude>
43+
<eastBoundLongitude>180</eastBoundLongitude>
44+
<southBoundLatitude>-90</southBoundLatitude>
45+
<northBoundLatitude>90</northBoundLatitude>
46+
</EX_GeographicBoundingBox>
47+
<BoundingBox CRS="EPSG:4326" minx="-90.0" miny="-180.0" maxx="90.0" maxy="180.0"/>
48+
</Layer>
49+
</Capability>
50+
</WMS_Capabilities>

tests/test_wfs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_geopandas(self):
5555
},
5656
request_headers={'Authorization': 'Bearer e327d9c3-a4f3-4bd7-a5e1-30b26cae8064'})
5757

58-
m.get('http://mock-instance/wfs',
58+
m.get('http://mock-instance/wfs/956d3656-2d14-5951-96a0-f962b92371cd',
5959
json={
6060
"type": "FeatureCollection",
6161
"features": [
@@ -286,7 +286,7 @@ def test_geopandas(self):
286286
self.assertEqual(
287287
# pylint: disable=line-too-long
288288
wfs_request.url,
289-
"http://mock-instance/wfs?service=WFS&version=2.0.0&request=GetFeature&outputFormat=application%2Fjson&typeNames=registry%3A956d3656-2d14-5951-96a0-f962b92371cd&bbox=-60.0%2C5.0%2C61.0%2C6.0&time=2014-04-01T12%3A00%3A00.000%2B00%3A00&srsName=EPSG%3A4326&queryResolution=0.1%2C0.1"
289+
"http://mock-instance/wfs/956d3656-2d14-5951-96a0-f962b92371cd?service=WFS&version=2.0.0&request=GetFeature&outputFormat=application%2Fjson&typeNames=956d3656-2d14-5951-96a0-f962b92371cd&bbox=-60.0%2C5.0%2C61.0%2C6.0&time=2014-04-01T12%3A00%3A00.000%2B00%3A00&srsName=EPSG%3A4326&queryResolution=0.1%2C0.1"
290290
)
291291

292292
expected_df = gpd.GeoDataFrame(
@@ -401,7 +401,7 @@ def test_wfs_curl(self):
401401
self.assertEqual(
402402
# pylint: disable=line-too-long
403403
wfs_curl,
404-
"""curl -X GET -H "Authorization: Bearer e327d9c3-a4f3-4bd7-a5e1-30b26cae8064" 'http://mock-instance/wfs?service=WFS&version=2.0.0&request=GetFeature&outputFormat=application%2Fjson&typeNames=registry%3A956d3656-2d14-5951-96a0-f962b92371cd&bbox=-60.0%2C5.0%2C61.0%2C6.0&time=2014-04-01T12%3A00%3A00.000%2B00%3A00&srsName=EPSG%3A4326&queryResolution=0.1%2C0.1'"""
404+
"""curl -X GET -H "Authorization: Bearer e327d9c3-a4f3-4bd7-a5e1-30b26cae8064" 'http://mock-instance/wfs/956d3656-2d14-5951-96a0-f962b92371cd?service=WFS&version=2.0.0&request=GetFeature&outputFormat=application%2Fjson&typeNames=956d3656-2d14-5951-96a0-f962b92371cd&bbox=-60.0%2C5.0%2C61.0%2C6.0&time=2014-04-01T12%3A00%3A00.000%2B00%3A00&srsName=EPSG%3A4326&queryResolution=0.1%2C0.1'"""
405405
)
406406

407407
def test_wfs_error(self):

tests/test_wms.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ def test_ndvi(self):
5151
m.get('http://epsg.io/4326.gml?download', body=epsg4326_gml)
5252

5353
# Unfortunately, we need a separate library to catch the request from the WMS call
54+
with open("tests/responses/wms_capabilities.xml", "r", encoding="utf-8") as wms_capabilities:
55+
m.get(
56+
# pylint: disable=line-too-long
57+
'http://mock-instance/wms/5b9508a8-bd34-5a1c-acd6-75bb832d2d38?service=WMS&request=GetCapabilities&version=1.3.0',
58+
text=wms_capabilities.read())
59+
5460
with open("tests/responses/wms-ndvi.png", "rb") as wms_ndvi:
5561
responses.add(
5662
# pylint: disable=line-too-long
5763
'GET',
58-
'http://mock-instance/wms?service=WMS&version=1.3.0&request=GetMap&layers=5b9508a8-bd34-5a1c-acd6-75bb832d2d38&styles=&width=620&height=310&crs=EPSG:4326&bbox=-90.0,-180.0,90.0,180.0&format=image/png&transparent=FALSE&bgcolor=0xFFFFFF&exceptions=XML&time=2014-04-01T12%3A00%3A00.000%2B00%3A00',
64+
'http://mock-instance/wms/5b9508a8-bd34-5a1c-acd6-75bb832d2d38?service=WMS&version=1.3.0&request=GetMap&layers=5b9508a8-bd34-5a1c-acd6-75bb832d2d38&styles=&width=620&height=310&crs=EPSG:4326&bbox=-90.0,-180.0,90.0,180.0&format=image/png&transparent=FALSE&bgcolor=0xFFFFFF&exceptions=XML&time=2014-04-01T12%3A00%3A00.000%2B00%3A00',
5965
match_querystring=True,
6066
body=wms_ndvi.read(),
6167
content_type='image/png'
@@ -93,7 +99,7 @@ def test_ndvi(self):
9399
self.assertEqual(type(ax), cartopy.mpl.geoaxes.GeoAxesSubplot)
94100

95101
# Check requests from the mocker
96-
self.assertEqual(len(m.request_history), 4)
102+
self.assertEqual(len(m.request_history), 5)
97103

98104
workflow_request = m.request_history[1]
99105
self.assertEqual(workflow_request.method, "POST")
@@ -132,9 +138,15 @@ def test_ndvi_image(self):
132138
m.get('http://epsg.io/4326.gml?download', body=epsg4326_gml)
133139

134140
# Unfortunately, we need a separate library to catch the request from the WMS call
141+
with open("tests/responses/wms_capabilities.xml", "r", encoding="utf-8") as wms_capabilities:
142+
m.get(
143+
# pylint: disable=line-too-long
144+
'http://mock-instance/wms/5b9508a8-bd34-5a1c-acd6-75bb832d2d38?service=WMS&request=GetCapabilities&version=1.3.0',
145+
text=wms_capabilities.read())
146+
135147
m.get(
136148
# pylint: disable=line-too-long
137-
'http://mock-instance/wms?service=WMS&version=1.3.0&request=GetMap&layers=5b9508a8-bd34-5a1c-acd6-75bb832d2d38&time=2014-04-01T12%3A00%3A00.000%2B00%3A00&crs=EPSG%3A4326&bbox=-90.0%2C-180.0%2C90.0%2C180.0&width=200&height=100&format=image%2Fpng&styles=custom%3A%7B%22type%22%3A+%22linearGradient%22%2C+%22breakpoints%22%3A+%5B%7B%22value%22%3A+0%2C+%22color%22%3A+%5B0%2C+0%2C+0%2C+255%5D%7D%2C+%7B%22value%22%3A+255%2C+%22color%22%3A+%5B255%2C+255%2C+255%2C+255%5D%7D%5D%2C+%22noDataColor%22%3A+%5B0%2C+0%2C+0%2C+0%5D%2C+%22defaultColor%22%3A+%5B0%2C+0%2C+0%2C+0%5D%7D',
149+
'http://mock-instance/wms/5b9508a8-bd34-5a1c-acd6-75bb832d2d38?service=WMS&version=1.3.0&request=GetMap&layers=5b9508a8-bd34-5a1c-acd6-75bb832d2d38&time=2014-04-01T12%3A00%3A00.000%2B00%3A00&crs=EPSG%3A4326&bbox=-90.0%2C-180.0%2C90.0%2C180.0&width=200&height=100&format=image%2Fpng&styles=custom%3A%7B%22type%22%3A+%22linearGradient%22%2C+%22breakpoints%22%3A+%5B%7B%22value%22%3A+0%2C+%22color%22%3A+%5B0%2C+0%2C+0%2C+255%5D%7D%2C+%7B%22value%22%3A+255%2C+%22color%22%3A+%5B255%2C+255%2C+255%2C+255%5D%7D%5D%2C+%22noDataColor%22%3A+%5B0%2C+0%2C+0%2C+0%5D%2C+%22defaultColor%22%3A+%5B0%2C+0%2C+0%2C+0%5D%7D',
138150
body=ndvi_png,
139151
)
140152

@@ -301,7 +313,7 @@ def test_wms_url(self):
301313
self.assertEqual(
302314
# pylint: disable=line-too-long
303315
wms_curl,
304-
"""curl -X GET -H "Authorization: Bearer c4983c3e-9b53-47ae-bda9-382223bd5081" 'http://mock-instance/wms?service=WMS&version=1.3.0&request=GetMap&layers=5b9508a8-bd34-5a1c-acd6-75bb832d2d38&time=2014-04-01T12%3A00%3A00.000%2B00%3A00&crs=EPSG%3A4326&bbox=-90.0%2C-180.0%2C90.0%2C180.0&width=360&height=180&format=image%2Fpng&styles='"""
316+
"""curl -X GET -H "Authorization: Bearer c4983c3e-9b53-47ae-bda9-382223bd5081" 'http://mock-instance/wms/5b9508a8-bd34-5a1c-acd6-75bb832d2d38?service=WMS&version=1.3.0&request=GetMap&layers=5b9508a8-bd34-5a1c-acd6-75bb832d2d38&time=2014-04-01T12%3A00%3A00.000%2B00%3A00&crs=EPSG%3A4326&bbox=-90.0%2C-180.0%2C90.0%2C180.0&width=360&height=180&format=image%2Fpng&styles='"""
305317
)
306318

307319
def test_result_descriptor(self):

0 commit comments

Comments
 (0)