QGIS开发之矢量图层的使用
来源:互联网 发布:淘宝小美工作室假货吗 编辑:程序博客网 时间:2024/05/16 11:47
- Retrieving information about attributes
- Selecting features
- Iterating over Vector Layer
3.1 Accessing attributes
3.2 Iterating over selected features
3.3 Iterating over a subset of features - Modifying Vector Layers
4.1 Add Features
4.2 Delete Features
4.3 Modify Features
4.4 Adding and Removing Fields - Modifying Vector Layers with an Editing Buffer
- Using Spatial Index
- Writing Vector Layers
- Memory Provider
- Appearance (Symbology) of Vector Layers
9.1 Single Symbol Renderer
9.2 Categorized Symbol Renderer
9.3 Graduated Symbol Renderer
9.4 Working with Symbols
9.4.1 Working with Symbol Layers
9.4.2 Creating Custom Symbol Layer Types - Creating Custom Renderers
- Further Topics
- 检索关于属性的信息
- 选择要素
- 遍历矢量图层
- 访问属性
1 检索关于属性的信息
You can retrieve information about the fields associated with a vector layer by calling pendingFields() on a QgsVectorLayer instance:
可以通过调用QgsVectorLayer实例中的的pendingFields()来检索与矢量图层关联的字段的信息:
# "layer" is a QgsVectorLayer instancefor field in layer.pendingFields(): print field.name(), field.typeName()
NOTE:Starting from QGIS 2.12 there is also a fields() in QgsVectorLayer which is an alias to pendingFields().
注意:从QGIS 2.12开始,QgsVectorLayer中还有一个fields(),它是pendingFields()的别名。
2 选择要素
In QGIS desktop, features can be selected in different ways, the user can click on a feature, draw a rectangle on the map canvas or use an expression filter. Selected features are normally highlighted in a different color (default is yellow) to draw user’s attention on the selection. Sometimes can be useful to programmatically select features or to change the default color.
在QGIS桌面中,要素可以以不同的方式进行选择,用户可以点击要素,在地图画布上绘制一个矩形或使用表达式过滤器。 所选功能通常以不同的颜色突出显示(默认为黄色),以吸引用户对选择的注意。 有时可以通过编程方式选择功能或更改默认颜色。
To change the selection color you can use setSelectionColor() method of QgsMapCanvas as shown in the following example:
可以使用QgsMapCanvas中的setSelectionColor() 方法改变选择集的颜色,代码如下:
iface.mapCanvas().setSelectionColor( QColor("red") )
To add features to the selected features list for a given layer, you can call setSelectedFeatures() passing to it the list of features IDs:
要为指定图层的所选要素列表添加要素,可以调用setSelectedFeatures()将要素的ID列表传递给它:
# Get the active layer (must be a vector layer)layer = iface.activeLayer()# Get the first feature from the layerfeature = layer.getFeatures().next()# Add this features to the selected listlayer.setSelectedFeatures([feature.id()])
To clear the selection, just pass an empty list:
若要清空选择集,只需要将列表设为空
layer.setSelectedFeatures([])
3 遍历矢量图层
Iterating over the features in a vector layer is one of the most common tasks. Below is an example of the simple basic code to perform this task and showing some information about each feature. the layer variable is assumed to have a QgsVectorLayer object
遍历矢量图层中的要素是最常见的需求之一。 以下是执行此任务的简单基本代码的示例,显示有关每个要素的一些信息。 该图层变量假定有一个QgsVectorLayer对象
iter = layer.getFeatures()for feature in iter: # retrieve every feature with its geometry and attributes # fetch geometry geom = feature.geometry() print "Feature ID %d: " % feature.id() # show some information about the feature if geom.type() == QGis.Point: x = geom.asPoint() print "Point: " + str(x) elif geom.type() == QGis.Line: x = geom.asPolyline() print "Line: %d points" % len(x) elif geom.type() == QGis.Polygon: x = geom.asPolygon() numPts = 0 for ring in x: numPts += len(ring) print "Polygon: %d rings with %d points" % (len(x), numPts) else: print "Unknown" # fetch attributes attrs = feature.attributes() # attrs is a list. It contains all the attribute values of this feature print attrs
4 访问属性
- QGIS开发之矢量图层的使用
- QGis二次开发基础 -- 矢量图层的显示样式
- QGis二次开发基础 -- 矢量图层的显示样式
- ArcEngine开发之矢量图层渲染实现
- QGis(三)查询矢量图层的要素属性字段值
- QGis(一)加载栅格图层和矢量图层
- QGis(四)shp矢量图层添加新字段
- QGis二次开发基础 -- 矢量图层属性图表显示
- QGis二次开发基础 -- 矢量图层属性图表显示
- QGIS python开发手册--使用栅格图层
- WebGIS学习(七)WebGIS中栅格、矢量图层设计之栅格、矢量图层的本质
- QGIS使用栅格图层
- OpenLayers 3 之 使用矢量图层(Vector)
- OpenLayers开发:调用矢量图层
- Android开发 之 矢量图的兼容问题
- IDataSet接口的使用和矢量图层复制
- QGis(五)矢量图层根据指定字段分级渲染显示
- 显示栅格图层和矢量图层的属性表(AE开发)
- win10的ie打不开,用注册表解决
- erlang节点互联
- n个整数中找出连续m个数加和是最大Java版
- Windows平台vlc-qt的编译和使用
- java进阶建议读的11本书
- QGIS开发之矢量图层的使用
- wireshark抓包图解 TCP三次握手/四次挥手详解
- Redundant Connection问题及解法
- 《驾驭Core Data》 第三章 数据建模
- 111
- python3中利用serial模块实现单片机与python上位机的通信(串口调试助手)
- win10+GTX1070+1T硬盘
- 用Scheme解释器项目来了解Java(一)
- Springboot中如何引入本地jar包,并通过maven把项目成功打包成jar包部署