Пример #1
0
def service_get_presentationlayer_settings(
    request, pl_id):
    """get_settings of presentationlayer
    return:

        overlaytype: presentationtype_overlaytype - integer - (wms,
        map, general, (point, line))

        type: presentationtype_valuetype - integer - (timeserie,
        classification, singlevalue, static)

        has_value_source (kan ik waarden of grafieken van een punt
        opvragen??)

        legend: array of legends with:
                id:
                name:
                in case of default: dtype (0=personal default,
                1=project default, 2=presentationType default)

    in case of grid:
        extent (in original srid) - north, south, west,east
        srid
        nrrows
        nrcols
        gridsize
    in case of animation:
        firstnr (nr first timestep)
        startnr (where default starts the animation slider)
        lastnr  (nr last timestep)
        dt (delta time between timesteps)
    in case of classification:
        firstnr (nr first class)
        startnr (default class, which is first showed when )
        lastnr  (nr last timestep)
        array of class boundaries
        voor resultaten met figuren, haalt afmetingen en extents op
    """
    pl = get_object_or_404(PresentationLayer, pk=pl_id)
    pm = PermissionManager(request.user)
    if not pm.check_permission(
        pl, PermissionManager.PERMISSION_PRESENTATIONLAYER_VIEW):
        raise Http404

    rec = {}
    if pl.presentationtype.geo_type == PresentationType.GEO_TYPE_GRID:
        try:
            pl.presentationgrid
        except PresentationGrid.DoesNotExist:
            return HttpResponse(
                simplejson.dumps({}), mimetype="application/json")

        rec['bounds'] = {}
        rec['bounds']['projection'] = pl.presentationgrid.bbox_orignal_srid

        extent = pl.presentationgrid.extent.extent
        if pl.presentationgrid.bbox_orignal_srid == 28992:
            (rec['bounds']['south'], rec['bounds']['west'],
             rec['bounds']['north'], rec['bounds']['east']) = extent
            rec['bounds']['projection'] = 28992
        else:
            (rec['bounds']['west'], rec['bounds']['south'],
             rec['bounds']['east'], rec['bounds']['north']) = extent
            rec['bounds']['projection'] = 4326

        rec['height'] = pl.presentationgrid.rownr
        rec['width'] = pl.presentationgrid.colnr
        rec['gridsize'] = pl.presentationgrid.gridsize

    anim = {}

    if (pl.presentationtype.value_type ==
        PresentationType.VALUE_TYPE_TIME_SERIE):
        anim['firstnr'] = pl.animation.firstnr
        anim['lastnr'] = pl.animation.lastnr
        anim['options'] = {}
        anim['options']['startnr'] = pl.animation.startnr
        if (pl.animation.delta_timestep > 0):
            anim['options']['delta'] = pl.animation.delta_timestep * 24 * 3600

    legends = pm.get_legends(pl)

    legend_objects = [{'id': l.id, 'name': l.name} for l in legends]

    default_legend = ShapeDataLegend.objects.get(
        pk=pl.presentationtype.default_legend_id)

    log.debug('got default legend')

    info = {}
    info['rec'] = rec
    info['anim'] = anim
    info['legends'] = legend_objects
    info['default_legend'] = {
        'id': default_legend.id,
        'name': default_legend.name
    }

    if ((pl.presentationtype.value_type ==
         PresentationType.VALUE_TYPE_TIME_SERIE) and
        pl.presentationtype.geo_type in [
            PresentationType.GEO_TYPE_POLYGON,
            PresentationType.GEO_TYPE_LINE,
            PresentationType.GEO_TYPE_POINT]):

        anim['lastnr'] = pl.animation.lastnr
        pass

    log.debug('json dump van info')
    log.debug(simplejson.dumps(info))
    return HttpResponse(simplejson.dumps(info), mimetype="application/json")
Пример #2
0
def service_get_presentationlayer_settings(request, pl_id):
    """get_settings of presentationlayer
    return:

        overlaytype: presentationtype_overlaytype - integer - (wms,
        map, general, (point, line))

        type: presentationtype_valuetype - integer - (timeserie,
        classification, singlevalue, static)

        has_value_source (kan ik waarden of grafieken van een punt
        opvragen??)

        legend: array of legends with:
                id:
                name:
                in case of default: dtype (0=personal default,
                1=project default, 2=presentationType default)

    in case of grid:
        extent (in original srid) - north, south, west,east
        srid
        nrrows
        nrcols
        gridsize
    in case of animation:
        firstnr (nr first timestep)
        startnr (where default starts the animation slider)
        lastnr  (nr last timestep)
        dt (delta time between timesteps)
    in case of classification:
        firstnr (nr first class)
        startnr (default class, which is first showed when )
        lastnr  (nr last timestep)
        array of class boundaries
        voor resultaten met figuren, haalt afmetingen en extents op
    """
    pl = get_object_or_404(PresentationLayer, pk=pl_id)
    pm = PermissionManager(request.user)
    if not pm.check_permission(
            pl, PermissionManager.PERMISSION_PRESENTATIONLAYER_VIEW):
        raise Http404

    result = pyramids.get_result_by_presentationlayer(pl)
    if result is not None and result.animation:
        return JSONResponse(
            pyramids.settings_for_animation(result.animation, result.scenario))

    rec = {}
    if pl.presentationtype.geo_type == PresentationType.GEO_TYPE_GRID:
        try:
            pl.presentationgrid
        except PresentationGrid.DoesNotExist:
            return JSONResponse({})

        rec['bounds'] = {}
        rec['bounds']['projection'] = pl.presentationgrid.bbox_orignal_srid

        extent = pl.presentationgrid.extent.extent
        if pl.presentationgrid.bbox_orignal_srid == 28992:
            (rec['bounds']['south'], rec['bounds']['west'],
             rec['bounds']['north'], rec['bounds']['east']) = extent
            rec['bounds']['projection'] = 28992
        else:
            (rec['bounds']['west'], rec['bounds']['south'],
             rec['bounds']['east'], rec['bounds']['north']) = extent
            rec['bounds']['projection'] = 4326

        rec['height'] = pl.presentationgrid.rownr
        rec['width'] = pl.presentationgrid.colnr
        rec['gridsize'] = pl.presentationgrid.gridsize

    anim = {}

    if (pl.presentationtype.value_type ==
            PresentationType.VALUE_TYPE_TIME_SERIE):
        anim['firstnr'] = pl.animation.firstnr
        anim['lastnr'] = pl.animation.lastnr
        anim['options'] = {}
        anim['options']['startnr'] = pl.animation.startnr
        if (pl.animation.delta_timestep > 0):
            anim['options']['delta'] = pl.animation.delta_timestep * 24 * 3600

    legends = pm.get_legends(pl)

    legend_objects = [{'id': l.id, 'name': l.name} for l in legends]

    default_legend = ShapeDataLegend.objects.get(
        pk=pl.presentationtype.default_legend_id)

    log.debug('got default legend')

    info = {}
    info['rec'] = rec
    info['anim'] = anim
    info['legends'] = legend_objects
    info['default_legend'] = {
        'id': default_legend.id,
        'name': default_legend.name
    }

    if ((pl.presentationtype.value_type
         == PresentationType.VALUE_TYPE_TIME_SERIE)
            and pl.presentationtype.geo_type in [
                PresentationType.GEO_TYPE_POLYGON,
                PresentationType.GEO_TYPE_LINE, PresentationType.GEO_TYPE_POINT
            ]):

        anim['lastnr'] = pl.animation.lastnr
        pass

    log.debug('json dump van info')
    log.debug(json.dumps(info))
    return JSONResponse(info)