Пример #1
0
def make_node( data, id, config=None ):
    """
    Generate a RAMP layer entry for a WMS.

    :param data: The initial payload to RCS
    :type data: dict
    :param id: An identifier for the layer (as this is unique it is generally supplied from :module:rcs )
    :type id: str
    :returns: dict -- a RAMP configuration fragment representing the WMS layer
    """
    wms_node = { 'id': id }
    wms_node['url'] = data['service_url']
    wms_node['layerName'] = data['layer']
    wms_node['displayName'] = data['layer']
    if 'service_name' in data:
        wms_node['displayName'] = data['service_name']
    wms_node['format'] = 'image/png'
    metadata_url, catalogue_url = metadata.get_url( data, config )
    if metadata_url:
        wms_node['metadataUrl'] = metadata_url
        wms_node['catalogueUrl'] = catalogue_url
    if 'legend_format' in data:
        wms_node['legendMimeType'] = data['legend_format']
    fi_node = make_feature_info( data )
    if fi_node is not None:
        wms_node['featureInfo'] = fi_node
    return wms_node
Пример #2
0
def make_node( data, id, config ):
    """
    Generate a RAMP layer entry for an ESRI feature service.

    :param data: The initial payload to RCS (should contain a 'service_url' entry)
    :type data: dict
    :param id: An identifier for the layer (as this is unique it is generally supplied from :module:rcs )
    :type id: str
    :returns: dict -- a RAMP configuration fragment representing the ESRI layer
    """
    node = { 'id': id }
    r = requests.get( data['service_url'] + '?f=json' )
    svc_data = r.json()
    node['url'] = data['service_url']
    node['displayName'] = data.get('service_name',None)
    node['nameField'] = data.get('display_field',None)
    if node.get('displayName',None) is None:
        node['displayName'] = svc_data['name']
    if node.get('nameField',None) is None:
        node['nameField'] = svc_data['displayField']
    metadata_url, catalogue_url = metadata.get_url( data, config )
    if metadata_url:
        node['metadataUrl'] = metadata_url
        node['catalogueUrl'] = catalogue_url
    node['minScale'] = svc_data.get('minScale',0)
    node['maxScale'] = svc_data.get('maxScale',0)
    node['datagrid'] = make_data_grid( svc_data )
    node['layerExtent'] = make_extent( svc_data )
    node['symbology'] = make_symbology( svc_data, data )
    node['aliasMap'] = make_alias_mapping( svc_data['fields'] )    
    node['maxAllowableOffset'] = data.get('maxAllowableOffset', 0)
    return node
Пример #3
0
def make_node(key, json_request, config):
    """
    Construct a basic layer node which could be consumed by the viewer.
    """
    langs = config['LANGS']
    node = {lang: {} for lang in langs}
    v1 = None
    svc_types = {lang: get_endpoint_type(json_request[lang]['service_url']) for lang in langs}
    if len(set(svc_types.values())) > 1:
        raise ServiceEndpointException('Mismatched service types across languages {0}'.format(svc_types.values()))
    if svc_types.values()[0] in [ServiceTypes.WMS, ServiceTypes.FEATURE]:
        v1 = {lang: {} for lang in langs}
    for lang in langs:
        n = node[lang]
        n['id'] = make_id(key, lang)
        ltype = svc_types[lang]
        n['layerType'] = remapped_types.get(ltype, ltype)
        if 'service_type' in json_request[lang] and json_request[lang]['service_type'] != svc_types[lang]:
            msg = 'Mismatched service type in {0} object, endpoint identified as {1} but provided as {2}' \
                  .format(lang, svc_types[lang], json_request[lang]['service_type'])
            raise ServiceEndpointException(msg)
        n['url'] = json_request[lang]['service_url']
        m_url, c_url = metadata.get_url(json_request[lang], config)
        if c_url:
            node[lang]['metadataUrl'] = m_url
            node[lang]['catalogueUrl'] = c_url
        n.update(parser_map[ltype](json_request[lang]))
        if 'service_name' in json_request[lang]:
            # important to do this last so it overwrites anything scraped from the custom parser
            n['name'] = json_request[lang]['service_name']
        if ltype == ServiceTypes.WMS:
            v1[lang] = ogc.make_v1_wms_node(json_request[lang], n)
        elif ltype == ServiceTypes.FEATURE:
            v1[lang] = esri.make_v1_feature_node(json_request[lang], n)
    return node, v1
Пример #4
0
def make_node( data, id, config ):
    """
    Generate a RAMP layer entry for an ESRI feature service.

    :param data: The initial payload to RCS (should contain a 'service_url' entry)
    :type data: dict
    :param id: An identifier for the layer (as this is unique it is generally supplied from :module:rcs )
    :type id: str
    :returns: dict -- a RAMP configuration fragment representing the ESRI layer
    """
    node = { 'id': id }

    global _proxies
    if 'FEATURE_SERVICE_PROXY' in config:
        _proxies = { 'http': config['FEATURE_SERVICE_PROXY'], 'https': config['FEATURE_SERVICE_PROXY']}
    r = requests.get( data['service_url'] + '?f=json', proxies=_proxies )
    svc_data = r.json()
    node['url'] = data['service_url']
    node['displayName'] = data.get('service_name',None)
    node['nameField'] = data.get('display_field',None)
    if node.get('displayName',None) is None:
        node['displayName'] = svc_data['name']
    if node.get('nameField',None) is None:
        node['nameField'] = svc_data['displayField']
    metadata_url, catalogue_url = metadata.get_url( data, config )
    if metadata_url:
        node['metadataUrl'] = metadata_url
        node['catalogueUrl'] = catalogue_url
    node['minScale'] = svc_data.get('minScale',0)
    node['maxScale'] = svc_data.get('maxScale',0)
    node['datagrid'] = make_data_grid( svc_data )
    node['layerExtent'] = make_extent( svc_data )
    node['symbology'] = make_symbology( svc_data, data )
    node['aliasMap'] = make_alias_mapping( svc_data['fields'] )
    if 'max_allowable_offset' in data:
        node['maxAllowableOffset'] = data['max_allowable_offset']
    if 'loading_mode' in data:
        node['mode'] = data['loading_mode']
    elif test_small_layer( node['url'], svc_data ):
        node['mode'] = 'snapshot'
    node['geometryType'] = svc_data['geometryType']
    return node