示例#1
0
    def importFromTsv(self, filename):
        # append file item
        rootItem = self.model.invisibleRootItem()
        basename = os.path.basename(filename)
        parent = QStandardItem(os.path.splitext(basename)[0])
        rootItem.appendRow([parent])

        # load service info from tsv file
        try:
            with codecs.open(filename, "r", "utf-8") as f:
                lines = f.readlines()
        except Exception as e:
            QgsMessageLog.logMessage(self.tr("Fail to read {0}: {1}").format(basename, unicode(e)),
                                     self.tr("TileLayerPlugin"))
            return False

        for i, line in enumerate(lines):
            if line.startswith("#"):
                continue
            vals = line.rstrip().split("\t")
            nvals = len(vals)
            try:
                if nvals < 3:
                    raise
                title, attribution, url = vals[0:3]
                if not url:
                    raise
                if nvals < 4:
                    serviceInfo = TileLayerDefinition(title, attribution, url)
                else:
                    yOriginTop = int(vals[3])
                    if nvals < 6:
                        serviceInfo = TileLayerDefinition(title, attribution, url, yOriginTop)
                    else:
                        zmin, zmax = map(int, vals[4:6])
                        if nvals < 10:
                            serviceInfo = TileLayerDefinition(title, attribution, url, yOriginTop, zmin, zmax)
                        else:
                            bbox = BoundingBox.fromString(",".join(vals[6:10]))
                            epsg = None
                            try:
                                epsg = int(vals[10])
                            except Exception as e:
                                i = 0
                            serviceInfo = TileLayerDefinition(title, attribution, url, yOriginTop, zmin, zmax, bbox, epsg)
            except:
                QgsMessageLog.logMessage(self.tr("Invalid line format: {} line {}").format(basename, i + 1),
                                         self.tr("TileLayerPlugin"))
                continue

            # append the service info into the tree
            vals = serviceInfo.toArrayForTreeView() + [len(self.serviceInfoList)]
            rowItems = map(QStandardItem, map(unicode, vals))
            parent.appendRow(rowItems)
            self.serviceInfoList.append(serviceInfo)
        return True
示例#2
0
 def createLayer(self):
   return TileLayer(self.plugin, TileLayerDefinition.createEmptyInfo())
示例#3
0
 def createLayer(self):
   layer = TileLayer(self.plugin, TileLayerDefinition.createEmptyInfo())
   self.plugin.addActionToLayer(layer)
   return layer