Questions tagged «pyqgis»

QGIS的Python绑定。

3
如何创建将序列添加到PostGIS中唯一标识符列的QGIS处理脚本?
有人可以帮助我创建QGIS处理脚本,以将序列添加到PostGIS中现有的唯一标识符列(类型:整数)吗? 这将非常有帮助,例如,作为错误#6798的解决方法。不幸的是,我没有任何Python经验。 CREATE SEQUENCE /*input_schema*/./*input_table*/_/*uic*/_seq OWNED BY /*input_schema*/./*input_table*/./*uic*/; SELECT SETVAL('/*input_schema*/./*input_table*/_/*uic*/_seq', (SELECT MAX(/*uic*/) FROM /*input_schema*/./*input_table*/)); ALTER TABLE /*input_schema*/./*input_table*/ ALTER COLUMN /*uic*/ SET DEFAULT nextval('/*input_schema*/./*input_table*/_/*uic*/_seq'::regclass);

2
在独立的python脚本中导入QGIS处理?
我想编写一些使用Qgis处理工具箱的独立脚本。 我已经读了一些线程(例如,在这里和这里),但是找不到有效的解决方案。 在Ubuntu Xenial 16.04 LTS上使用Qgis 2.16.1 我的脚本的import部分如下所示: # Python modules import sys import time import os # Qgis modules from qgis.core import * import qgis.utils from PyQt4.QtCore import QFileInfo, QSettings 有人知道我无法导入处理模块吗? 通过简单的导入处理,我得到了: Original exception was: Traceback (most recent call last): File "/home/steph/Documents/Projets/20141227-CIM_Bishkek/Scripts/python/00-projets/20160811-AnalysesUAVs/20160811-UAVAnalyse.py", line 36, in <module> import processing File …


1
如何使用Python更改项目变量?
我想使用Python控制台更改用户定义的项目变量(可以在项目设置|变量中手动编辑)的值。我在QgsExpressionContextScope类中跟踪了setVariable()函数,但实际上并未成功更改项目设置中的变量。到目前为止,我的代码: iface.mapCanvas().mapSettings().expressionContext().scope(0).setVariable('myvar',1) 我想我在不同的表达上下文中迷路了...
10 qgis  pyqgis 

2
运行python脚本后如何退出QGIS?
我想通过运行python脚本qgis --code myscript.py,然后立即退出。我正在使用iface.actionExit().trigger(),当我从python控制台运行QGIS时,它会杀死QGIS,但当放入传递给的脚本时,它不会--code。 立即退出的正确方法是什么?我正在运行QGIS 2.0.1 更新:我也试过了sys.exit()。QGIS将其捕获并弹出以下窗口: An error occured during execution of following code: execfile('myscript.py') Traceback (most recent call last): File "", line 1, in File "myscript.py", line 14, in sys.exit() SystemExit 更新:os.kill(os.getpid(), 9)可以,但这是一个肮脏的hack,我正在寻找更好的东西。
10 qgis  python  pyqgis 

2
从模板以编程方式加载composer并使用PyQGIS生成图集
我正在尝试构建一个插件来从文件加载打印作曲家,生成图集并导出到图像。到目前为止,我已经成功加载了模板并将其导出到图像。 我无法将图例中的任何图层(也在目录中)添加到导出的地图中,这将导致生成空白地图,并且所有字段表达式均不起作用。 # Get layers in the legend and append, must be a cleaner way to do this? layers = self.iface.legendInterface().layers() layerStringList = [] for layer in layers: layerID = layer.id() layerStringList.append(layerID) # Add layer to map render myMapRenderer = QgsMapRenderer() myMapRenderer.setLayerSet(layerStringList) myMapRenderer.setProjectionsEnabled(False) # Load template myComposition = QgsComposition(myMapRenderer) myFile …

1
在QGIS处理/ SEXTANTE中使用内存矢量层
我正在尝试qgis:clip从控制台运行算法,但是在使用内存层作为overlay参数时遇到错误。这是意料之中的,还是我做错了什么? 码: mem_layer = QgsVectorLayer("Polygon?crs=epsg:4326", "temp_layer", "memory") if not mem_layer.isValid(): raise Exception("Failed to create memory layer") mem_layer_provider = mem_layer.dataProvider() clip_polygon = QgsFeature() clip_polygon.setGeometry(QgsGeometry.fromRect( QgsRectangle( self.output_layer.extent().xMinimum() + 10, self.output_layer.extent().yMinimum() + 10, self.output_layer.extent().xMaximum() - 10, self.output_layer.extent().yMaximum() - 10 ) )) mem_layer_provider.addFeatures([clip_polygon]) mem_layer.updateExtents() output = self.output_layer_path + "2" processing.runalg("qgis:clip", layer, mem_layer, output) # …

2
如何在pyQGIS中更改矢量层的颜色?
添加矢量图层时是否可以更改颜色?我有一个带有水域的矢量层,并希望将其加载为蓝色样式。该层添加有: QgsMapLayerRegistry.instance().addMapLayer(self.vlayer) 加载后或加载时,我能以某种方式更改颜色吗?
10 qgis  python  pyqgis  color 

3
如何使用pyQGIS缩放到所选功能
我想创建一个选择功能并将其缩放的功能(在QGIS中类似)。因此,具有以下功能: QgsMapLayerRegistry.instance().addMapLayer(self.vlayer) def zoomTo(self): layer = self.vlayer atable = self.ui.table selectList=[] for i in atable.selectionModel().selectedRows(): ID = atable.item(i.row(),0).text() selectList.append(int(ID)) layer.setSelectedFeatures(selectList) 所选要素在地图上突出显示。但是我不知道如何对选定的要素进行“缩放”或将其聚焦在地图中间。
10 qgis  python  pyqgis 

1
在使用pyqgis遍历矢量层时,如何检查是否选择了要素?
在使用以下代码(从pyqgis cookbook的示例总结)遍历向量层的同时,有没有办法检查是否选择了要素? provider = vlayer.dataProvider() feat = QgsFeature() allAttrs = provider.attributeIndexes() provider.select(allAttrs) while provider.nextFeature(feat): geom = feat.geometry() attrs = feat.attributeMap() for (k,attr) in attrs.iteritems(): print "%d: %s" % (k, attr.toString()) 另外,我可以使用创建一个选定功能的列表vlayer.selectedFeatures(),但我希望有一种方法可以直接检查每个功能。
10 qgis  python  pyqgis  select 

5
如何在QGIS python控制台之外运行sextante算法?
我有点想从OSGeo4W发行版的独立python中找出运行sextante的方式。我要执行此操作的原因是,每当我要从“模型构建器”测试模型时,我都会在对话框中输入参数感到厌倦。 所以这是python脚本,我们称之为 test.py # as per http://qgis.org/pyqgis-cookbook/intro.html#using-pyqgis-in-custom-application from qgis.core import * # supply path to where is your qgis installed QgsApplication.setPrefixPath("C:/OSGeo4W/apps/qgis", True) # load providers QgsApplication.initQgis() from sextante.core.Sextante import Sextante Sextante.alglist() Sextante.alghelp("saga:slopeaspectcurvature") 我正在从批处理文件中调用 @echo off set OSGEO4W_ROOT=C:\OSGeo4W set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%OSGEO4W_ROOT%\apps\qgis\python\plugins;%HOME%/.qgis/python/plugins set PATH=%OSGEO4W_ROOT%\bin;%OSGEO4W_ROOT%\apps\qgis\bin;%OSGEO4W_ROOT%\apps\qgis\plugins python test.py 问题是它说,Algorithm not found而我从QGIS python控制台获得有意义的输出。 我觉得我想初始化一些东西。但是呢 除了使用GUI输入大量参数外,还有没有更好的方法来测试模型? 更新7/2/2012 …

3
学习PyQGIS的资源?[关闭]
已关闭。这个问题需要更加集中。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅通过编辑此帖子来关注一个问题。 2年前关闭。 我正在寻找一些学习PyQGIS的资源。 收集一些书籍或网站,提供一些实用的示例以学习语法或完成特定任务,这将是很有趣的。 理想情况下,这些资源应为初学者和有经验的用户提供一般指导。 在哪里可以找到QGIS教程和Web资源?这是一个非常相似的问题,但是它为学习QGIS(特别是PyQGIS)提供了帮助(实际上,它没有PyQGIS标签)。 有什么帮助吗?

1
使用PyQGIS添加字段并计算表达式?
我想使用PyQGIS添加一个新字段并计算每个功能的值。类似于字段计算器选项。 我的“字段计算器”表达式例如: y(start_point($geometry)) from PyQt4.QtCore import QVariant from qgis.core import QgsField, QgsExpression, QgsFeature vl = iface.activeLayer() vl.startEditing() #step 1 myField = QgsField( 'myNewColumn', QVariant.Float ) vl.addAttribute( myField ) idx = vl.fieldNameIndex( 'myNewColumn' ) #step 2 e = QgsExpression( 'y(start_point($geometry))' ) e.prepare( vl.pendingFields() ) for f in vl.getFeatures(): f[idx] = e.evaluate( …


5
使用开源工具计算卫星图像的图像边界/足迹?
我需要创建多个单层栅格图像的多边形轮廓,而不是范围/边界框,而是要创建没有nodata值的区域,如下所示:创建显示 shapepoint的Raster的shapefile?。 在上述问题的答案中,提到了Image Boundary插件,但是,我在运行于Ubuntu的QGIS 1.8.0 Lisboa中找不到它。 该工具仍然可用吗? 如果没有,是否有办法使用gdal,R,QGIS,GRASS或类似工具而不是ArcMap使用开源工具来做到这一点?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.