def test_url_build(self): base_url = 'http://example.com' queries = [('q1', 'foo'), ('q2', 'bar'), ('q2', 'baz')] url_helper = UrlHelper() url = url_helper.build(base_url, queries) expected_url = 'http://example.com?q1=foo&q2=baz' self.assertURLEqual(url, expected_url)
def get_get_legend_graphic_url(self): """ Creates the url for the wms getLegendGraphic request. Returns: str: URL for getLegendGraphic request. """ uri = self.service.operation_urls.filter( operation=OGCOperationEnum.GET_LEGEND_GRAPHIC.value, method="Get").first() if uri is None: return uri = uri.url request_type = OGCOperationEnum.GET_LEGEND_GRAPHIC.value layer = self.layer.identifier service_format = self.service.metadata.get_formats().filter( mime_type__istartswith='image/').exclude( mime_type__icontains='svg').first() if not service_format: # no formats are supported... return None return version = self.service.service_type.version service_type = self.service.service_type.name queries = [ ('REQUEST', request_type), ('LAYER', layer), ('FORMAT', service_format), ('SERVICE', service_type), ('VERSION', version), ] url = UrlHelper.build(uri, queries) return url
def get_describe_layer_url(self): """ Creates the url for the wms DescribeLayer request. Returns: str: URL for DescribeLayer request. """ uri = self.service.operation_urls.filter( operation=OGCOperationEnum.DESCRIBE_LAYER.value, method="Get").first() if uri is None: return uri = uri.url request_type = OGCOperationEnum.DESCRIBE_LAYER.value # make sure that version is describeLayer specific version 1.1.1 and not wms version 1.3.0 service_version = OGCServiceVersionEnum.V_1_1_1.value service_type = OGCServiceEnum.WMS.value layers = self.layer.identifier queries = [ ('REQUEST', request_type), ('VERSION', service_version), ('SERVICE', service_type), ('LAYERS', layers), ('WIDTH', 1), ('HEIGHT', 1), ] url = UrlHelper.build(uri, queries) return url
def get_describe_featuretype_url(self, type_name: str): """ Creates the url for the wfs DescribeFeatureType request. Args: type_name (str): The name of the feature type to check. Returns: str: URL for DescribeFeatureType request. """ uri = None try: uri = self.parent_service.operation_urls.filter( operation=OGCOperationEnum.DESCRIBE_FEATURE_TYPE, method="Get").first() except AttributeError: pass if uri is None: return if type_name is None: return uri = uri.url request_type = OGCOperationEnum.DESCRIBE_FEATURE_TYPE.value service_version = self.parent_service.service_type.version service_type = OGCServiceEnum.WFS.value if service_version == OGCServiceVersionEnum.V_1_0_0.value \ or service_version == OGCServiceVersionEnum.V_1_1_0.value: queries = [('REQUEST', request_type), ('VERSION', service_version), ('SERVICE', service_type), ('typeName', type_name)] else: queries = [('REQUEST', request_type), ('VERSION', service_version), ('SERVICE', service_type), ('typeNames', type_name)] url = UrlHelper.build(uri, queries) return url
def get_get_styles_url(self): """ Creates the url for the wms getStyles request. Returns: str: URL for getStyles request. """ uri = self.service.operation_urls.filter( operation=OGCOperationEnum.GET_STYLES.value, method="Get").first() if uri is None: return uri = uri.url service_version = OGCServiceVersionEnum.V_1_1_1.value service_type = OGCServiceEnum.WMS.value layers = self.layer.identifier request_type = OGCOperationEnum.GET_STYLES.value queries = [('SERVICE', service_type), ('REQUEST', request_type), ('VERSION', service_version), ('LAYERS', layers)] url = UrlHelper.build(uri, queries) return url
def get_list_stored_queries(self): """ Creates the url for the wfs ListStoredQueries request. Returns: str: URL for ListStoredQueries request. """ uri = self.service.operation_urls.filter( operation=OGCOperationEnum.LIST_STORED_QUERIES.value, method="Get").first() if uri is None: return uri = uri.url request_type = OGCOperationEnum.LIST_STORED_QUERIES.value service_version = self.service.service_type.version service_type = OGCServiceEnum.WFS.value queries = [('REQUEST', request_type), ('VERSION', service_version), ('SERVICE', service_type)] url = UrlHelper.build(uri, queries) return url
def get_get_capabilities_url(self): """ Creates the url for the wfs GetCapabilities request. Returns: str: URL for GetCapabilities request. """ uri = self.parent_service.operation_urls.filter( operation=OGCOperationEnum.GET_CAPABILITIES.value, method="Get") uri = uri.first() if uri is None: return uri = uri.url request_type = OGCOperationEnum.GET_CAPABILITIES.value service_version = self.parent_service.service_type.version service_type = OGCServiceEnum.WFS.value queries = [('REQUEST', request_type), ('VERSION', service_version), ('SERVICE', service_type)] url = UrlHelper.build(uri, queries) return url
def get_get_feature_info_url(self): """ Creates the url for the wms getFeatureInfo request. Returns: str: URL for getFeatureInfo request. """ uri = self.service.operation_urls.filter( operation=OGCOperationEnum.GET_FEATURE_INFO.value, method="Get").first() if uri is None or not self.layer.is_queryable: return uri = uri.url request_type = OGCOperationEnum.GET_FEATURE_INFO.value service_version = self.service.service_type.version service_type = OGCServiceEnum.WMS.value layers = self.layer.identifier crs = f'EPSG:{self.bbox.crs.srid}' bbox = ','.join(map(str, self.bbox.extent)) styles = '' width = 1 height = 1 query_layers = layers x = 0 y = 0 queries = [('REQUEST', request_type), ('VERSION', service_version), ('SERVICE', service_type), ('LAYERS', layers), (self.crs_srs_identifier, crs), ('BBOX', bbox), ('STYLES', styles), ('WIDTH', width), ('HEIGHT', height), ('QUERY_LAYERS', query_layers)] if service_version.lower( ) == OGCServiceVersionEnum.V_1_3_0.value.lower(): queries = queries + [('I', x), ('J', y)] else: queries = queries + [('X', x), ('Y', y)] url = UrlHelper.build(uri, queries) return url
def get_get_map_url(self): """ Creates the url for the wms getMap request. Returns: str: URL for getMap request. """ uri = self.service.operation_urls.filter( operation=OGCOperationEnum.GET_MAP.value, method="Get").first() if uri is None: return uri = uri.url # Fetch request parameters request_type = OGCOperationEnum.GET_MAP.value service_version = self.service.service_type.version service_type = OGCServiceEnum.WMS.value # Get bbox value for request layers = self.layer.identifier srs = f'EPSG:{self.bbox.crs.srid}' bbox = ','.join(map(str, self.bbox.extent)) styles = '' width = 1 height = 1 service_format = self.service.metadata.get_formats().filter( operation=OGCOperationEnum.GET_MAP.value, mime_type__istartswith='image/').exclude( mime_type__icontains='svg').first() queries = [('REQUEST', request_type), ('VERSION', service_version), ('SERVICE', service_type), ('LAYERS', layers), (self.crs_srs_identifier, srs), ('BBOX', bbox), ('STYLES', styles), ('WIDTH', width), ('HEIGHT', height), ('FORMAT', service_format)] url = UrlHelper.build(uri, queries) return url