Skip to content

Instantly share code, notes, and snippets.

@wwaites
Created April 3, 2011 22:17
Show Gist options
  • Save wwaites/900878 to your computer and use it in GitHub Desktop.
Save wwaites/900878 to your computer and use it in GitHub Desktop.
is this host a wms or a csw service?
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")
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