本文整理汇总了Python中qgis.gui.QgsMapCanvas.setCrsTransformEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python QgsMapCanvas.setCrsTransformEnabled方法的具体用法?Python QgsMapCanvas.setCrsTransformEnabled怎么用?Python QgsMapCanvas.setCrsTransformEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.gui.QgsMapCanvas
的用法示例。
在下文中一共展示了QgsMapCanvas.setCrsTransformEnabled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PdfMaker
# 需要导入模块: from qgis.gui import QgsMapCanvas [as 别名]
# 或者: from qgis.gui.QgsMapCanvas import setCrsTransformEnabled [as 别名]
#.........这里部分代码省略.........
self.canvas.enableAntiAliasing(True)
self.template_path = template_path
def __del__(self):
"""Destructor."""
del self.app
def _load_template(self):
"""Load the template.
:return: QgsComposition containing the loaded template.
:rtype: QgsComposition
"""
template_file = file(self.template_path)
template_content = template_file.read()
template_file.close()
document = QDomDocument()
document.setContent(template_content)
composition = QgsComposition(self.canvas.mapSettings())
# You can use this to replace any string like this [key]
# in the template with a new value. e.g. to replace
# [date] pass a map like this {'date': '1 Jan 2012'}
substitution_map = {
'DATE_TIME_START': 'foo',
'DATE_TIME_END': 'bar'}
composition.loadFromTemplate(document, substitution_map)
return composition
def _load_layers(self):
"""Manually load all the layers for our project.
:return: A list of QgsMapLayer instances.
:rtype: list
"""
layers = []
# First the RW layer
host = 'db'
port = '5432'
user = 'docker'
password = 'docker'
dbname = 'gis'
uri = QgsDataSourceURI()
uri.setConnection(host, port, dbname, user, password)
schema = 'public'
table = 'flood_mapper_rw'
geometry_column = 'geometry'
where_clause = ''
title = 'RW'
uri.setDataSource(schema, table, geometry_column, where_clause)
layer = QgsVectorLayer(uri.uri(), title, 'postgres')
QgsMapLayerRegistry.instance().addMapLayer(layer, False)
canvas_layer = QgsMapCanvasLayer(layer)
layers.append(canvas_layer)
# Now the JK layer
path = './data/jk.shp'
title = 'JK'
layer = QgsVectorLayer(path, title, 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(layer, False)
canvas_layer = QgsMapCanvasLayer(layer)
layers.append(canvas_layer)
return layers
def make_pdf(self, pdf_path):
"""Generate a pdf for the given project and template files.
:param pdf_path: Absolute path for the output PDF file.
:type pdf_path: str
"""
layers = self._load_layers()
self.canvas.setLayerSet(layers)
if self.canvas.layerCount() < 1:
print 'No layers loaded from this project, exiting.'
return
self.canvas.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
self.canvas.setCrsTransformEnabled(True)
self.canvas.zoomToFullExtent()
print 'Extent: %s' % self.canvas.mapSettings().extent().toString()
# self._load_project()
composition = self._load_template()
# You must set the id in the template
map_item = composition.getComposerItemById('map')
map_item.setMapCanvas(self.canvas)
map_item.zoomToExtent(self.canvas.extent())
# You must set the id in the template
legend_item = composition.getComposerItemById('legend')
legend_item.updateLegend()
composition.refreshItems()
composition.exportAsPDF(pdf_path)
QgsProject.instance().clear()