Created
April 3, 2011 22:17
-
-
Save wwaites/900878 to your computer and use it in GitHub Desktop.
is this host a wms or a csw service?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from owslib import csw | |
def iscsw(url): | |
success = False | |
try: | |
s = csw.CatalogueServiceWeb(url) | |
success = isinstance(s.operations, list) and len(s.operations) > 0 | |
except: | |
pass | |
if not success and "?" in url: | |
parts = url.split("?", 1) | |
url = parts[0] | |
success = iscsw(url) | |
if not success and not url.endswith("/csw"): | |
parts = url.split("?", 1) | |
url = parts[0] | |
url = url.rstrip("/") + "/csw" | |
success = iscsw(url) | |
return success | |
if __name__ == '__main__': | |
assert iscsw("http://www.nationaalgeoregister.nl/geonetwork/srv/eng/csw") | |
assert iscsw("http://www.nationaalgeoregister.nl/geonetwork/srv/eng/") | |
assert not iscsw("http://grid1.wdcb.ru/cgi-bin/mapserv?map=/var/www/html/mapFiles/maingis.map") | |
assert not iscsw("http://www.google.com") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from owslib import wms | |
def iswms(url): | |
try: | |
s = wms.WebMapService(url) | |
return isinstance(s.contents, dict) and s.contents != {} | |
except: | |
pass | |
return False | |
if __name__ == '__main__': | |
assert iswms("http://grid1.wdcb.ru/cgi-bin/mapserv?map=/var/www/html/mapFiles/maingis.map") | |
assert not iswms("http://www.google.com/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment