コード例 #1
0
def create_datastore(request, username, ds_name, ws):

    ds_type = 'v_PostGIS'
    description = 'BBDD ' + ds_name

    dbhost = settings.GVSIGOL_USERS_CARTODB['dbhost']
    dbport = settings.GVSIGOL_USERS_CARTODB['dbport']
    dbname = settings.GVSIGOL_USERS_CARTODB['dbname']
    dbuser = settings.GVSIGOL_USERS_CARTODB['dbuser']
    dbpassword = settings.GVSIGOL_USERS_CARTODB['dbpassword']
    connection_params = '{ "host": "' + dbhost + '", "port": "' + dbport + '", "database": "' + dbname + '", "schema": "' + ds_name + '", "user": "******", "passwd": "' + dbpassword + '", "dbtype": "postgis" }'

    if create_schema(ds_name):
        gs = geographic_servers.get_instance().get_server_by_id(ws.server.id)
        if gs.createDatastore(ws, ds_type, ds_name, description,
                              connection_params):
            # save it on DB if successfully created
            datastore = Datastore(workspace=ws,
                                  type=ds_type,
                                  name=ds_name,
                                  description=description,
                                  connection_params=connection_params,
                                  created_by=username)
            datastore.save()

            return datastore
コード例 #2
0
ファイル: utils.py プロジェクト: nyaconsulting/gvsig-online
def create_workspace(server_id, ws_name, uri, values, username):
    # first create the ws on the backend
    gs = geographic_servers.get_instance().get_server_by_id(server_id)
    if gs.createWorkspace(ws_name, uri):
        # save it on DB if successfully created
        newWs = Workspace(**values)
        newWs.created_by = username
        newWs.save()
        gs.reload_nodes()
        return newWs
コード例 #3
0
ファイル: utils.py プロジェクト: nyaconsulting/gvsig-online
def add_datastore(workspace, type, name, description, connection_params,
                  username):
    gs = geographic_servers.get_instance().get_server_by_id(
        workspace.server.id)
    # first create the datastore on the backend
    if gs.createDatastore(workspace, type, name, description,
                          connection_params):

        # save it on DB if successfully created
        datastore = Datastore(workspace=workspace,
                              type=type,
                              name=name,
                              description=description,
                              connection_params=connection_params,
                              created_by=username)
        datastore.save()
        return datastore
コード例 #4
0
ファイル: apps.py プロジェクト: GPGespromat/gvsig-online
 def _updateLayerInfo(self):
     import geographic_servers
     from models import Layer, Datastore, Workspace
     layer_list = Layer.objects.filter(external=False)
     for l in layer_list:
         datastore = Datastore.objects.get(id=l.datastore_id)
         workspace = Workspace.objects.get(id=datastore.workspace_id)
         server = geographic_servers.get_instance().get_server_by_id(workspace.server.id)
         try:
             (ds_type, layer_info) = server.getResourceInfo(workspace.name, datastore, l.name, "json")
             if ds_type == 'imagemosaic':
                 ds_type = 'coverage'
             l.native_srs = layer_info[ds_type]['srs']
             l.native_extent = str(layer_info[ds_type]['nativeBoundingBox']['minx']) + ',' + str(layer_info[ds_type]['nativeBoundingBox']['miny']) + ',' + str(layer_info[ds_type]['nativeBoundingBox']['maxx']) + ',' + str(layer_info[ds_type]['nativeBoundingBox']['maxy'])
             l.latlong_extent = str(layer_info[ds_type]['latLonBoundingBox']['minx']) + ',' + str(layer_info[ds_type]['latLonBoundingBox']['miny']) + ',' + str(layer_info[ds_type]['latLonBoundingBox']['maxx']) + ',' + str(layer_info[ds_type]['latLonBoundingBox']['maxy'])
             
         except Exception as e:
             l.default_srs = 'EPSG:4326'
             l.native_extent = '-180,-90,180,90'
             l.latlong_extent = '-180,-90,180,90'
         l.save()
コード例 #5
0
ファイル: utils.py プロジェクト: nyaconsulting/gvsig-online
def clone_layer(target_datastore,
                layer,
                layer_group,
                copy_data=True,
                permissions=CLONE_PERMISSION_CLONE):
    if layer.type == 'v_PostGIS':  # operation not defined for the rest of types
        # create the table
        dbhost = settings.GVSIGOL_USERS_CARTODB['dbhost']
        dbport = settings.GVSIGOL_USERS_CARTODB['dbport']
        dbname = settings.GVSIGOL_USERS_CARTODB['dbname']
        dbuser = settings.GVSIGOL_USERS_CARTODB['dbuser']
        dbpassword = settings.GVSIGOL_USERS_CARTODB['dbpassword']
        i = Introspect(database=dbname,
                       host=dbhost,
                       port=dbport,
                       user=dbuser,
                       password=dbpassword)
        table_name = layer.source_name if layer.source_name else layer.name
        new_table_name = i.clone_table(layer.datastore.name,
                                       table_name,
                                       target_datastore.name,
                                       table_name,
                                       copy_data=copy_data)
        i.close()

        from gvsigol_services import views
        server = geographic_servers.get_instance().get_server_by_id(
            target_datastore.workspace.server.id)

        layerConf = ast.literal_eval(layer.conf) if layer.conf else {}
        extraParams = {
            "max_features": layerConf.get('featuretype', {}).get('', 0)
        }
        # add layer to Geoserver
        views.do_add_layer(server, target_datastore, new_table_name,
                           layer.title, layer.queryable, extraParams)

        new_name = new_table_name
        if Layer.objects.filter(name=new_name,
                                datastore=target_datastore).exists():
            base_name = target_datastore.workspace.name + "_" + layer.name
            new_name = base_name
            i = 1
            salt = ''
            while Layer.objects.filter(name=layer.name,
                                       datastore=target_datastore).exists():
                new_name = base_name + '_' + str(i) + salt
                i = i + 1
                if (i % 1000) == 0:
                    salt = '_' + get_random_string(3)

        # clone layer
        old_id = layer.pk
        layer.pk = None
        layer.name = new_name
        layer.datastore = target_datastore
        if layer_group is not None:
            layer.layer_group = layer_group
        layer.save()

        new_layer_instance = Layer.objects.get(id=layer.pk)
        old_instance = Layer.objects.get(id=old_id)

        if permissions != CLONE_PERMISSION_SKIP:
            admin_group = UserGroup.objects.get(name__exact='admin')
            read_groups = [admin_group]
            write_groups = [admin_group]

            for lrg in LayerReadGroup.objects.filter(layer=old_instance):
                lrg.pk = None
                lrg.layer = new_layer_instance
                lrg.save()
                read_groups.append(lrg.group)

            for lwg in LayerWriteGroup.objects.filter(layer=old_instance):
                lwg.pk = None
                lwg.layer = new_layer_instance
                lwg.save()
                write_groups.append(lwg.group)
            server.setLayerDataRules(layer, read_groups, write_groups)

        set_time_enabled(server, new_layer_instance)

        for enum in LayerFieldEnumeration.objects.filter(layer=old_instance):
            enum.pk = None
            enum.layer = new_layer_instance
            enum.save()

        from gvsigol_symbology.services import clone_layer_styles
        clone_layer_styles(server, old_instance, new_layer_instance)

        for lyr_res in LayerResource.objects.filter(layer=old_instance):
            lyr_res.pk = None
            lyr_res.layer = new_layer_instance
            lyr_res.save()
        """
        TODO:
        - models from plugins (for instance metadata, charts, etc)
        """
        server.updateThumbnail(new_layer_instance, 'create')

        core_utils.toc_add_layer(new_layer_instance)
        server.createOrUpdateGeoserverLayerGroup(
            new_layer_instance.layer_group)
        return new_layer_instance
    return layer