Пример #1
0
def linechart_update(request, layer_id, chart_id):
    if request.method == 'POST':
        layer = Layer.objects.get(id=int(layer_id))
        chart = Chart.objects.get(id=int(chart_id))

        title = request.POST.get('title')
        description = request.POST.get('description')
        chart_conf = request.POST.get('chart_conf')

        chart.title = title
        chart.description = description
        chart.conf = chart_conf

        chart.save()

        return HttpResponse(json.dumps({'success': True}, indent=4),
                            content_type='application/json')

    else:
        layer = Layer.objects.get(id=int(layer_id))
        chart = Chart.objects.get(id=int(chart_id))

        layer = Layer.objects.get(id=int(layer_id))
        datastore = Datastore.objects.get(id=layer.datastore_id)
        workspace = Workspace.objects.get(id=datastore.workspace_id)
        gs = geographic_servers.get_instance().get_server_by_id(
            workspace.server.id)

        (ds_type, resource) = gs.getResourceInfo(workspace.name, datastore,
                                                 layer.name, "json")
        fields = utils.get_fields(resource)
        numeric_fields = utils.get_numeric_fields(fields)
        alpha_numeric_fields = utils.get_alphanumeric_fields(fields)
        geom_fields = utils.get_geometry_fields(fields)

        conf = json.loads(chart.conf)

        y_axis_begin_at_zero = False
        if 'y_axis_begin_at_zero' in conf:
            y_axis_begin_at_zero = conf['y_axis_begin_at_zero']

        return render(
            request, 'linechart_update.html', {
                'layer_id': layer_id,
                'chart_id': chart_id,
                'fields': json.dumps(fields),
                'numeric_fields': json.dumps(numeric_fields),
                'alpha_numeric_fields': json.dumps(alpha_numeric_fields),
                'geom_fields': json.dumps(geom_fields),
                'title': chart.title,
                'description': chart.description,
                'dataset_type': conf['dataset_type'],
                'x_axis_title': conf['x_axis_title'],
                'y_axis_title': conf['y_axis_title'],
                'y_axis_begin_at_zero': y_axis_begin_at_zero,
                'geographic_names_column': conf['geographic_names_column'],
                'geometries_column': conf['geometries_column'],
                'selected_columns': json.dumps(conf['columns'])
            })
def get_conf(request, layer_id):
    layer = Layer.objects.get(id=int(layer_id))
    datastore = Datastore.objects.get(id=layer.datastore_id)
    workspace = Workspace.objects.get(id=datastore.workspace_id)
    gs = geographic_servers.get_instance().get_server_by_id(workspace.server.id)
    index = utils.get_next_index(layer)
    (ds_type, resource) = gs.getResourceInfo(workspace.name, datastore, layer.name, "json")
    fields = utils.get_fields(resource)
    if layer.conf:
        new_fields = []
        conf = None
        if layer and layer.conf:
            conf = ast.literal_eval(layer.conf)
        for field in fields:
            if conf:
                for f in conf['fields']:
                    if f['name'] == field['name']:
                        for id, language in settings.LANGUAGES:
                            field['title-'+id] = f['title-'+id]
            else:
                for id, language in settings.LANGUAGES:
                    field['title-'+id] = field['name']
            new_fields.append(field)
        fields = new_fields
        
    feature_type = utils.get_feature_type(fields)
    alphanumeric_fields = utils.get_alphanumeric_fields(fields)
       
    supported_fonts_str = gs.getSupportedFonts()
    supported_fonts = json.loads(supported_fonts_str)
    sorted_fonts = utils.sortFontsArray(supported_fonts.get("fonts"))
              
    layer_url = core_utils.get_wms_url(workspace)
    layer_wfs_url = core_utils.get_wfs_url(workspace)
    
    preview_url = ''
    if feature_type == 'PointSymbolizer':
        preview_url = workspace.server.frontend_url + '/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=preview_point'    
    elif feature_type == 'LineSymbolizer':      
        preview_url = workspace.server.frontend_url + '/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=preview_line'     
    elif feature_type == 'PolygonSymbolizer': 
        preview_url = workspace.server.frontend_url + '/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=preview_polygon'
                  
    conf = {
        'featureType': feature_type,
        'fields': alphanumeric_fields,
        'json_alphanumeric_fields': json.dumps(alphanumeric_fields),
        'fonts': sorted_fonts,
        'layer_id': layer_id,
        'layer_url': layer_url,
        'layer_wfs_url': layer_wfs_url,
        'layer_name': workspace.name + ':' + layer.name,
        'style_name': workspace.name + '_' + layer.name + '_' + str(index),
        'libraries': Library.objects.all(),
        'supported_crs': json.dumps(core_utils.get_supported_crs()),
        'preview_url': preview_url
    }    
     
    return conf
Пример #3
0
def piechart_add(request, layer_id):
    if request.method == 'POST':
        layer = Layer.objects.get(id=int(layer_id))

        title = request.POST.get('title')
        description = request.POST.get('description')
        chart_conf = request.POST.get('chart_conf')

        chart = Chart(layer=layer,
                      type='piechart',
                      title=title,
                      description=description,
                      conf=chart_conf)
        chart.save()

        return HttpResponse(json.dumps({'success': True}, indent=4),
                            content_type='application/json')

    else:
        layer = Layer.objects.get(id=int(layer_id))

        layer = Layer.objects.get(id=int(layer_id))
        datastore = Datastore.objects.get(id=layer.datastore_id)
        workspace = Workspace.objects.get(id=datastore.workspace_id)
        gs = geographic_servers.get_instance().get_server_by_id(
            workspace.server.id)

        (ds_type, resource) = gs.getResourceInfo(workspace.name, datastore,
                                                 layer.name, "json")
        fields = utils.get_fields(resource)
        numeric_fields = utils.get_numeric_fields(fields)
        alpha_numeric_fields = utils.get_alphanumeric_fields(fields)
        geom_fields = utils.get_geometry_fields(fields)

        conf = {
            'layer_id': layer_id,
            'fields': json.dumps(fields),
            'numeric_fields': json.dumps(numeric_fields),
            'alpha_numeric_fields': json.dumps(alpha_numeric_fields),
            'geom_fields': json.dumps(geom_fields)
        }

        return render(request, 'piechart_add.html', conf)
Пример #4
0
def get_conf(request, layer_id):
    layer = Layer.objects.get(id=int(layer_id))
    datastore = Datastore.objects.get(id=layer.datastore_id)
    workspace = Workspace.objects.get(id=datastore.workspace_id)

    index = len(StyleLayer.objects.filter(layer=layer))
    styleLayers = StyleLayer.objects.filter(layer=layer)
    for style_layer in styleLayers:
        aux_name = style_layer.style.name
        aux_name = aux_name.replace(workspace.name + '_' + layer.name + '_',
                                    '')

        try:
            aux_index = int(aux_name)
            if index < aux_index + 1:
                index = aux_index + 1
        except ValueError:
            print "Error getting index"

    (ds_type, resource) = mapservice.getResourceInfo(workspace.name, datastore,
                                                     layer.name, "json")
    fields = utils.get_fields(resource)
    if layer.conf:
        new_fields = []
        conf = None
        if layer and layer.conf:
            conf = ast.literal_eval(layer.conf)
        for field in fields:
            if conf:
                for f in conf['fields']:
                    if f['name'] == field['name']:
                        for id, language in settings.LANGUAGES:
                            field['title-' + id] = f['title-' + id]
            else:
                for id, language in settings.LANGUAGES:
                    field['title-' + id] = field['name']
            new_fields.append(field)
        fields = new_fields

    feature_type = utils.get_feature_type(fields)
    alphanumeric_fields = utils.get_alphanumeric_fields(fields)

    supported_fonts_str = mapservice.getSupportedFonts()
    supported_fonts = json.loads(supported_fonts_str)
    sorted_fonts = utils.sortFontsArray(supported_fonts.get("fonts"))

    layer_url = core_utils.get_wms_url(request, workspace)
    layer_wfs_url = core_utils.get_wfs_url(request, workspace)

    preview_url = ''
    if feature_type == 'PointSymbolizer':
        preview_url = settings.GVSIGOL_SERVICES[
            'URL'] + '/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=preview_point'
    elif feature_type == 'LineSymbolizer':
        preview_url = settings.GVSIGOL_SERVICES[
            'URL'] + '/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=preview_line'
    elif feature_type == 'PolygonSymbolizer':
        preview_url = settings.GVSIGOL_SERVICES[
            'URL'] + '/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=preview_polygon'

    conf = {
        'featureType': feature_type,
        'fields': alphanumeric_fields,
        'json_alphanumeric_fields': json.dumps(alphanumeric_fields),
        'fonts': sorted_fonts,
        'layer_id': layer_id,
        'layer_url': layer_url,
        'layer_wfs_url': layer_wfs_url,
        'layer_name': workspace.name + ':' + layer.name,
        'style_name': workspace.name + '_' + layer.name + '_' + str(index),
        'libraries': Library.objects.all(),
        'supported_crs': json.dumps(core_utils.get_supported_crs()),
        'preview_url': preview_url
    }

    return conf