本文整理汇总了Python中sextante.core.SextanteUtils.SextanteUtils.getTempFilename方法的典型用法代码示例。如果您正苦于以下问题:Python SextanteUtils.getTempFilename方法的具体用法?Python SextanteUtils.getTempFilename怎么用?Python SextanteUtils.getTempFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sextante.core.SextanteUtils.SextanteUtils
的用法示例。
在下文中一共展示了SextanteUtils.getTempFilename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exportVectorLayer
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def exportVectorLayer(layer):
'''Takes a QgsVectorLayer and returns the filename to refer to it, which allows external
apps which support only file-based layers to use it. It performs the necessary export
in case the input layer is not in a standard format suitable for most applications, it is
a remote one or db-based (non-file based) one, or if there is a selection and it should be
used, exporting just the selected features.
Currently, the output is restricted to shapefiles, so anything that is not in a shapefile
will get exported'''
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = SextanteUtils.getTempFilename("shp")
provider = layer.dataProvider()
allAttrs = provider.attributeIndexes()
provider.select( allAttrs )
useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED)
if useSelection and layer.selectedFeatureCount() != 0:
writer = QgsVectorFileWriter( output, systemEncoding,provider.fields(), provider.geometryType(), provider.crs() )
selection = layer.selectedFeatures()
for feat in selection:
writer.addFeature(feat)
del writer
return output
else:
if (not unicode(layer.source()).endswith("shp")):
writer = QgsVectorFileWriter( output, systemEncoding,provider.fields(), provider.geometryType(), provider.crs() )
feat = QgsFeature()
while provider.nextFeature(feat):
writer.addFeature(feat)
del writer
return output
else:
return unicode(layer.source())
示例2: exportVectorLayer
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def exportVectorLayer(layer):
'''Takes a QgsVectorLayer and returns the filename to refer to it, which allows external
apps which support only file-based layers to use it. It performs the necessary export
in case the input layer is not in a standard format suitable for most applications, it is
a remote one or db-based (non-file based) one, or if there is a selection and it should be
used, exporting just the selected features.
Currently, the output is restricted to shapefiles, so anything that is not in a shapefile
will get exported.
It also export to a new file if the original one contains non-ascii characters'''
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = SextanteUtils.getTempFilename("shp")
provider = layer.dataProvider()
useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED)
if useSelection and layer.selectedFeatureCount() != 0:
writer = QgsVectorFileWriter(output, systemEncoding, layer.pendingFields(), provider.geometryType(), layer.crs())
selection = layer.selectedFeatures()
for feat in selection:
writer.addFeature(feat)
del writer
return output
else:
isASCII=True
try:
unicode(layer.source()).decode("ascii")
except UnicodeEncodeError:
isASCII=False
if (not unicode(layer.source()).endswith("shp") or not isASCII):
writer = QgsVectorFileWriter( output, systemEncoding, layer.pendingFields(), provider.geometryType(), layer.crs() )
for feat in layer.getFeatures():
writer.addFeature(feat)
del writer
return output
else:
return unicode(layer.source())
示例3: exportTable
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def exportTable( table):
'''Takes a QgsVectorLayer and returns the filename to refer to its attributes table,
which allows external apps which support only file-based layers to use it.
It performs the necessary export in case the input layer is not in a standard format
suitable for most applications, it isa remote one or db-based (non-file based) one
Currently, the output is restricted to dbf.
It also export to a new file if the original one contains non-ascii characters'''
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" )
output = SextanteUtils.getTempFilename("dbf")
provider = table.dataProvider()
isASCII=True
try:
unicode(table.source()).decode("ascii")
except UnicodeEncodeError:
isASCII=False
isDbf = unicode(table.source()).endswith("dbf") or unicode(table.source()).endswith("shp")
if (not isDbf or not isASCII):
writer = QgsVectorFileWriter( output, systemEncoding, provider.fields(), QGis.WKBNoGeometry, layer.crs() )
for feat in table.getFeatures():
writer.addFeature(feat)
del writer
return output
else:
filename = unicode(table.source())
if unicode(table.source()).endswith("shp"):
return filename[:-3] + "dbf"
else:
return filename
示例4: processAlgorithm
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def processAlgorithm(self, progress):
#TODO:check correct num of bands
input = self.getParameterValue(SplitRGBBands.INPUT)
temp = SextanteUtils.getTempFilename(None).replace('.','');
basename = os.path.basename(temp)
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
safeBasename = ''.join(c for c in basename if c in validChars)
temp = os.path.join(os.path.dirname(temp), safeBasename)
r = self.getOutputValue(SplitRGBBands.R)
g = self.getOutputValue(SplitRGBBands.G)
b = self.getOutputValue(SplitRGBBands.B)
commands = []
if SextanteUtils.isWindows():
commands.append("io_gdal 0 -GRIDS \"" + temp + "\" -FILES \"" + input+"\"")
commands.append("io_gdal 1 -GRIDS \"" + temp + "_0001.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + r + "\"");
commands.append("io_gdal 1 -GRIDS \"" + temp + "_0002.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + g + "\"");
commands.append("io_gdal 1 -GRIDS \"" + temp + "_0003.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + b + "\"");
else:
commands.append("libio_gdal 0 -GRIDS \"" + temp + "\" -FILES \"" + input + "\"")
commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0001.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + r + "\"");
commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0002.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + g + "\"");
commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0003.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + b + "\"");
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
SagaUtils.executeSaga(progress);
示例5: test_gdalogrsieveWithUnsupportedOutputFormat
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def test_gdalogrsieveWithUnsupportedOutputFormat(self):
outputs=sextante.runalg("gdalogr:sieve",raster(),2,0, SextanteUtils.getTempFilename("img"))
output=outputs['dst_filename']
self.assertTrue(os.path.isfile(output))
dataset=gdal.Open(output, GA_ReadOnly)
strhash=hash(str(dataset.ReadAsArray(0).tolist()))
self.assertEqual(strhash,-1353696889)
示例6: test_SagaRasterAlgorithmWithUnsupportedOutputFormat
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def test_SagaRasterAlgorithmWithUnsupportedOutputFormat(self):
outputs=sextante.runalg("saga:convergenceindex",raster(),0,0,SextanteUtils.getTempFilename("img"))
output=outputs['RESULT']
self.assertTrue(os.path.isfile(output))
dataset=gdal.Open(output, GA_ReadOnly)
strhash=hash(str(dataset.ReadAsArray(0).tolist()))
self.assertEqual(strhash, 485390137)
示例7: exportRasterLayer
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def exportRasterLayer(self, layer):
destFilename = SextanteUtils.getTempFilename("sgrd")
self.exportedLayers[layer]= destFilename
if SextanteUtils.isWindows():
return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer+"\""
else:
return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
示例8: test_SagaVectorAlgorithWithUnsupportedInputAndOutputFormat
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def test_SagaVectorAlgorithWithUnsupportedInputAndOutputFormat(self):
'''this tests both the exporting to shp and then the format change in the output layer'''
layer = sextante.getobject(polygonsGeoJson());
feature = layer.getFeatures().next()
selected = [feature.id()]
layer.setSelectedFeatures(selected)
outputs=sextante.runalg("saga:polygoncentroids",polygonsGeoJson(),True, SextanteUtils.getTempFilename("geojson"))
layer.setSelectedFeatures([])
output=outputs['CENTROIDS']
layer=QGisLayers.getObjectFromUri(output, True)
fields=layer.pendingFields()
expectednames=['ID','POLY_NUM_A','POLY_ST_A']
expectedtypes=['Real','Real','String']
names=[str(f.name()) for f in fields]
types=[str(f.typeName()) for f in fields]
self.assertEqual(expectednames, names)
self.assertEqual(expectedtypes, types)
features=sextante.getfeatures(layer)
self.assertEqual(1, len(features))
feature=features.next()
attrs=feature.attributes()
expectedvalues=["0","1.1","string a"]
values=[str(attr.toString()) for attr in attrs]
self.assertEqual(expectedvalues, values)
wkt='POINT(270787.49991451 4458955.46775295)'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
示例9: getCompatibleFileName
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def getCompatibleFileName(self, alg):
'''Returns a filename that is compatible with the algorithm that is going to generate this output.
If the algorithm supports the file format of the current output value, it returns that value. If not,
it returns a temporary file with a supported file format, to be used to generate the output result.'''
if self.value.endswith(self.getDefaultFileExtension(alg)):
return self.value
else:
if self.compatible is None:
self.compatible = SextanteUtils.getTempFilename(self.getDefaultFileExtension(alg))
return self.compatible;
示例10: getCompatibleFileName
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def getCompatibleFileName(self, alg):
'''Returns a filename that is compatible with the algorithm that is going to generate this output.
If the algorithm supports the file format of the current output value, it returns that value. If not,
it returns a temporary file with a supported file format, to be used to generate the output result.'''
ext = self.value[self.value.rfind(".") + 1:]
if ext in alg.provider.getSupportedOutputVectorLayerExtensions():
return self.value
else:
if self.compatible is None:
self.compatible = SextanteUtils.getTempFilename(self.getDefaultFileExtension(alg))
return self.compatible;
示例11: processAlgorithm
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def processAlgorithm(self, progress):
'''Here is where the processing itself takes place'''
ili = self.getParameterValue(self.ILI)
imd = SextanteUtils.getTempFilename('imd')
gml = SextanteUtils.getTempFilename('gml')
db = self.getParameterFromName(self.DB)
#output = self.getOutputValue(self.OUTPUT)
IliUtils.runIli2c(["-oIMD", "--out", imd, ili], progress)
gmlstr = extract_enums_asgml(imd)
f = open(gml, "w")
f.write(gmlstr)
f.close()
#IliUtils.runShellCmd(["ogr2ogr", "-f", "PostgreSQL", db.getOgrConnection(), gml], progress)
ogr2ogr(pszFormat=db.getOgrDriverName(),
pszDataSource=gml,
pszDestDataSource=db.getOgrConnection(),
errfunc=IliUtils.errfunc)
示例12: resampleRasterLayer
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def resampleRasterLayer(self,layer):
'''this is supposed to be run after having exported all raster layers'''
if layer in self.exportedLayers.keys():
inputFilename = self.exportedLayers[layer]
else:
inputFilename = layer
destFilename = SextanteUtils.getTempFilename("sgrd")
self.exportedLayers[layer]= destFilename
if SextanteUtils.isWindows():
s = "grid_tools \"Resampling\" -INPUT \"" + inputFilename + "\" -TARGET 0 -SCALE_UP_METHOD 4 -SCALE_DOWN_METHOD 4 -USER_XMIN " +\
str(self.xmin) + " -USER_XMAX " + str(self.xmax) + " -USER_YMIN " + str(self.ymin) + " -USER_YMAX " + str(self.ymax) +\
" -USER_SIZE " + str(self.cellsize) + " -USER_GRID \"" + destFilename + "\""
else:
s = "libgrid_tools \"Resampling\" -INPUT \"" + inputFilename + "\" -TARGET 0 -SCALE_UP_METHOD 4 -SCALE_DOWN_METHOD 4 -USER_XMIN " +\
str(self.xmin) + " -USER_XMAX " + str(self.xmax) + " -USER_YMIN " + str(self.ymin) + " -USER_YMAX " + str(self.ymax) +\
" -USER_SIZE " + str(self.cellsize) + " -USER_GRID \"" + destFilename + "\""
return s
示例13: checkSagaIsInstalled
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def checkSagaIsInstalled(cls):
if SextanteUtils.isWindows():
path = SagaUtils.sagaPath()
if path == "":
return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms."
cmdpath = os.path.join(path, "saga_cmd.exe")
if not os.path.exists(cmdpath):
return ("The specified SAGA folder does not contain a valid SAGA executable.\n"
+ "Please, go to the SEXTANTE settings dialog, and check that the SAGA\n"
+ "folder is correctly configured")
SAGA_INSTALLED = "/SextanteQGIS/SagaInstalled"
settings = QSettings()
if settings.contains(SAGA_INSTALLED):
return
try:
qgis = QGisLayers.iface
crs = qgis.mapCanvas().mapRenderer().destinationCrs()
fields = []
fields.append(QgsField("NUM_FIELD", QVariant.Int))
filename = SextanteUtils.getTempFilename("shp")
writer = SextanteVectorWriter(filename, None, fields, QGis.WKBPoint, crs)
for x in range(5):
for y in range(5):
attrs = []
attrs.append(QVariant(x))
outFeat = QgsFeature()
pt = QgsPoint(x, y)
outFeat.setGeometry(QgsGeometry.fromPoint(pt))
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
del writer.writer
del writer
from sextante.core.Sextante import runalg
result = runalg("saga:thiessenpolygons", filename, None)
if not os.path.exists(result['POLYGONS']):
return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."
except:
s = traceback.format_exc()
return "Error while checking SAGA installation. SAGA might not be correctly configured.\n" + s;
settings.setValue("/SextanteQGIS/SagaInstalled", True)
示例14: createSummaryTable
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def createSummaryTable(self):
createTable = False
for out in self.algs[0].outputs:
if isinstance(out, (OutputNumber,OutputString)):
createTable = True
break
if not createTable:
return
outputFile = SextanteUtils.getTempFilename("html")
f = open(outputFile, "w")
for alg in self.algs:
f.write("<hr>\n")
for out in alg.outputs:
if isinstance(out, (OutputNumber,OutputString)):
f.write("<p>" + out.description + ": " + str(out.value) + "</p>\n")
f.write("<hr>\n")
f.close()
SextanteResults.addResult(self.algs[0].name + "[summary]", outputFile)
示例15: runalgIterating
# 需要导入模块: from sextante.core.SextanteUtils import SextanteUtils [as 别名]
# 或者: from sextante.core.SextanteUtils.SextanteUtils import getTempFilename [as 别名]
def runalgIterating(alg, paramToIter, progress):
# generate all single-feature layers
settings = QSettings()
systemEncoding = settings.value("/UI/encoding", "System").toString()
layerfile = alg.getParameterValue(paramToIter)
layer = QGisLayers.getObjectFromUri(layerfile, False)
provider = layer.dataProvider()
allAttrs = provider.attributeIndexes()
provider.select(allAttrs)
feat = QgsFeature()
filelist = []
outputs = {}
while provider.nextFeature(feat):
output = SextanteUtils.getTempFilename("shp")
filelist.append(output)
writer = QgsVectorFileWriter(
output, systemEncoding, provider.fields(), provider.geometryType(), layer.crs()
)
writer.addFeature(feat)
del writer
# store output values to use them later as basenames for all outputs
for out in alg.outputs:
outputs[out.name] = out.value
# now run all the algorithms
i = 1
for f in filelist:
alg.setParameterValue(paramToIter, f)
for out in alg.outputs:
filename = outputs[out.name]
if filename:
filename = filename[: filename.rfind(".")] + "_" + str(i) + filename[filename.rfind(".") :]
out.value = filename
progress.setText("Executing iteration " + str(i) + "/" + str(len(filelist)) + "...")
progress.setPercentage((i * 100) / len(filelist))
if UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress()):
SextantePostprocessing.handleAlgorithmResults(alg, progress, False)
i += 1
else:
return False
return True