本文整理匯總了Python中qgis.core.QgsRasterProjector類的典型用法代碼示例。如果您正苦於以下問題:Python QgsRasterProjector類的具體用法?Python QgsRasterProjector怎麽用?Python QgsRasterProjector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了QgsRasterProjector類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testImportIntoGpkg
def testImportIntoGpkg(self):
# init target file
test_gpkg = tempfile.mktemp(suffix='.gpkg', dir=self.testDataDir)
gdal.GetDriverByName('GPKG').Create(test_gpkg, 1, 1, 1)
source = QgsRasterLayer(os.path.join(self.testDataDir, 'raster', 'band3_byte_noct_epsg4326.tif'), 'my', 'gdal')
self.assertTrue(source.isValid())
provider = source.dataProvider()
fw = QgsRasterFileWriter(test_gpkg)
fw.setOutputFormat('gpkg')
fw.setCreateOptions(['RASTER_TABLE=imported_table', 'APPEND_SUBDATASET=YES'])
pipe = QgsRasterPipe()
self.assertTrue(pipe.set(provider.clone()))
projector = QgsRasterProjector()
projector.setCrs(provider.crs(), provider.crs())
self.assertTrue(pipe.insert(2, projector))
self.assertEqual(fw.writeRaster(pipe,
provider.xSize(),
provider.ySize(),
provider.extent(),
provider.crs()), 0)
# Check that the test geopackage contains the raster layer and compare
rlayer = QgsRasterLayer('GPKG:%s:imported_table' % test_gpkg)
self.assertTrue(rlayer.isValid())
out_provider = rlayer.dataProvider()
self.assertEqual(provider.block(1, provider.extent(), source.width(), source.height()).data(),
out_provider.block(1, out_provider.extent(), rlayer.width(), rlayer.height()).data())
# remove result file
os.unlink(test_gpkg)
示例2: write
def write(self, theRasterName):
print theRasterName
path = "%s/%s" % (self.testDataDir, theRasterName)
# myFileInfo = QFileInfo( path )
# myBaseName = myFileInfo.baseName()
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 destroyd 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
# nuller = QgsRasterNuller()
# nuller.setNoData( ... )
# if not pipe.insert( 1, nuller ):
# print "Cannot set pipe nuller"
# 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
示例3: _testGeneratePyramids
def _testGeneratePyramids(self, pyramidFormat):
tmpName = tempfile.mktemp(suffix='.tif')
source = QgsRasterLayer(os.path.join(self.testDataDir, 'raster', 'byte.tif'), 'my', 'gdal')
self.assertTrue(source.isValid())
provider = source.dataProvider()
fw = QgsRasterFileWriter(tmpName)
fw.setBuildPyramidsFlag(QgsRaster.PyramidsFlagYes)
fw.setPyramidsFormat(pyramidFormat)
fw.setPyramidsList([2])
pipe = QgsRasterPipe()
self.assertTrue(pipe.set(provider.clone()))
projector = QgsRasterProjector()
projector.setCrs(provider.crs(), provider.crs())
self.assertTrue(pipe.insert(2, projector))
self.assertEqual(fw.writeRaster(pipe,
provider.xSize(),
provider.ySize(),
provider.extent(),
provider.crs()), 0)
del fw
ds = gdal.Open(tmpName)
self.assertEqual(ds.GetRasterBand(1).GetOverviewCount(), 1)
fl = ds.GetFileList()
if pyramidFormat == QgsRaster.PyramidsGTiff:
self.assertEqual(len(fl), 2, fl)
self.assertIn('.ovr', fl[1])
elif pyramidFormat == QgsRaster.PyramidsInternal:
self.assertEqual(len(fl), 1, fl)
elif pyramidFormat == QgsRaster.PyramidsErdas:
self.assertEqual(len(fl), 2, fl)
self.assertIn('.aux', fl[1])
os.unlink(tmpName)