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: QgsMessageLog.logMessage( self.tr("Fail to read: {}").format(basename), self.tr("TileLayerPlugin")) return False for i, line in enumerate(lines): if line.startswith("#"): continue vals = line.split("\t") nvals = len(vals) try: if nvals < 3: raise title, credit, url = vals[0:3] if nvals < 4: serviceInfo = TileServiceInfo(title, credit, url) else: yOriginTop = int(vals[3]) if nvals < 6: serviceInfo = TileServiceInfo(title, credit, url, yOriginTop) else: zmin, zmax = map(int, vals[4:6]) if nvals < 10: serviceInfo = TileServiceInfo( title, credit, url, yOriginTop, zmin, zmax) else: bbox = BoundingBox.fromString(",".join(vals[6:10])) serviceInfo = TileServiceInfo( title, credit, url, yOriginTop, zmin, zmax, bbox) 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
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
def readXml(self, node): self.readCustomProperties(node) self.layerDef.title = self.customProperty("title", "") self.layerDef.attribution = self.customProperty("credit", "") if self.layerDef.attribution == "": self.layerDef.attribution = self.customProperty("providerName", "") # for compatibility with 0.11 self.layerDef.serviceUrl = self.customProperty("serviceUrl", "") self.layerDef.yOriginTop = int(self.customProperty("yOriginTop", 1)) self.layerDef.zmin = int(self.customProperty("zmin", TileDefaultSettings.ZMIN)) self.layerDef.zmax = int(self.customProperty("zmax", TileDefaultSettings.ZMAX)) bbox = self.customProperty("bbox", None) if bbox: self.layerDef.bbox = BoundingBox.fromString(bbox) self.setExtent(BoundingBox.degreesToMercatorMeters(self.layerDef.bbox).toQgsRectangle()) # layer style self.setTransparency(int(self.customProperty("transparency", 0))) self.setBlendModeByName(self.customProperty("blendMode", self.DEFAULT_BLEND_MODE)) self.setSmoothRender(int(self.customProperty("smoothRender", self.DEFAULT_SMOOTH_RENDER))) self.creditVisibility = int(self.customProperty("creditVisibility", 1)) # max connections of downloader self.maxConnections = HonestAccess.maxConnections(self.layerDef.serviceUrl) return True