Esempio n. 1
0
 def layer_updated_handler(self, sender, **kwargs):
     layer = kwargs['layer']
     try:
         lm = LayerMetadata.objects.get(layer=layer)
         (ds_type, layer_info) = mapservice.getResourceInfo(
             layer.datastore.workspace.name, layer.datastore, layer.name,
             "json")
         if self.xmlapi.gn_auth(self.user, self.password):
             self.xmlapi.gn_update_metadata(lm.metadata_uuid, layer,
                                            layer.abstract, layer_info,
                                            ds_type)
             self.xmlapi.gn_unauth()
     except Exception as e:
         logger.exception("layer metadata update failed")
         pass
Esempio n. 2
0
    def layer_created_handler(self, sender, **kwargs):
        layer = kwargs['layer']
        try:
            (ds_type, layer_info) = mapservice.getResourceInfo(
                layer.datastore.workspace.name, layer.datastore, layer.name,
                "json")
            muuid = self.metadata_insert(layer, layer.abstract,
                                         layer.datastore.workspace, layer_info,
                                         ds_type)
            if muuid:
                lm = LayerMetadata(layer=layer,
                                   metadata_uuid=muuid[0],
                                   metadata_id=muuid[1])
                lm.save()

        except Exception as e:
            logger.exception("layer metadata create failed")
            pass
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")

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

    preview_url = settings.GVSIGOL_SERVICES[
        'URL'] + '/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=preview_polygon'

    conf = {
        '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()),
        'extent':
        json.dumps(resource.get('coverage').get('nativeBoundingBox')),
        'extent_epsg': resource.get('coverage').get('grid').get('crs'),
        'preview_url': preview_url
    }

    return conf
Esempio n. 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