def _parse_wms(context, repos, record, identifier): from owslib.wms import WebMapService recobjs = [] serviceobj = repos.dataset() md = WebMapService(record) # generate record of service instance _set(context, serviceobj, 'pycsw:Identifier', identifier) _set(context, serviceobj, 'pycsw:Typename', 'csw:Record') _set(context, serviceobj, 'pycsw:Schema', 'http://www.opengis.net/wms') _set(context, serviceobj, 'pycsw:MdSource', record) _set(context, serviceobj, 'pycsw:InsertDate', util.get_today_and_now()) _set(context, serviceobj, 'pycsw:XML', md.getServiceXML()) _set(context, serviceobj, 'pycsw:AnyText', util.get_anytext(md.getServiceXML())) _set(context, serviceobj, 'pycsw:Type', 'service') _set(context, serviceobj, 'pycsw:Title', md.identification.title) _set(context, serviceobj, 'pycsw:Abstract', md.identification.abstract) _set(context, serviceobj, 'pycsw:Keywords', ','.join(md.identification.keywords)) _set(context, serviceobj, 'pycsw:Creator', md.provider.contact.name) _set(context, serviceobj, 'pycsw:Publisher', md.provider.contact.name) _set(context, serviceobj, 'pycsw:Contributor', md.provider.contact.name) _set(context, serviceobj, 'pycsw:OrganizationName', md.provider.contact.name) _set(context, serviceobj, 'pycsw:AccessConstraints', md.identification.accessconstraints) _set(context, serviceobj, 'pycsw:OtherConstraints', md.identification.fees) _set(context, serviceobj, 'pycsw:Source', record) _set(context, serviceobj, 'pycsw:Format', md.identification.type) for c in md.contents: if md.contents[c].parent is None: bbox = md.contents[c].boundingBoxWGS84 tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, serviceobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) break _set(context, serviceobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326') _set(context, serviceobj, 'pycsw:DistanceUOM', 'degrees') _set(context, serviceobj, 'pycsw:ServiceType', md.identification.type) _set(context, serviceobj, 'pycsw:ServiceTypeVersion', md.identification.version) _set(context, serviceobj, 'pycsw:Operation', ','.join([d.name for d in md.operations])) _set(context, serviceobj, 'pycsw:OperatesOn', ','.join(list(md.contents))) _set(context, serviceobj, 'pycsw:CouplingType', 'tight') recobjs.append(serviceobj) # generate record foreach layer LOGGER.debug('Harvesting %d WMS layers' % len(md.contents)) for layer in md.contents: recobj = repos.dataset() identifier2 = '%s-%s' % (identifier, md.contents[layer].name) _set(context, recobj, 'pycsw:Identifier', identifier2) _set(context, recobj, 'pycsw:Typename', 'csw:Record') _set(context, recobj, 'pycsw:Schema', 'http://www.opengis.net/wms') _set(context, recobj, 'pycsw:MdSource', record) _set(context, recobj, 'pycsw:InsertDate', util.get_today_and_now()) _set(context, recobj, 'pycsw:XML', md.getServiceXML()) _set(context, recobj, 'pycsw:AnyText', util.get_anytext(md._capabilities)) _set(context, recobj, 'pycsw:Type', 'dataset') _set(context, recobj, 'pycsw:ParentIdentifier', identifier) _set(context, recobj, 'pycsw:Title', md.contents[layer].title) _set(context, recobj, 'pycsw:Abstract', md.contents[layer].abstract) _set(context, recobj, 'pycsw:Keywords', ','.join(md.contents[layer].keywords)) bbox = md.contents[layer].boundingBoxWGS84 if bbox is not None: tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) _set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326') _set(context, recobj, 'pycsw:Denominator', 'degrees') else: bbox = md.contents[layer].boundingBox if bbox: tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) _set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:%s' % \ bbox[-1].split(':')[1]) recobjs.append(recobj) return recobjs
def _parse_wms(context, repos, record, identifier): from owslib.wms import WebMapService recobjs = [] serviceobj = repos.dataset() md = WebMapService(record) # generate record of service instance _set(context, serviceobj, 'pycsw:Identifier', identifier) _set(context, serviceobj, 'pycsw:Typename', 'csw:Record') _set(context, serviceobj, 'pycsw:Schema', 'http://www.opengis.net/wms') _set(context, serviceobj, 'pycsw:MdSource', record) _set(context, serviceobj, 'pycsw:InsertDate', util.get_today_and_now()) _set(context, serviceobj, 'pycsw:XML', md.getServiceXML()) _set(context, serviceobj, 'pycsw:AnyText', util.get_anytext(md.getServiceXML())) _set(context, serviceobj, 'pycsw:Type', 'service') _set(context, serviceobj, 'pycsw:Title', md.identification.title) _set(context, serviceobj, 'pycsw:Abstract', md.identification.abstract) _set(context, serviceobj, 'pycsw:Keywords', ','.join(md.identification.keywords)) _set(context, serviceobj, 'pycsw:Creator', md.provider.contact.name) _set(context, serviceobj, 'pycsw:Publisher', md.provider.contact.name) _set(context, serviceobj, 'pycsw:Contributor', md.provider.contact.name) _set(context, serviceobj, 'pycsw:OrganizationName', md.provider.contact.name) _set(context, serviceobj, 'pycsw:AccessConstraints', md.identification.accessconstraints) _set(context, serviceobj, 'pycsw:OtherConstraints', md.identification.fees) _set(context, serviceobj, 'pycsw:Source', record) _set(context, serviceobj, 'pycsw:Format', md.identification.type) for c in md.contents: if md.contents[c].parent is None: bbox = md.contents[c].boundingBoxWGS84 tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, serviceobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) break _set(context, serviceobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326') _set(context, serviceobj, 'pycsw:DistanceUOM', 'degrees') _set(context, serviceobj, 'pycsw:ServiceType', md.identification.type) _set(context, serviceobj, 'pycsw:ServiceTypeVersion', md.identification.version) _set(context, serviceobj, 'pycsw:Operation', ','.join([d.name for d in md.operations])) _set(context, serviceobj, 'pycsw:OperatesOn', ','.join(list(md.contents))) _set(context, serviceobj, 'pycsw:CouplingType', 'tight') links = [ '%s,OGC-WMS Web Map Service,OGC:WMS,%s' % (identifier, md.url), '%s,OGC-WMS Capabilities service (ver 1.1.1),OGC:WMS-1.1.1-http-get-capabilities,%s' % (identifier, build_get_url(md.url, {'service': 'WMS', 'version': '1.1.1', 'request': 'GetCapabilities'})), ] _set(context, serviceobj, 'pycsw:Links', '^'.join(links)) recobjs.append(serviceobj) # generate record foreach layer LOGGER.debug('Harvesting %d WMS layers' % len(md.contents)) for layer in md.contents: recobj = repos.dataset() identifier2 = '%s-%s' % (identifier, md.contents[layer].name) _set(context, recobj, 'pycsw:Identifier', identifier2) _set(context, recobj, 'pycsw:Typename', 'csw:Record') _set(context, recobj, 'pycsw:Schema', 'http://www.opengis.net/wms') _set(context, recobj, 'pycsw:MdSource', record) _set(context, recobj, 'pycsw:InsertDate', util.get_today_and_now()) _set(context, recobj, 'pycsw:XML', md.getServiceXML()) _set(context, recobj, 'pycsw:AnyText', util.get_anytext(md._capabilities)) _set(context, recobj, 'pycsw:Type', 'dataset') _set(context, recobj, 'pycsw:ParentIdentifier', identifier) _set(context, recobj, 'pycsw:Title', md.contents[layer].title) _set(context, recobj, 'pycsw:Abstract', md.contents[layer].abstract) _set(context, recobj, 'pycsw:Keywords', ','.join(md.contents[layer].keywords)) bbox = md.contents[layer].boundingBoxWGS84 if bbox is not None: tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) _set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326') _set(context, recobj, 'pycsw:Denominator', 'degrees') else: bbox = md.contents[layer].boundingBox if bbox: tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) _set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:%s' % \ bbox[-1].split(':')[1]) params = { 'service': 'WMS', 'version': '1.1.1', 'request': 'GetMap', 'layers': md.contents[layer].name, 'format': 'image/png', 'height': '200', 'width': '200', 'srs': 'EPSG:4326', 'bbox': '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]), 'styles': '' } links = [ '%s,Web image thumbnail (URL),WWW:LINK-1.0-http--image-thumbnail,%s' % (md.contents[layer].name, build_get_url(md.url, params)) ] _set(context, recobj, 'pycsw:Links', '^'.join(links)) recobjs.append(recobj) return recobjs
import pandas from owslib.wms import WebMapService import simplekml import xml.etree.ElementTree as ET import os.path as osp import fnmatch, re layer_table_path = 'https://raw.githubusercontent.com/Envirometrix/LandGISmaps/master/tables/LandGIS_tables_landgis_layers.csv' df = pandas.read_table(layer_table_path,sep=',') df = df.loc[df.layer_public_download==1,:] wms = WebMapService('https://geoserver.opengeohub.org/landgisgeoserver/wms', version='1.3.0') wms_layers = list(wms.contents) wms_xml = ET.fromstring(wms.getServiceXML()) folder_style_radio = simplekml.Style() folder_style_radio.liststyle.listitemtype = simplekml.ListItemType.radiofolder link_style_hidden = simplekml.Style() link_style_hidden.liststyle.listitemtype = simplekml.ListItemType.checkhidechildren #%% def month_to_number(month): months = dict(jan=1, feb=2, mar=3, apr=4, may=5, jun=6, jul=7, aug=8, sep=9, oct=10, nov=11, dec=12, annual=13, annualdiff=14) return months.get(month,0) def find_month(desc): months = dict(jan=1, feb=2, mar=3, apr=4, may=5, jun=6, jul=7, aug=8, sep=9, oct=10, nov=11, dec=12, annual=13, annualdiff=14) for month in months.keys():
def _parse_wms(context, repos, record, identifier): from owslib.wms import WebMapService recobjs = [] serviceobj = repos.dataset() md = WebMapService(record) # generate record of service instance _set(context, serviceobj, 'pycsw:Identifier', identifier) _set(context, serviceobj, 'pycsw:Typename', 'csw:Record') _set(context, serviceobj, 'pycsw:Schema', 'http://www.opengis.net/wms') _set(context, serviceobj, 'pycsw:MdSource', record) _set(context, serviceobj, 'pycsw:InsertDate', util.get_today_and_now()) _set(context, serviceobj, 'pycsw:XML', md.getServiceXML()) _set(context, serviceobj, 'pycsw:AnyText', util.get_anytext(md.getServiceXML())) _set(context, serviceobj, 'pycsw:Type', 'service') _set(context, serviceobj, 'pycsw:Title', md.identification.title) _set(context, serviceobj, 'pycsw:Abstract', md.identification.abstract) _set(context, serviceobj, 'pycsw:Keywords', ','.join(md.identification.keywords)) _set(context, serviceobj, 'pycsw:Creator', md.provider.contact.name) _set(context, serviceobj, 'pycsw:Publisher', md.provider.name) _set(context, serviceobj, 'pycsw:Contributor', md.provider.contact.name) _set(context, serviceobj, 'pycsw:OrganizationName', md.provider.contact.name) _set(context, serviceobj, 'pycsw:AccessConstraints', md.identification.accessconstraints) _set(context, serviceobj, 'pycsw:OtherConstraints', md.identification.fees) _set(context, serviceobj, 'pycsw:Source', record) _set(context, serviceobj, 'pycsw:Format', md.identification.type) for c in md.contents: if md.contents[c].parent is None: bbox = md.contents[c].boundingBoxWGS84 tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, serviceobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) break _set(context, serviceobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326') _set(context, serviceobj, 'pycsw:DistanceUOM', 'degrees') _set(context, serviceobj, 'pycsw:ServiceType', md.identification.type) _set(context, serviceobj, 'pycsw:ServiceTypeVersion', md.identification.version) _set(context, serviceobj, 'pycsw:Operation', ','.join([d.name for d in md.operations])) _set(context, serviceobj, 'pycsw:OperatesOn', ','.join(list(md.contents))) _set(context, serviceobj, 'pycsw:CouplingType', 'tight') links = [ '%s,OGC-WMS Web Map Service,OGC:WMS,%s' % (identifier, md.url), '%s,OGC-WMS Capabilities service (ver 1.1.1),OGC:WMS-1.1.1-http-get-capabilities,%s' % (identifier, build_get_url(md.url, { 'service': 'WMS', 'version': '1.1.1', 'request': 'GetCapabilities' })), ] _set(context, serviceobj, 'pycsw:Links', '^'.join(links)) recobjs.append(serviceobj) # generate record foreach layer LOGGER.debug('Harvesting %d WMS layers' % len(md.contents)) for layer in md.contents: recobj = repos.dataset() identifier2 = '%s-%s' % (identifier, md.contents[layer].name) _set(context, recobj, 'pycsw:Identifier', identifier2) _set(context, recobj, 'pycsw:Typename', 'csw:Record') _set(context, recobj, 'pycsw:Schema', 'http://www.opengis.net/wms') _set(context, recobj, 'pycsw:MdSource', record) _set(context, recobj, 'pycsw:InsertDate', util.get_today_and_now()) _set(context, recobj, 'pycsw:XML', md.getServiceXML()) _set(context, recobj, 'pycsw:Type', 'dataset') _set(context, recobj, 'pycsw:ParentIdentifier', identifier) _set(context, recobj, 'pycsw:Title', md.contents[layer].title) _set(context, recobj, 'pycsw:Abstract', md.contents[layer].abstract) _set(context, recobj, 'pycsw:Keywords', ','.join(md.contents[layer].keywords)) _set( context, recobj, 'pycsw:AnyText', util.get_anytext([ md.contents[layer].title, md.contents[layer].abstract, ','.join(md.contents[layer].keywords) ])) bbox = md.contents[layer].boundingBoxWGS84 if bbox is not None: tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) _set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326') _set(context, recobj, 'pycsw:DistanceUOM', 'degrees') else: bbox = md.contents[layer].boundingBox if bbox: tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) _set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:%s' % \ bbox[-1].split(':')[1]) params = { 'service': 'WMS', 'version': '1.1.1', 'request': 'GetMap', 'layers': md.contents[layer].name, 'format': 'image/png', 'height': '200', 'width': '200', 'srs': 'EPSG:4326', 'bbox': '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]), 'styles': '' } links = [ '%s,Web image thumbnail (URL),WWW:LINK-1.0-http--image-thumbnail,%s' % (md.contents[layer].name, build_get_url(md.url, params)) ] params['width'] = '500' params['height'] = '300' links.append( '%s,OGC Web Map Service (ver 1.1.1),OGC:WMS-1.1.1-http-get-map,%s' % (md.contents[layer].name, build_get_url(md.url, params))) _set(context, recobj, 'pycsw:Links', '^'.join(links)) recobjs.append(recobj) return recobjs
def _parse_wms(context, repos, record, identifier): from owslib.wms import WebMapService recobjs = [] serviceobj = repos.dataset() md = WebMapService(record) # generate record of service instance _set(context, serviceobj, 'pycsw:Identifier', identifier) _set(context, serviceobj, 'pycsw:Typename', 'csw:Record') _set(context, serviceobj, 'pycsw:Schema', 'http://www.opengis.net/wms') _set(context, serviceobj, 'pycsw:MdSource', record) _set(context, serviceobj, 'pycsw:InsertDate', util.get_today_and_now()) _set(context, serviceobj, 'pycsw:XML', md.getServiceXML()) _set(context, serviceobj, 'pycsw:AnyText', util.get_anytext(md.getServiceXML())) _set(context, serviceobj, 'pycsw:Type', 'service') _set(context, serviceobj, 'pycsw:Title', md.identification.title) _set(context, serviceobj, 'pycsw:Abstract', md.identification.abstract) _set(context, serviceobj, 'pycsw:Keywords', ','.join(md.identification.keywords)) _set(context, serviceobj, 'pycsw:Creator', md.provider.contact.name) _set(context, serviceobj, 'pycsw:Publisher', md.provider.contact.name) _set(context, serviceobj, 'pycsw:Contributor', md.provider.contact.name) _set(context, serviceobj, 'pycsw:OrganizationName', md.provider.contact.name) _set(context, serviceobj, 'pycsw:AccessConstraints', md.identification.accessconstraints) _set(context, serviceobj, 'pycsw:OtherConstraints', md.identification.fees) _set(context, serviceobj, 'pycsw:Source', record) _set(context, serviceobj, 'pycsw:Format', md.identification.type) for c in md.contents: if md.contents[c].parent is None: bbox = md.contents[c].boundingBoxWGS84 tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, serviceobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) break _set(context, serviceobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326') _set(context, serviceobj, 'pycsw:DistanceUOM', 'degrees') _set(context, serviceobj, 'pycsw:ServiceType', md.identification.type) _set(context, serviceobj, 'pycsw:ServiceTypeVersion', md.identification.version) _set(context, serviceobj, 'pycsw:Operation', ','.join([d.name for d in md.operations])) _set(context, serviceobj, 'pycsw:OperatesOn', ','.join(list(md.contents))) _set(context, serviceobj, 'pycsw:CouplingType', 'tight') recobjs.append(serviceobj) # generate record foreach layer for layer in md.contents: recobj = repos.dataset() identifier2 = '%s-%s' % (identifier, md.contents[layer].name) _set(context, recobj, 'pycsw:Identifier', identifier2) _set(context, recobj, 'pycsw:Typename', 'csw:Record') _set(context, recobj, 'pycsw:Schema', 'http://www.opengis.net/wms') _set(context, recobj, 'pycsw:MdSource', record) _set(context, recobj, 'pycsw:InsertDate', util.get_today_and_now()) _set(context, recobj, 'pycsw:XML', md.getServiceXML()) _set(context, recobj, 'pycsw:AnyText', util.get_anytext(md._capabilities)) _set(context, recobj, 'pycsw:Type', 'dataset') _set(context, recobj, 'pycsw:ParentIdentifier', identifier) _set(context, recobj, 'pycsw:Title', md.contents[layer].title) _set(context, recobj, 'pycsw:Abstract', md.contents[layer].abstract) _set(context, recobj, 'pycsw:Keywords', ','.join(md.contents[layer].keywords)) bbox = md.contents[layer].boundingBoxWGS84 if bbox is not None: tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) _set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:4326') _set(context, recobj, 'pycsw:Denominator', 'degrees') else: bbox = md.contents[layer].boundingBox if bbox: tmp = '%s,%s,%s,%s' % (bbox[0], bbox[1], bbox[2], bbox[3]) _set(context, recobj, 'pycsw:BoundingBox', util.bbox2wktpolygon(tmp)) _set(context, recobj, 'pycsw:CRS', 'urn:ogc:def:crs:EPSG:6.11:%s' % \ bbox[-1].split(':')[1]) recobjs.append(recobj) return recobjs