|
28 | 28 | # =================================================================
|
29 | 29 |
|
30 | 30 | import logging
|
| 31 | +from owslib.wms import WebMapService as WMS |
| 32 | +from owslib.wfs import WebFeatureService as WFS |
| 33 | +from owslib.ogcapi.features import Features as OAPIF |
| 34 | +from owslib.ogcapi.coverages import Coverages as OAPIC |
| 35 | +from owslib.ogcapi.records import Records as OAPIR |
| 36 | +from owslib.wcs import WebCoverageService as WCS |
| 37 | +from owslib.csw import CatalogueServiceWeb as CSW |
| 38 | +from owslib.wps import WebProcessingService as WPS |
| 39 | +from owslib.sos import SensorObservationService as SOS |
| 40 | +from owslib.wmts import WebMapTileService as WMTS |
31 | 41 |
|
32 |
| -LOGGER = logging.getLogger(__name__) |
33 |
| - |
34 |
| -__version__ = '0.2-dev' |
35 |
| - |
| 42 | +__version__ = '1.1' |
36 | 43 |
|
37 | 44 | def inurl(needles, haystack, position='any'):
|
38 | 45 | """convenience function to make string.find return bool"""
|
@@ -60,7 +67,7 @@ def inurl(needles, haystack, position='any'):
|
60 | 67 | return False
|
61 | 68 |
|
62 | 69 |
|
63 |
| -def sniff_link(url): |
| 70 | +def sniff_link(url, extended=False, first=True): |
64 | 71 | """performs basic heuristics to detect what the URL is"""
|
65 | 72 |
|
66 | 73 | protocol = None
|
@@ -105,6 +112,105 @@ def sniff_link(url):
|
105 | 112 | elif inurl(['kml', 'kmz'], link, 'end'):
|
106 | 113 | protocol = 'OGC:KML'
|
107 | 114 | else:
|
108 |
| - LOGGER.info('No link type detected') |
| 115 | + if (extended): |
| 116 | + protocol = [] |
| 117 | + #for each servicetype, head out to see if it is valid |
| 118 | + try: |
| 119 | + wms = WMS(link) |
| 120 | + if (wms.identification.type == 'OGC:WMS'): |
| 121 | + if (first): |
| 122 | + return wms.identification.type |
| 123 | + else: |
| 124 | + protocol.append(wms.identification.type) |
| 125 | + except: |
| 126 | + pass # No need to log? |
| 127 | + try: |
| 128 | + wmts = WMTS(link) |
| 129 | + if (wmts.identification.type == 'OGC:WMTS'): |
| 130 | + if (first): |
| 131 | + return wmts.identification.type |
| 132 | + else: |
| 133 | + protocol.append(wmts.identification.type) |
| 134 | + except: |
| 135 | + pass |
| 136 | + try: |
| 137 | + wps = WPS(link, verbose=False, skip_caps=True) |
| 138 | + wps.getcapabilities() |
| 139 | + if (wps.identification.type == 'OGC:WPS'): |
| 140 | + if (first): |
| 141 | + return wps.identification.type |
| 142 | + else: |
| 143 | + protocol.append(wps.identification.type) |
| 144 | + except: |
| 145 | + pass |
| 146 | + try: |
| 147 | + wfs = WFS(link) |
| 148 | + if (wfs.identification.type == 'OGC:WFS'): |
| 149 | + if (first): |
| 150 | + return wfs.identification.type |
| 151 | + else: |
| 152 | + protocol.append(wfs.identification.type) |
| 153 | + except: |
| 154 | + pass |
| 155 | + try: |
| 156 | + csw = CSW('http://geodiscover.cgdi.ca/wes/serviceManagerCSW/csw') |
| 157 | + if (csw.identification.type == 'OGC:CSW'): |
| 158 | + if (first): |
| 159 | + return csw.identification.type |
| 160 | + else: |
| 161 | + protocol.append(csw.identification.type) |
| 162 | + except: |
| 163 | + pass |
| 164 | + try: |
| 165 | + wcs = WCS(link) |
| 166 | + if (wcs.identification.type == 'OGC:WCS'): |
| 167 | + if (first): |
| 168 | + return wcs.identification.type |
| 169 | + else: |
| 170 | + protocol.append(wcs.identification.type) |
| 171 | + except: |
| 172 | + pass |
| 173 | + try: |
| 174 | + sos = SOS(link) |
| 175 | + if (sos.identification.type == 'OGC:SOS'): |
| 176 | + if (first): |
| 177 | + return sos.identification.type |
| 178 | + else: |
| 179 | + protocol.append(sos.identification.type) |
| 180 | + except: |
| 181 | + pass |
| 182 | + try: |
| 183 | + oapir = OAPIR(link) |
| 184 | + if (oapir.conformance()): |
| 185 | + if (first): |
| 186 | + return "OGCAPI:records" |
| 187 | + else: |
| 188 | + protocol.append("OGCAPI:records") |
| 189 | + except: |
| 190 | + pass |
| 191 | + try: |
| 192 | + oapif = OAPIF(link) |
| 193 | + if (oapir.conformance()): |
| 194 | + if (first): |
| 195 | + return "OGCAPI:features" |
| 196 | + else: |
| 197 | + protocol.append("OGCAPI:features") |
| 198 | + except: |
| 199 | + pass |
| 200 | + try: |
| 201 | + oapic = OAPIC(link) |
| 202 | + if (oapir.conformance()): |
| 203 | + if (first): |
| 204 | + return "OGCAPI:coverages" |
| 205 | + else: |
| 206 | + protocol.append("OGCAPI:coverages") |
| 207 | + except: |
| 208 | + pass |
| 209 | + |
| 210 | + if len(protocol) == 1: |
| 211 | + protocol = protocol[0] |
| 212 | + |
| 213 | + else: |
| 214 | + LOGGER.info('No link type detected') |
109 | 215 |
|
110 | 216 | return protocol
|
0 commit comments