本文整理汇总了Python中qgis.PyQt.QtCore.QFile类的典型用法代码示例。如果您正苦于以下问题:Python QFile类的具体用法?Python QFile怎么用?Python QFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QFile类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testQgsSvgMarkerSymbolLayer
def testQgsSvgMarkerSymbolLayer(self):
"""
Create a new style from a .sld file and match test
"""
mTestName = 'QgsSvgMarkerSymbolLayer'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
mDoc = QDomDocument(mTestName)
mFile = QFile(mFilePath)
mFile.open(QIODevice.ReadOnly)
mDoc.setContent(mFile, True)
mFile.close()
mSymbolLayer = QgsSvgMarkerSymbolLayer.createFromSld(mDoc.elementsByTagName('PointSymbolizer').item(0).toElement())
mExpectedValue = type(QgsSvgMarkerSymbolLayer(""))
mValue = type(mSymbolLayer)
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = 'skull.svg'
mValue = os.path.basename(mSymbolLayer.path())
print(("VALUE", mSymbolLayer.path()))
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = 12
mValue = mSymbolLayer.size()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = 45
mValue = mSymbolLayer.angle()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
示例2: testQgsSVGFillSymbolLayer
def testQgsSVGFillSymbolLayer(self):
"""
Create a new style from a .sld file and match test
"""
mTestName = 'QgsSVGFillSymbolLayer'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
mDoc = QDomDocument(mTestName)
mFile = QFile(mFilePath)
mFile.open(QIODevice.ReadOnly)
mDoc.setContent(mFile, True)
mFile.close()
mSymbolLayer = QgsSVGFillSymbolLayer.createFromSld(
mDoc.elementsByTagName('PolygonSymbolizer').item(0).toElement())
mExpectedValue = type(QgsSVGFillSymbolLayer(""))
mValue = type(mSymbolLayer)
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = 'accommodation_camping.svg'
mValue = os.path.basename(mSymbolLayer.svgFilePath())
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = 6
mValue = mSymbolLayer.patternWidth()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
示例3: testQgsCentroidFillSymbolLayerV2
def testQgsCentroidFillSymbolLayerV2(self):
"""
Create a new style from a .sld file and match test
"""
mTestName = 'QgsCentroidFillSymbolLayerV2'
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))
mDoc = QDomDocument(mTestName)
mFile = QFile(mFilePath)
mFile.open(QIODevice.ReadOnly)
mDoc.setContent(mFile, True)
mFile.close()
mSymbolLayer = QgsCentroidFillSymbolLayerV2.createFromSld(
mDoc.elementsByTagName('PointSymbolizer').item(0).toElement())
mExpectedValue = type(QgsCentroidFillSymbolLayerV2())
mValue = type(mSymbolLayer)
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = u'regular_star'
mValue = mSymbolLayer.subSymbol().symbolLayer(0).name()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = u'#55aaff'
mValue = mSymbolLayer.subSymbol().symbolLayer(0).color().name()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
mExpectedValue = u'#00ff00'
mValue = mSymbolLayer.subSymbol().symbolLayer(0).borderColor().name()
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
示例4: _add_raster_layer
def _add_raster_layer(self, raster_layer, layer_name, save_style=False):
"""Add a raster layer to the folder.
:param raster_layer: The layer to add.
:type raster_layer: QgsRasterLayer
:param layer_name: The name of the layer in the datastore.
:type layer_name: str
:param save_style: If we have to save a QML too. Default to False.
:type save_style: bool
:returns: A two-tuple. The first element will be True if we could add
the layer to the datastore. The second element will be the layer
name which has been used or the error message.
:rtype: (bool, str)
.. versionadded:: 4.0
"""
if not self.is_writable():
return False, 'The destination is not writable.'
output = QFileInfo(self.uri.filePath(layer_name + '.tif'))
source = QFileInfo(raster_layer.source())
if source.exists() and source.suffix() in ['tiff', 'tif']:
# If it's tiff file based.
QFile.copy(source.absoluteFilePath(), output.absoluteFilePath())
else:
# If it's not file based.
renderer = raster_layer.renderer()
provider = raster_layer.dataProvider()
crs = raster_layer.crs()
pipe = QgsRasterPipe()
pipe.set(provider.clone())
pipe.set(renderer.clone())
file_writer = QgsRasterFileWriter(output.absoluteFilePath())
file_writer.Mode(1)
file_writer.writeRaster(
pipe,
provider.xSize(),
provider.ySize(),
provider.extent(),
crs)
del file_writer
if save_style:
style_path = QFileInfo(self.uri.filePath(layer_name + '.qml'))
raster_layer.saveNamedStyle(style_path.absoluteFilePath())
assert output.exists()
return True, output.baseName()
示例5: removeCert
def removeCert(certFile):
certFile = certFile.replace("'", "")
file = QFile(certFile)
# set permission to allow removing on Win.
# On linux and Mac if file is set with QFile::>ReadUser
# does not create problem removing certs
if not file.setPermissions(QFile.WriteOwner):
raise Exception('Cannot change permissions on {}: error code: {}'.format(file.fileName(), file.error()))
if not file.remove():
raise Exception('Cannot remove {}: error code: {}'.format(file.fileName(), file.error()))
示例6: convert_metadata
def convert_metadata(self):
"""Method invoked when OK button is clicked."""
# Converter parameter
converter_parameter = {}
# Target exposure
if self.target_exposure_combo_box.isEnabled():
exposure_index = self.target_exposure_combo_box.currentIndex()
exposure_key = self.target_exposure_combo_box.itemData(
exposure_index, Qt.UserRole)
converter_parameter['exposure'] = exposure_key
# Metadata
current_metadata = self.keyword_io.read_keywords(self.layer)
old_metadata = convert_metadata(
current_metadata, **converter_parameter)
# Input
input_layer_path = self.layer.source()
input_directory_path = os.path.dirname(input_layer_path)
input_file_name = os.path.basename(input_layer_path)
input_base_name = os.path.splitext(input_file_name)[0]
input_extension = os.path.splitext(input_file_name)[1]
# Output
output_path = self.output_path_line_edit.text()
output_directory_path = os.path.dirname(output_path)
output_file_name = os.path.basename(output_path)
output_base_name = os.path.splitext(output_file_name)[0]
# Copy all related files, if exists
extensions = [
# Vector layer
'.shp', '.geojson', '.qml', '.shx', '.dbf', '.prj', 'qpj',
# Raster layer
'.tif', '.tiff', '.asc',
]
for extension in extensions:
source_path = os.path.join(
input_directory_path, input_base_name + extension)
if not os.path.exists(source_path):
continue
target_path = os.path.join(
output_directory_path, output_base_name + extension)
QFile.copy(source_path, target_path)
# Replace the metadata with the old one
output_file_path = os.path.join(
output_directory_path, output_base_name + input_extension
)
write_iso19115_metadata(
output_file_path, old_metadata, version_35=True)
示例7: createSimpleMemorial
def createSimpleMemorial(self):
tempDoc = QDomDocument()
simple = QFile(self.simpleMemorial)
simple.open(QIODevice.ReadOnly)
loaded = tempDoc.setContent(simple)
simple.close()
element = tempDoc.documentElement()
nodes = element.elementsByTagName("table")
table = nodes.item(0).toElement()
tr = tempDoc.createElement("tr")
tr.appendChild(self.createCellElement(tempDoc, u"MEMORIAL DESCRITIVO SINTÉTICO", 7, 0))
table.appendChild(tr)
tr = tempDoc.createElement("tr")
tr.appendChild(self.createCellElement(tempDoc, u"VÉRTICE", 0, 2))
tr.appendChild(self.createCellElement(tempDoc, "COORDENADAS", 2, 0))
tr.appendChild(self.createCellElement(tempDoc, "LADO", 0, 2))
tr.appendChild(self.createCellElement(tempDoc, "AZIMUTES", 2, 0))
tr.appendChild(self.createCellElement(tempDoc, u"DISTÂNCIA", 0, 0))
table.appendChild(tr)
tr = tempDoc.createElement("tr")
tr.appendChild(self.createCellElement(tempDoc, "E", 0, 0))
tr.appendChild(self.createCellElement(tempDoc, "N", 0, 0))
tr.appendChild(self.createCellElement(tempDoc, "PLANO", 0, 0))
tr.appendChild(self.createCellElement(tempDoc, "REAL", 0, 0))
tr.appendChild(self.createCellElement(tempDoc, "(m)", 0, 0))
table.appendChild(tr)
convergence = float(self.convergenciaEdit.text())
rowCount = self.tableWidget.rowCount()
for i in range(0,rowCount):
lineElement = tempDoc.createElement("tr")
lineElement.appendChild(self.createCellElement(tempDoc, self.tableWidget.item(i,0).text(), 0, 0))
lineElement.appendChild(self.createCellElement(tempDoc, self.tableWidget.item(i,1).text(), 0, 0))
lineElement.appendChild(self.createCellElement(tempDoc, self.tableWidget.item(i,2).text(), 0, 0))
lineElement.appendChild(self.createCellElement(tempDoc, self.tableWidget.item(i,3).text(), 0, 0))
lineElement.appendChild(self.createCellElement(tempDoc, self.tableWidget.item(i,4).text(), 0, 0))
lineElement.appendChild(self.createCellElement(tempDoc, self.tableWidget.item(i,5).text(), 0, 0))
lineElement.appendChild(self.createCellElement(tempDoc, self.tableWidget.item(i,6).text(), 0, 0))
table.appendChild(lineElement)
simple = open(self.simpleMemorial, "w", encoding='utf-8')
simple.write(tempDoc.toString())
simple.close()