-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_wms.py
108 lines (93 loc) · 3.59 KB
/
utils_wms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
# Copyright notice
# --------------------------------------------------------------------
# Copyright (C) 2024 Deltares
# Gerrit Hendriksen ([email protected])
# Ioanna Micha (Ioanna Micha)
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------
#
# This tool is part of <a href="http://www.OpenEarth.eu">OpenEarthTools</a>.
# OpenEarthTools is an online collaboration to share and manage data and
# programming tools in an open source, version controlled environment.
# Sign up to recieve regular updates of this function, and to contribute
# your own tools.
from owslib.wms import WebMapService
from owslib.util import ServiceException
def checkwfsfeature(wms, layer, layernameprinting=False):
if layernameprinting:
print(f"testing {layer}")
lbbox = wms.contents[layer].boundingBox[0:4]
lcrs = wms.contents[layer].boundingBox[-1]
try:
response = wms.getfeatureinfo(
layers=[layer],
srs=lcrs,
bbox=lbbox,
size=(10, 10),
format="image/jpeg",
query_layers=[layer],
info_format="text/html",
xy=(5, 5),
)
jf = response.read()
if "ServiceException code" in str(jf):
print("getfeaturinfo failed for ", layer)
except TimeoutError as e:
print(f"WMS server timed out for layer {layer} {e}")
except ServiceException as e:
print(f"WMS server error for layer {layer} {e}")
def checkgetmap(wms, layer):
lbbox = wms.contents[layer].boundingBox[0:4]
lcrs = wms.contents[layer].boundingBox[-1]
try:
response = wms.getmap(
layers=[layer],
srs=lcrs,
bbox=lbbox,
size=(10, 10),
format="image/jpeg",
)
jf = response.read()
if "ServiceException code" in str(jf):
print("getfeaturinfo failed for ", layer)
except TimeoutError as e:
print(f"WMS timed out for layer {layer} {e}")
except ServiceException as e:
print(f"WMS error for layer {layer} {e}")
except Exception as e:
print(f"General exception for layer {layer} {e}")
def connecttowms(url):
try:
wms = WebMapService(url, version="1.3.0", timeout=180)
layers = wms.contents
print("connection succesful")
return wms, layers
except ServiceException as e:
assert f"WMS server error for {url} {e}"
def __main__():
urls = [
"https://rwsprojectarchief.openearth.nl/geoserver/ows",
"https://marineprojects.openearth.nl/geoserver/ows",
"https://datahuiswadden.openearth.nl/geoserver/ows",
"https://coastalhazardwheel.avi.deltares.nl/geoserver/ows",
"https://deltaresdata.openearth.eu/geoserver/ows",
]
url = urls[4]
print(f"exploring {url}")
wms, layers = connecttowms(url)
for layer in layers:
# checklayer(wms, layer)
checkgetmap(wms, layer)