Answers:
看一看PyQGIS Cookbook。
按照有关如何遍历矢量层的示例进行操作。访问几何,可以应用buffer()方法。另请参见QGIS API:http://www.qgis.org/api/classQgsGeometry.html#a98208752e1beb1a5d3a7eedffbfdb2e4
您可以通过不同的方式通过PyQGIS控制台获得所需的内容:
from qgis.utils import iface
from qgis.analysis import QgsGeometryAnalyzer
mc = iface.mapCanvas()
layer = mc.currentLayer()
QgsGeometryAnalyzer().buffer(layer, "path_to/output.shp", 500, False, False, -1)
from sextante.core.Sextante import Sextante
Sextante.runalg("ftools:fixeddistancebuffer","input_path.shp", False, 500, 5, True, "output_path_buffer.shp")
要获取sextante参数,请Sextante.alghelp("ftools:fixeddistancebuffer")
在PyQGIS控制台中输入。
希望这可以帮助 !
如果您需要基本代码,可以尝试:
#Don't forget to Toggle Editing
lyr = qgis.utils.iface.activeLayer()
provider = lyr.dataProvider()
feat= QgsFeature()
alls = provider.attributeIndexes()
provider.select(alls)
while provider.nextFeature(feat):
buff = feat.geometry().buffer(5,2)
lyr.dataProvider().changeGeometryValues({feat.id(): buff})
仅需添加一点即可添加到最后的回复中。
要搜索有关给定主题的SEXTANTE算法,请使用Sextante.alglist()。例如,在搜索包含“缓冲区”的内容时,您可以
>>> from sextante.core.Sextante import Sextante
>>> Sextante.alglist("buffer")
您会得到:
Grid Buffer------------------------------------------>saga:gridbuffer
Grid Proximity Buffer-------------------------------->saga:gridproximitybuffer
Shapes Buffer---------------------------------------->saga:shapesbuffer
Threshold Buffer------------------------------------->saga:thresholdbuffer
Fixed distance buffer-------------------------------->ftools:fixeddistancebuffer
Variable distance buffer----------------------------->ftools:variabledistancebuffer
r.buffer - Creates a raster map layer showing buffer zones surrounding cells that contain non-NULL category values.--->grass:r.buffer
v.buffer.angle--------------------------------------->grass:v.buffer.angl
v.buffer.column - Creates a buffer around features of given type.--->grass:v.buffer.column
v.buffer.distance - Creates a buffer around features of given type.--->grass:v.buffer.distance
v.buffer.minordistance------------------------------->grass:v.buffer.minordistance
这样,您可以找到要调用的算法的名称(ftools:fixeddistancebuffer,在以上回复中提出的示例中)
您可以在SEXTANTE中将脚本转换为新算法。SEXTANTE文档包含有关此内容的详细信息。