def write(self, theRasterName): print theRasterName path = "%s/%s" % (self.testDataDir, theRasterName) rasterLayer = QgsRasterLayer(path, "test") if not rasterLayer.isValid(): return False provider = rasterLayer.dataProvider() tmpFile = QTemporaryFile() tmpFile.open() # fileName is no avialable until open tmpName = tmpFile.fileName() tmpFile.close() # do not remove when class is destroyed so that we can read # the file and see difference tmpFile.setAutoRemove(False) fileWriter = QgsRasterFileWriter(tmpName) pipe = QgsRasterPipe() if not pipe.set(provider.clone()): print "Cannot set pipe provider" return False projector = QgsRasterProjector() projector.setCRS(provider.crs(), provider.crs()) if not pipe.insert(2, projector): print "Cannot set pipe projector" return False fileWriter.writeRaster( pipe, provider.xSize(), provider.ySize(), provider.extent(), provider.crs()) checker = QgsRasterChecker() ok = checker.runTest("gdal", tmpName, "gdal", path) self.report += checker.report() # All OK, we can delete the file tmpFile.setAutoRemove(ok) return ok
def _get_cursor_columns(self, c): tf = QTemporaryFile() tf.open() tmp = tf.fileName() tf.close() q = QUrl.toPercentEncoding(c.sql) p = QgsVectorLayer("%s?query=%s" % (QUrl.fromLocalFile(tmp).toString(), q), "vv", "virtual") if not p.isValid(): return [] f = [f.name() for f in p.fields()] if p.geometryType() != QGis.WKBNoGeometry: gn = getQueryGeometryName(tmp) if gn: f += [gn] return f
def __init__(self, db, sql, parent=None): # create a virtual layer with non-geometry results q = QUrl.toPercentEncoding(sql) t = QTime() t.start() tf = QTemporaryFile() tf.open() tmp = tf.fileName() tf.close() p = QgsVectorLayer( "%s?query=%s" % (QUrl.fromLocalFile(tmp).toString(), q), "vv", "virtual") self._secs = t.elapsed() / 1000.0 if not p.isValid(): data = [] header = [] raise DbError(p.dataProvider().error().summary(), sql) else: header = [f.name() for f in p.fields()] has_geometry = False if p.geometryType() != QGis.WKBNoGeometry: gn = getQueryGeometryName(tmp) if gn: has_geometry = True header += [gn] data = [] for f in p.getFeatures(): a = f.attributes() if has_geometry: if f.geometry(): a += [f.geometry().exportToWkt()] else: a += [None] data += [a] self._secs = 0 self._affectedRows = len(data) BaseTableModel.__init__(self, header, data, parent)
def __init__(self, db, sql, parent=None): # create a virtual layer with non-geometry results q = QUrl.toPercentEncoding(sql) t = QTime() t.start() tf = QTemporaryFile() tf.open() tmp = tf.fileName() tf.close() p = QgsVectorLayer("%s?query=%s" % (QUrl.fromLocalFile(tmp).toString(), q), "vv", "virtual") self._secs = t.elapsed() / 1000.0 if not p.isValid(): data = [] header = [] raise DbError(p.dataProvider().error().summary(), sql) else: header = [f.name() for f in p.fields()] has_geometry = False if p.geometryType() != QGis.WKBNoGeometry: gn = getQueryGeometryName(tmp) if gn: has_geometry = True header += [gn] data = [] for f in p.getFeatures(): a = f.attributes() if has_geometry: if f.geometry(): a += [f.geometry().exportToWkt()] else: a += [None] data += [a] self._secs = 0 self._affectedRows = len(data) BaseTableModel.__init__(self, header, data, parent)
def write(self, theRasterName): print(theRasterName) path = "%s/%s" % (self.testDataDir, theRasterName) rasterLayer = QgsRasterLayer(path, "test") if not rasterLayer.isValid(): return False provider = rasterLayer.dataProvider() tmpFile = QTemporaryFile() tmpFile.open() # fileName is no avialable until open tmpName = tmpFile.fileName() tmpFile.close() # do not remove when class is destroyed so that we can read # the file and see difference tmpFile.setAutoRemove(False) fileWriter = QgsRasterFileWriter(tmpName) pipe = QgsRasterPipe() if not pipe.set(provider.clone()): print("Cannot set pipe provider") return False projector = QgsRasterProjector() projector.setCRS(provider.crs(), provider.crs()) if not pipe.insert(2, projector): print("Cannot set pipe projector") return False fileWriter.writeRaster(pipe, provider.xSize(), provider.ySize(), provider.extent(), provider.crs()) checker = QgsRasterChecker() ok = checker.runTest("gdal", tmpName, "gdal", path) self.report += checker.report() # All OK, we can delete the file tmpFile.setAutoRemove(ok) return ok