def expand_params(self, resource): # Use WFS Capabilities doc to get metadata for # PARAM_DEFS ranges/defaults try: wfs = self.get_metadata_cached(resource, version='1.1.0') feature_types = wfs.contents feature_type_names = list(feature_types.keys()) self.layer_count = len(feature_type_names) ft_namespaces = set([name.split(':')[0] if ':' in name else None for name in feature_type_names]) ft_namespaces = filter(None, list(ft_namespaces)) # In some cases default NS is used: no FT NSs nsmap = None if len(ft_namespaces) > 0: try: # issue #243 this depends if lxml etree present # and used by OWSLib ! Otherwise fall-back. nsmap = wfs._capabilities.nsmap except Exception as err: # Fall-back pass if not nsmap: # Just build dummy NS map, to satisfy REQUEST_TEMPLATE ft_namespaces = ['dummyns'] nsmap = {ft_namespaces[0]: 'http://dummy.ns/'} self.PARAM_DEFS['type_ns_prefix']['value'] = ft_namespaces[0] self.PARAM_DEFS['type_ns_uri']['value'] = \ nsmap[ft_namespaces[0]] # FeatureTypes to select self.PARAM_DEFS['type_name']['range'] = feature_type_names self.PARAM_DEFS['type_ns_prefix']['range'] = ft_namespaces self.PARAM_DEFS['type_ns_uri']['range'] = \ [nsmap[ns] for ns in ft_namespaces] # Image Format # for oper in wfs.operations: # if oper.name == 'GetFeature': # self.PARAM_DEFS['format']['range'] = \ # oper.formatOptions # break # Take random feature_type to determine generic attrs for feature_type_name in feature_types: feature_type_entry = feature_types[feature_type_name] break # SRS crs_list = feature_type_entry.crsOptions srs_range = ['EPSG:%s' % crs.code for crs in crs_list] self.PARAM_DEFS['srs']['range'] = srs_range default_srs = srs_range[0] self.PARAM_DEFS['srs']['default'] = default_srs # bbox as list: 0-3 is bbox llx, lly, ulx, uly bbox = feature_type_entry.boundingBoxWGS84 # It looks like the first SRS is the default # if it is not EPSG:4326 we need to transform bbox if default_srs != 'EPSG:4326': bbox = transform_bbox('EPSG:4326', srs_range[0], bbox) # Convert bbox floats to str self.PARAM_DEFS['bbox']['default'] = \ [str(f) for f in bbox] # self.PARAM_DEFS['exceptions']['range'] = wfs.exceptions except Exception as err: raise err
def expand_params(self, resource): # Use WFS Capabilities doc to get metadata for # PARAM_DEFS ranges/defaults try: wfs = self.get_metadata_cached(resource, version='1.1.0') feature_types = wfs.contents if not feature_types: raise Exception('No Feature Types in WFS') feature_type_names = list(feature_types.keys()) self.layer_count = len(feature_type_names) ft_namespaces = set([ name.split(':')[0] if ':' in name else None for name in feature_type_names ]) ft_namespaces = list(filter(None, list(ft_namespaces))) # In some cases default NS is used: no FT NSs nsmap = None if len(ft_namespaces) > 0: try: # issue #243 this depends if lxml etree present # and used by OWSLib ! Otherwise fall-back. nsmap = wfs._capabilities.nsmap except Exception: # Fall-back pass if not nsmap: # Just build dummy NS map, to satisfy REQUEST_TEMPLATE ft_namespaces = ['dummyns'] nsmap = {ft_namespaces[0]: 'http://dummy.ns/'} self.PARAM_DEFS['type_ns_prefix']['value'] = ft_namespaces[0] self.PARAM_DEFS['type_ns_uri']['value'] = \ nsmap[ft_namespaces[0]] # FeatureTypes to select self.PARAM_DEFS['type_name']['range'] = feature_type_names self.PARAM_DEFS['type_ns_prefix']['range'] = ft_namespaces self.PARAM_DEFS['type_ns_uri']['range'] = \ [nsmap[ns] for ns in ft_namespaces] # Image Format # for oper in wfs.operations: # if oper.name == 'GetFeature': # self.PARAM_DEFS['format']['range'] = \ # oper.formatOptions # break # Take first feature_type to determine generic attrs feature_type_entry = feature_types[feature_type_names[0]] # SRS crs_list = feature_type_entry.crsOptions srs_range = ['EPSG:%s' % crs.code for crs in crs_list] self.PARAM_DEFS['srs']['range'] = srs_range default_srs = srs_range[0] self.PARAM_DEFS['srs']['default'] = default_srs # bbox as list: 0-3 is bbox llx, lly, ulx, uly bbox = feature_type_entry.boundingBoxWGS84 # It looks like the first SRS is the default # if it is not EPSG:4326 we need to transform bbox if default_srs != 'EPSG:4326': bbox = transform_bbox('EPSG:4326', srs_range[0], bbox) # Convert bbox floats to str self.PARAM_DEFS['bbox']['default'] = \ [str(f) for f in bbox] # self.PARAM_DEFS['exceptions']['range'] = wfs.exceptions except Exception as err: raise err
def expand_params(self, resource): # Use WFS Capabilities doc to get metadata for # PARAM_DEFS ranges/defaults try: wfs = WebFeatureService(resource.url, version="1.1.0") feature_types = wfs.contents feature_type_names = list(feature_types.keys()) self.layer_count = len(feature_type_names) ft_namespaces = set([ name.split(':')[0] if ':' in name else None for name in feature_type_names ]) ft_namespaces = filter(None, list(ft_namespaces)) # In some cases default NS is used: no FT NSs if len(ft_namespaces) > 0: nsmap = wfs._capabilities.nsmap else: # Just use dummy NS, to satisfy REQUEST_TEMPLATE ft_namespaces = ['notapplicable'] nsmap = {ft_namespaces[0]: 'http://not.appli.cable/'} self.PARAM_DEFS['type_ns_prefix']['value'] = ft_namespaces[0] self.PARAM_DEFS['type_ns_uri']['value'] = \ nsmap[ft_namespaces[0]] # FeatureTypes to select self.PARAM_DEFS['type_name']['range'] = feature_type_names self.PARAM_DEFS['type_ns_prefix']['range'] = ft_namespaces self.PARAM_DEFS['type_ns_uri']['range'] = \ [nsmap[ns] for ns in ft_namespaces] # Image Format # for oper in wfs.operations: # if oper.name == 'GetFeature': # self.PARAM_DEFS['format']['range'] = \ # oper.formatOptions # break # Take first feature_type to determine generic attrs feature_type_name, feature_type_entry = feature_types.popitem() # SRS crs_list = feature_type_entry.crsOptions srs_range = ['EPSG:%s' % crs.code for crs in crs_list] self.PARAM_DEFS['srs']['range'] = srs_range default_srs = srs_range[0] self.PARAM_DEFS['srs']['default'] = default_srs # bbox as list: 0-3 is bbox llx, lly, ulx, uly bbox = feature_type_entry.boundingBoxWGS84 # It looks like the first SRS is the default # if it is not EPSG:4326 we need to transform bbox if default_srs != 'EPSG:4326': bbox = transform_bbox('EPSG:4326', srs_range[0], bbox) # Convert bbox floats to str self.PARAM_DEFS['bbox']['default'] = \ [str(f) for f in bbox] # self.PARAM_DEFS['exceptions']['range'] = wfs.exceptions except Exception as err: raise err