How to use the geonode.layers.models.Layer.objects.get function in GeoNode

To help you get started, we’ve selected a few GeoNode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GeoNode / geonode / geonode / geoserver / views.py View on Github external
_(
                        "You don't have permissions to change style for this layer"),
                    content_type="text/plain",
                    status=401)
            elif downstream_path == 'rest/styles':
                logger.info(
                    "[geoserver_proxy] Updating Style ---> url %s" %
                    url.geturl())
                affected_layers = style_update(request, raw_url)
            elif downstream_path == 'rest/layers':
                logger.debug(
                    "[geoserver_proxy] Updating Layer ---> url %s" %
                    url.geturl())
                try:
                    _layer_name = os.path.splitext(os.path.basename(request.path))[0]
                    _layer = Layer.objects.get(name__icontains=_layer_name)
                    affected_layers = [_layer]
                except BaseException:
                    logger.warn("Could not find any Layer %s on DB" % os.path.basename(request.path))

    kwargs = {'affected_layers': affected_layers}
    raw_url = unquote(raw_url).decode('utf8')
    timeout = getattr(ogc_server_settings, 'TIMEOUT') or 10
    allowed_hosts = [urlsplit(ogc_server_settings.public_url).hostname, ]
    return proxy(request, url=raw_url, response_callback=_response_callback,
                 timeout=timeout, allowed_hosts=allowed_hosts, **kwargs)
github MapStory / mapstory / mapstory / importer / tasks.py View on Github external
:param configuration_options: List of configuration objects for each layer that is being imported.
    """

    upload_file = UploadFile.objects.get(id=upload_file_id)

    for options in configuration_options:
        if not options.get('layer_owner'):
            options['layer_owner'] = upload_file.upload.user

    gi = GDALImport(upload_file.file.path)
    layers = gi.handle(configuration_options=configuration_options)

    for layer, config in layers:
        try:
            matched_layer = Layer.objects.get(name=layer)
            UploadLayer.objects.filter(upload=upload_file.upload, index=config.get('index')).update(layer=matched_layer)
        except UploadLayer.DoesNotExist, Layer.DoesNotExist:
            pass

    return layers
github SP7-Ritmare / starterkit / geosk / mdtools / views.py View on Github external
def get_data_api(request, format='json'):
    if request.method not in ('GET','POST'):
        return HttpResponse(status=405)

    rtype = request.POST.get('rtype')
    id = request.POST.get('id')

    if rtype == 'layer':
        r = Layer.objects.get(pk=id)
        exclude = LayerForm._meta.exclude
    elif rtype == 'map':
        r = Map.objects.get(pk=id)
        exclude = MapForm._meta.exclude

    exclude = exclude + ('owner', 'title', 'distribution_url', 'distribution_description')
    data = model_to_dict(r, exclude=exclude)

    #f=LayerForm(model_to_dict(l), prefix='layer')

    data['keywords'] = r.keyword_csv
    data['regions'] = [reg.name for reg in r.regions.all()] if r.regions else []
    # data_prefix = {"layer-%s" % k: v for k, v in data.items()}

    results = {
        'data': data
github GeoNode / geonode / geonode / contrib / worldmap / wm_extra / views.py View on Github external
if maplayer.transparent:
            cfg['transparent'] = True

        cfg["fixed"] = maplayer.fixed
        if 'url' not in cfg:
            cfg['url'] = maplayer.ows_url
        if cfg['url']:
            cfg['url'] = ows_sub.sub('', cfg['url'])
        if maplayer.group:
            cfg["group"] = maplayer.group
        cfg["visibility"] = maplayer.visibility

        if maplayer.name is not None and maplayer.source_params.find("gxp_gnsource") > -1:
            # Get parameters from GeoNode instead of WMS GetCapabilities
            try:
                gnLayer = Layer.objects.get(typename=maplayer.name)
                if gnLayer.srs:
                    cfg['srs'] = gnLayer.srs
                if gnLayer.bbox:
                    cfg['bbox'] = json.loads(gnLayer.bbox)
                if gnLayer.llbbox:
                    cfg['llbbox'] = json.loads(gnLayer.llbbox)
                cfg['attributes'] = (get_layer_attributes(gnLayer))
                attribute_cfg = gnLayer.attribute_config()
                if "getFeatureInfo" in attribute_cfg:
                    cfg["getFeatureInfo"] = attribute_cfg["getFeatureInfo"]
                cfg['queryable'] = (gnLayer.storeType == 'dataStore'),
                cfg['disabled'] = user is not None and not user.has_perm('maps.view_layer', obj=gnLayer)
                # cfg["displayOutsideMaxExtent"] = user is not None and  user.has_perm('maps.change_layer', obj=gnLayer)
                cfg['visibility'] = cfg['visibility'] and not cfg['disabled']
                cfg['abstract'] = gnLayer.abstract
                cfg['styles'] = maplayer.styles
github GeoNode / geonode / geonode / contrib / datatables / utils.py View on Github external
assert layer_typename is not None, "layer_typename cannot be None"
    assert table_attribute_name is not None, "table_attribute_name cannot be None"
    assert layer_attribute_name is not None, "layer_attribute_name cannot be None"

    LOGGER.info('setup_join. Step (1): Retrieve the DataTable object')
    try:
        dt = DataTable.objects.get(table_name=table_name)
    except DataTable.DoesNotExist:
        err_msg = 'No DataTable object found for table_name "%s"' % table_name
        LOGGER.error(err_msg)
        return None, err_msg

    LOGGER.info('setup_join. Step (2): Retrieve the Layer object')

    try:
        layer = Layer.objects.get(typename=layer_typename)
    except Layer.DoesNotExist:
        err_msg = 'No Layer object found for layer_typename "%s"' % layer_typename
        LOGGER.error(err_msg)
        return None, err_msg

    LOGGER.info('setup_join. Step (3): Retrieve the DataTableAttribute object')
    try:
        table_attribute = DataTableAttribute.objects.get(\
                                        datatable=dt,
                                        attribute=table_attribute_name)
    except DataTableAttribute.DoesNotExist:
        err_msg = 'No DataTableAttribute object found for table/attribute (%s/%s)' \
                  % (dt,
                     table_attribute_name)
        LOGGER.error(err_msg)
        return None, err_msg
github GeoNode / geonode / geonode / security / utils.py View on Github external
from geonode.base.models import ResourceBase
    from geonode.layers.models import Layer

    if resource:
        dirty_resources = ResourceBase.objects.filter(id=resource.id)
    else:
        dirty_resources = ResourceBase.objects.filter(dirty_state=True)
    if dirty_resources and dirty_resources.count() > 0:
        logger.debug(" --------------------------- synching with guardian!")
        for r in dirty_resources:
            if r.polymorphic_ctype.name == 'layer':
                layer = None
                try:
                    purge_geofence_layer_rules(r)
                    layer = Layer.objects.get(id=r.id)
                    perm_spec = layer.get_all_level_info()
                    logger.debug(" %s --------------------------- %s " % (layer, perm_spec))
                    # All the other users
                    if 'users' in perm_spec:
                        for user, perms in perm_spec['users'].items():
                            user = get_user_model().objects.get(username=user)
                            # Set the GeoFence User Rules
                            geofence_user = str(user)
                            if "AnonymousUser" in geofence_user:
                                geofence_user = None
                            sync_geofence_with_guardian(layer, perms, user=geofence_user)
                    # All the other groups
                    if 'groups' in perm_spec:
                        for group, perms in perm_spec['groups'].items():
                            group = Group.objects.get(name=group)
                            # Set the GeoFence Group Rules
github GeoNode / geonode / geonode / contrib / worldmap / wm_extra / views.py View on Github external
source_url = source['url']
            if settings.GEOSERVER_PUBLIC_LOCATION in source_url:
                if 'name' in layer_config:
                    is_wm = True
            if 'registry/hypermap' in source_url:
                is_hh = True
        group = 'General'
        layer_config['tiled'] = True
        if is_wm:
            source = layer_config['source']
            config['sources'][source]['ptype'] = 'gxp_gnsource'
            config['sources'][source]['url'] = config['sources'][source]['url'].replace('ows', 'wms')
            layer_config['local'] = True
            layer_config['queryable'] = True
            alternate = layer_config['name']
            layer = Layer.objects.get(alternate=alternate)
            layer_config['attributes'] = (get_layer_attributes(layer))
            # layer_config['url'] = layer.ows_url
            layer_config['url'] = layer.ows_url.replace('ows', 'wms')
            if 'styles' not in layer_config:
                if layer.default_style:
                    layer_config['styles'] = layer.default_style.name
                else:
                    layer_config['styles'] = layer.styles.all()[0].name
            if layer.category:
                group = layer.category.gn_description
            layer_config["srs"] = getattr(
                settings, 'DEFAULT_MAP_CRS', 'EPSG:900913')
            bbox = layer.bbox[:-1]
            # WorldMap GXP use a different bbox representation than GeoNode
            bbox = [bbox[0], bbox[2], bbox[1], bbox[3]]
            layer_config["bbox"] = [float(coord) for coord in bbox] if layer_config["srs"] != 'EPSG:900913' \
github GeoNode / geonode / geonode / maps / views.py View on Github external
request.session["map_status"] = map_status
        else:
            raise Exception(
                'Could not start the download of %s. Error was: %s' %
                (map_obj.title, content))

    locked_layers = []
    remote_layers = []
    downloadable_layers = []

    for lyr in map_obj.layer_set.all():
        if lyr.group != "background":
            if not lyr.local:
                remote_layers.append(lyr)
            else:
                ownable_layer = Layer.objects.get(alternate=lyr.name)
                if not request.user.has_perm(
                        'download_resourcebase',
                        obj=ownable_layer.get_self_resource()):
                    locked_layers.append(lyr)
                else:
                    # we need to add the layer only once
                    if len(
                            [_l for _l in downloadable_layers if _l.name == lyr.name]) == 0:
                        downloadable_layers.append(lyr)
    site_url = settings.SITEURL.rstrip('/') if settings.SITEURL.startswith('http') else settings.SITEURL
    return render(request, template, context={
        "geoserver": ogc_server_settings.PUBLIC_LOCATION,
        "map_status": map_status,
        "map": map_obj,
        "locked_layers": locked_layers,
        "remote_layers": remote_layers,
github GeoNode / geonode / geonode / catalogue / views.py View on Github external
resource.bbox_x1) + ',' + fst(
        resource.bbox_y0) + ',' + fst(resource.bbox_y1) + sc
    content += 'SRID  ' + s + fst(resource.srid) + sc
    content += 'Thumbnail url' + s + fst(resource.thumbnail_url) + sc

    content += 'keywords;' + get_keywords(resource) + s
    content += 'category' + s + fst(resource.category) + sc

    content += 'regions' + s
    for reg in resource.regions.all():
        content += fst(reg.name_en) + ','
    content = content[:-1]
    content += sc

    if resource.detail_url.find('/layers/') > -1:
        layer = Layer.objects.get(resourcebase_ptr_id=resource.id)
        content += 'attribute data' + sc
        content += 'attribute name;label;description\n'
        for attr in layer.attribute_set.all():
            content += fst(attr.attribute) + s
            content += fst(attr.attribute_label) + s
            content += fst(attr.description) + sc

    pocr = ContactRole.objects.get(
        resource_id=resource.id, role='pointOfContact')
    pocp = Profile.objects.get(id=pocr.contact_id)
    content += "Point of Contact" + sc
    content += "name" + s + fst(pocp.last_name) + sc
    content += "e-mail" + s + fst(pocp.email) + sc

    logger = logging.getLogger(__name__)
    logger.error(content)