Exemplo n.º 1
0
 def getTables(self, cartodbUser, apiKey, multiuser=False):
     cartoDBApi = CartoDBApi(cartodbUser, apiKey, multiuser)
     cartoDBApi.fetchContent.connect(self.cbTables)
     cartoDBApi.error.connect(self.error)
     self.isLoadingTables = True
     # cartoDBApi.getUserTables(self.tablesPage)
     cartoDBApi.getUserTables(1, 100000)
Exemplo n.º 2
0
 def timerComplete():
     """On timer complete, check import process in CartoDB Servers"""
     # pylint: disable-msg=E1101
     cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey,
                              self.currentMultiuser)
     cartodb_api.fetchContent.connect(statusComplete)
     cartodb_api.checkUploadStatus(data['item_queue_id'])
Exemplo n.º 3
0
 def getTables(self, cartodbUser, apiKey, multiuser=False):
     cartoDBApi = CartoDBApi(cartodbUser, apiKey, multiuser)
     cartoDBApi.fetchContent.connect(self.cbTables)
     cartoDBApi.error.connect(self.error)
     self.isLoadingTables = True
     # cartoDBApi.getUserTables(self.tablesPage)
     cartoDBApi.getUserTables(1, 100000)
Exemplo n.º 4
0
    def cbGetLayers(self, data):
        item = self.ui.mapList.item(0)
        widget = self.ui.mapList.itemWidget(item)
        layer = widget.layer
        cartoCSS = self.convert2CartoCSS(layer)
        cartoDBApi = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
        layer1 = data['layers'][1]
        layer1['options']['tile_style'] = cartoCSS
        layer1["options"]["legend"] = None
        cartoDBApi.fetchContent.connect(self.showMessage)
        cartoDBApi.updateLayerInMap(self.currentViz['map_id'], layer1)

        for i in range(1, self.ui.mapList.count()):
            item = self.ui.mapList.item(i)
            widget = self.ui.mapList.itemWidget(item)
            layer = widget.layer
            qDebug('Agregando: {} en pos: {}'.format(layer.tableName(), i))
            cartoCSS = self.convert2CartoCSS(layer)
            # cartoDBApi.fetchContent.connect(self.cbCreateViz)
            newLayer = copy.deepcopy(layer1)
            newLayer["options"]["table_name"] = layer.tableName()
            newLayer["options"]["tile_style"] = cartoCSS
            newLayer["options"]["order"] = i + 1
            newLayer["order"] = i + 1
            newLayer["id"] = None
            cartoDBApi.addLayerToMap(self.currentViz['map_id'], newLayer)
Exemplo n.º 5
0
    def cbCreateViz(self, data):
        self.currentViz = data

        cartoDBApi = CartoDBApi(self.currentUser, self.currentApiKey,
                                self.currentMultiuser)
        cartoDBApi.fetchContent.connect(self.cbGetLayers)
        cartoDBApi.getLayersMap(data['map_id'])
Exemplo n.º 6
0
    def uploadZip(self, zip_path, widget, convertLayer=None, convert=False):
        """Upload Zipfile"""
        def completeUpload(data):
            """On complete upload"""
            timer = QTimer(self)

            self.ui.uploadBar.hide()
            self.ui.uploadingLB.hide()
            self.ui.uploadBT.setEnabled(True)
            self.ui.bar.clearWidgets()
            self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Upload Complete'),
                                    level=QgsMessageBar.INFO, duration=5)

            def statusComplete(res):
                """On CartoDB import proccess complete o fail"""
                if res['state'] == 'complete':
                    timer.stop()
                    self.ui.statusLB.setText(QApplication.translate('CartoDBPlugin', 'Ready'))
                    widget.setStatus(res['state'], 100)
                    self.ui.bar.clearWidgets()
                    self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Table {} created').format(res['table_name']),
                                            level=QgsMessageBar.INFO, duration=5)

                    if convert:
                        self.convert2CartoDB(convertLayer if convertLayer is not None else widget.layer, res['table_name'])
                elif res['state'] == 'failure':
                    timer.stop()
                    self.ui.statusLB.setText(QApplication.translate('CartoDBPlugin', '{} failed, {}').format(
                        widget.layer.name(), res['get_error_text']['title']))
                    widget.setStatus(res['state'])
                    self.ui.bar.clearWidgets()
                    self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Error uploading {}').format(widget.layer.name()),
                                            level=QgsMessageBar.WARNING, duration=5)
                else:
                    widget.setStatus(res['state'])

            def timerComplete():
                """On timer complete, check import process in CartoDB Servers"""
                # pylint: disable-msg=E1101
                cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
                cartodb_api.fetchContent.connect(statusComplete)
                cartodb_api.checkUploadStatus(data['item_queue_id'])

            timer.timeout.connect(timerComplete)
            timer.start(500)


        # pylint: disable-msg=E1101
        cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
        cartodb_api.fetchContent.connect(completeUpload)
        cartodb_api.progress.connect(self.progressUpload)
        self.ui.uploadBar.show()
        self.ui.uploadBT.setEnabled(False)
        self.ui.uploadingLB.setText(QApplication.translate('CartoDBPlugin', 'Uploading {}').format(widget.layer.name()))
        self.ui.uploadingLB.show()
        self.ui.bar.clearWidgets()
        cartodb_api.upload(zip_path)
Exemplo n.º 7
0
 def uploadZip(self, zipPath, widget):
     cartodbApi = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
     cartodbApi.fetchContent.connect(self.completeUpload)
     cartodbApi.progress.connect(self.progressUpload)
     self.ui.uploadBar.show()
     self.ui.uploadBT.setEnabled(False)
     self.ui.uploadingLB.setText(QApplication.translate('CartoDBPlugin', 'Uploading {}').format(widget.layer.name()))
     self.ui.uploadingLB.show()
     self.ui.bar.clearWidgets()
     cartodbApi.upload(zipPath)
Exemplo n.º 8
0
    def loadLayer(self):
        if self.sql is None:
            sql = 'SELECT * FROM ' + ((self.owner + '.') if self.owner != self.dlg.currentUser else '') + self.tableName
            if self.filterByExtent:
                extent = self.iface.mapCanvas().extent()
                sql = sql + " WHERE ST_Intersects(ST_GeometryFromText('{}', 4326), the_geom)".format(extent.asWktPolygon())
        else:
            sql = self.sql

        cartoDBApi = CartoDBApi(self.dlg.currentUser, self.dlg.currentApiKey)
        cartoDBApi.fetchContent.connect(self._loadData)
        cartoDBApi.download(sql)
Exemplo n.º 9
0
    def createViz(self):
        self.ui.bar.clearWidgets()
        self.ui.bar.pushMessage("Info", QApplication.translate('CartoDBPlugin', 'Creating Map'), level=QgsMessageBar.INFO)
        self.withWarnings = False

        item = self.ui.mapList.item(0)
        widget = self.ui.mapList.itemWidget(item)
        layer = widget.layer

        cartoDBApi = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
        cartoDBApi.fetchContent.connect(self.cbCreateViz)
        cartoDBApi.createVizFromTable(layer.tableName(), self.ui.mapNameTX.text())
Exemplo n.º 10
0
 def uploadZip(self, zipPath, widget):
     cartodbApi = CartoDBApi(self.currentUser, self.currentApiKey,
                             self.currentMultiuser)
     cartodbApi.fetchContent.connect(self.completeUpload)
     cartodbApi.progress.connect(self.progressUpload)
     self.ui.uploadBar.show()
     self.ui.uploadBT.setEnabled(False)
     self.ui.uploadingLB.setText(
         QApplication.translate('CartoDBPlugin',
                                'Uploading {}').format(widget.layer.name()))
     self.ui.uploadingLB.show()
     self.ui.bar.clearWidgets()
     cartodbApi.upload(zipPath)
Exemplo n.º 11
0
 def upload(self):
     registry = QgsMapLayerRegistry.instance()
     for layerItem in self.ui.layersList.selectedItems():
         widget = self.ui.layersList.itemWidget(layerItem)
         qDebug('Layer: ' + str(widget.layer.storageType()))
         if widget.layer.storageType() == 'ESRI Shapefile':
             zipPath = self.zipLayer(widget.layer)
             cartodbApi = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
             cartodbApi.fetchContent.connect(self.completeUpload)
             cartodbApi.progress.connect(self.progressUpload)
             self.ui.uploadBar.show()
             self.ui.uploadBT.setEnabled(False)
             self.ui.uploadingLB.setText('Uploading {}'.format(widget.layer.name()))
             self.ui.uploadingLB.show()
             cartodbApi.upload(zipPath)
Exemplo n.º 12
0
    def createViz(self):
        self.ui.bar.clearWidgets()
        self.ui.bar.pushMessage("Info",
                                QApplication.translate('CartoDBPlugin',
                                                       'Creating Map'),
                                level=QgsMessageBar.INFO)
        self.withWarnings = False

        item = self.ui.mapList.item(0)
        widget = self.ui.mapList.itemWidget(item)
        layer = widget.layer

        cartoDBApi = CartoDBApi(self.currentUser, self.currentApiKey,
                                self.currentMultiuser)
        cartoDBApi.fetchContent.connect(self.cbCreateViz)
        cartoDBApi.createVizFromTable(layer.tableName(),
                                      self.ui.mapNameTX.text())
Exemplo n.º 13
0
    def cbCreateViz(self, data):
        """Callback for create map, get created map data"""
        self.currentViz = data

        # pylint: disable-msg=E1101
        cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
        cartodb_api.fetchContent.connect(self.cbGetLayers)
        cartodb_api.getLayersMap(data['map_id'])
        if self.ui.publicCH.isChecked():
            data['privacy'] = 'PUBLIC'
            cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
            cartodb_api.updateViz(data)
Exemplo n.º 14
0
    def cbGetLayers(self, data):
        item = self.ui.mapList.item(0)
        widget = self.ui.mapList.itemWidget(item)
        layer = widget.layer
        cartoCSS = self.convert2CartoCSS(layer)
        cartoDBApi = CartoDBApi(self.currentUser, self.currentApiKey,
                                self.currentMultiuser)
        layer1 = data['layers'][1]
        layer1['options']['tile_style'] = cartoCSS
        layer1["options"]["legend"] = None
        cartoDBApi.fetchContent.connect(self.showMessage)
        cartoDBApi.updateLayerInMap(self.currentViz['map_id'], layer1)

        for i in range(1, self.ui.mapList.count()):
            item = self.ui.mapList.item(i)
            widget = self.ui.mapList.itemWidget(item)
            layer = widget.layer
            qDebug('Agregando: {} en pos: {}'.format(layer.tableName(), i))
            cartoCSS = self.convert2CartoCSS(layer)
            # cartoDBApi.fetchContent.connect(self.cbCreateViz)
            newLayer = copy.deepcopy(layer1)
            newLayer["options"]["table_name"] = layer.tableName()
            newLayer["options"]["tile_style"] = cartoCSS
            newLayer["options"]["order"] = i + 1
            newLayer["order"] = i + 1
            newLayer["id"] = None
            cartoDBApi.addLayerToMap(self.currentViz['map_id'], newLayer)
Exemplo n.º 15
0
    def createViz(self):
        """Create Map in CartoDB"""
        self.ui.bar.clearWidgets()
        self.ui.bar.pushMessage("Info", QApplication.translate('CartoDBPlugin', 'Creating Map'), level=QgsMessageBar.INFO)
        self.withWarnings = False

        for ly in self.cartoDBLayers:
            layer = ly
            if not layer.isSQL:
                break
            else:
                layer = None

        if layer is not None:
            # pylint: disable-msg=E1101
            cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
            cartodb_api.fetchContent.connect(self.cbCreateViz)
            cartodb_api.createVizFromTable(layer.fullTableName(), self.ui.mapNameTX.text(), self.ui.descriptionTX.toPlainText())
        else:
            self.ui.bar.clearWidgets()
            widget = self.ui.bar.createMessage(QApplication.translate('CartoDBPlugin', 'Error!!'),
                                               QApplication.translate('CartoDBPlugin', 'All layers are SQL layers'))
            self.ui.bar.pushWidget(widget, QgsMessageBar.CRITICAL)
Exemplo n.º 16
0
    def cbGetLayers(self, data):
        """Callback for getLayers, update cartoCSS to map layers"""
        layer = self.cartoDBLayers[0]
        carto_css = self.convert2CartoCSS(layer)
        # pylint: disable-msg=E1101
        cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
        layer1 = data['layers'][1]
        if layer.isSQL:
            layer1["options"]["query"] = layer.sql
        else:
            layer1["options"]["query"] = ""
            qDebug('Layer {}'.format(layer.fullTableName()))
            layer1["options"]["table_name"] = layer.fullTableName()
        layer1['options']['tile_style'] = carto_css
        layer1["options"]["legend"] = None
        layer1["options"]["order"] = 1
        layer1["order"] = 1
        cartodb_api.fetchContent.connect(self.showMessage)
        cartodb_api.updateLayerInMap(self.currentViz['map_id'], layer1)

        for i, layer in enumerate(self.cartoDBLayers[1:len(self.cartoDBLayers)]):
            order = i + 2
            qDebug('Agregando: {} en pos: {}'.format(layer.tableName(), order))
            carto_css = self.convert2CartoCSS(layer)
            # cartodb_api.fetchContent.connect(self.cbCreateViz)
            new_layer = copy.deepcopy(layer1)
            new_layer["options"]["tile_style"] = carto_css
            new_layer["options"]["order"] = order
            new_layer["options"]["legend"] = None
            new_layer["order"] = order
            new_layer["id"] = None
            if layer.isSQL:
                new_layer["options"]["query"] = layer.sql
            else:
                qDebug('Layer {}'.format(layer.fullTableName()))
                new_layer["options"]["query"] = ""
                new_layer["options"]["table_name"] = layer.fullTableName()
            cartodb_api.addLayerToMap(self.currentViz['map_id'], new_layer)
Exemplo n.º 17
0
    def cbCreateViz(self, data):
        self.currentViz = data

        cartoDBApi = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
        cartoDBApi.fetchContent.connect(self.cbGetLayers)
        cartoDBApi.getLayersMap(data['map_id'])
Exemplo n.º 18
0
 def getUserData(self, cartodbUser, apiKey, multiuser=False):
     cartoDBApi = CartoDBApi(cartodbUser, apiKey, multiuser)
     cartoDBApi.fetchContent.connect(self.cbUserData)
     cartoDBApi.getUserDetails()
Exemplo n.º 19
0
 def getUserData(self, cartodbUser, apiKey, multiuser=False):
     cartoDBApi = CartoDBApi(cartodbUser, apiKey, multiuser)
     cartoDBApi.fetchContent.connect(self.cbUserData)
     cartoDBApi.getUserDetails()
Exemplo n.º 20
0
    def uploadZip(self, zip_path, widget, convertLayer=None, convert=False):
        """Upload Zipfile"""
        def completeUpload(data):
            """On complete upload"""
            timer = QTimer(self)
            qDebug('data: {}'.format(str(data)))

            if 'error' in data and data['error'] is not None:
                self.ui.bar.clearWidgets()
                self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Error uploading layer: {}').format(data['error']),
                                        level=QgsMessageBar.CRITICAL, duration=5)
                widget.setStatus('Error', 0)
                return

            self.ui.uploadBar.hide()
            self.ui.uploadingLB.hide()
            self.ui.uploadBT.setEnabled(True)
            self.ui.bar.clearWidgets()
            self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Upload Complete'),
                                    level=QgsMessageBar.INFO, duration=5)

            def statusComplete(res):
                """On CARTO import proccess complete o fail"""
                if res['state'] == 'complete':
                    timer.stop()
                    self.ui.statusLB.setText(QApplication.translate('CartoDBPlugin', 'Ready'))
                    widget.setStatus(res['state'], 100)
                    self.ui.bar.clearWidgets()
                    self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Table {} created').format(res['table_name']),
                                            level=QgsMessageBar.INFO, duration=5)

                    if convert:
                        self.convert2CartoDB(convertLayer if convertLayer is not None else widget.layer, res['table_name'])
                elif res['state'] == 'failure':
                    timer.stop()
                    self.ui.statusLB.setText(QApplication.translate('CartoDBPlugin', '{} failed, {}').format(
                        widget.layer.name(), res['get_error_text']['title']))
                    widget.setStatus(res['state'])
                    self.ui.bar.clearWidgets()
                    self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Error uploading {}').format(widget.layer.name()),
                                            level=QgsMessageBar.WARNING, duration=5)
                else:
                    widget.setStatus(res['state'])

            def timerComplete():
                """On timer complete, check import process in CARTO Servers"""
                # pylint: disable-msg=E1101
                cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
                cartodb_api.fetchContent.connect(statusComplete)
                cartodb_api.checkUploadStatus(data['item_queue_id'])

            timer.timeout.connect(timerComplete)
            timer.start(500)


        # pylint: disable-msg=E1101
        cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
        cartodb_api.fetchContent.connect(completeUpload)
        cartodb_api.progress.connect(self.progressUpload)
        self.ui.uploadBar.show()
        self.ui.uploadBT.setEnabled(False)
        self.ui.uploadingLB.setText(QApplication.translate('CartoDBPlugin', 'Uploading {}').format(widget.layer.name()))
        self.ui.uploadingLB.show()
        self.ui.bar.clearWidgets()
        cartodb_api.upload(zip_path)
Exemplo n.º 21
0
 def timerComplete():
     """On timer complete, check import process in CARTO Servers"""
     # pylint: disable-msg=E1101
     cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
     cartodb_api.fetchContent.connect(statusComplete)
     cartodb_api.checkUploadStatus(data['item_queue_id'])