QGIS基本资料
QGIS git https://github.com/qgis
QGIS 快速指南
用户手册 https://docs.qgis.org/3.16/en/docs/user_manual/index.html
教程 https://docs.qgis.org/3.16/en/docs/training_manual/index.html
QGIS Python 开发手册
https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/index.html
PyQGIS API https://qgis.org/pyqgis/
QGIS C++ 开发手册 https://qgis.org/api/
QGIS API https://qgis.org/api/3.14/api_break.html
早期3.1.0.0的用户手册https://docs.huihoo.com/qgis/qgis-1.0.0-user-guide-en.pdf
开发人员手册:https://docs.qgis.org/3.16/en/docs/developers_guide/index.html
QgsDiagramRendererV2
几何生成器函数介绍:https://docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/functions_list.html?highlight=tapered_buffer#geometry-functions
插件目录:http://plugins.qgis.org/plugins/
表达式-函数编辑器
https://docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/expression.html?highlight=function%20editor#function-editor
通过 QgsVectorLayer 的 setDiagramRenderer() 方法,传入一个 QgsDiagramRendererV2 的实例,当前的矢量图层就会以设置的方法来渲染显示图表。
其中 QgsLinearlyInterpolatedDiagramRenderer和QgsSingleCategoryDiagramRenderer 分别是具体的渲染方法类,
Diagram类
QGis当中提供的图表类包括三个,QgsPieDiagram、QgsTextDiagram 和 QgsHistogramDiagram,它们分别对应于饼状图、文本图和柱状图,都是继承自 QgsDiagram 类
具体来说,有两个,一个是QgsDiagramSettings,用于配置针对图表的参数,另一个是 QgsDiagramLayerSettings,是更高一级的参数,将图表类作为一个图层,配置与矢量要素的显示关系.
Name |
说明 |
angleOffset |
起始角度(仅饼状图) |
backgroundColor |
背景颜色 |
barWidth |
柱宽度(仅柱状图) |
categoryAttributes \ categoryColors |
用于控制不同属性显示不同颜色 |
diagramOrientation |
图表方向 |
font |
字体(仅文本图) |
labelPlacementMethod |
图表中文本的显示位置(仅文本图),包括Hight和XHight |
maxScaleDenominator \ minScaleDenominator |
显示尺度。大于或小于缩放尺度,图表将不再显示 |
minimumSize |
图表显示的最小尺寸。小于这个尺寸的图表会放大到这个尺寸显示 |
penColor \ penWidth |
控制轮廓的颜色和宽度 |
scaleByArea |
是否根据要素面积进行缩放图表(仅polygon要素) |
size |
图表大小 |
sizeType |
图表大小的单位,包括 MM 和 MapUnits |
transparency |
透明度 |
基本代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| void qgis_dev_layerPropDialog::setDiagramProperty() { QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( activeLayer() ); QgsDiagram* diagram = 0; QString diagramType = "Hist"; bool scaleAttributeValueOk = false; QgsVectorDataProvider* provider = layer->dataProvider(); double maxVal = 0; int fld = 2; if ( fld != -1 ) { bool ok = false; double val = provider->maximumValue( fld ).toDouble( &ok ); if ( ok ) { maxVal = val; } } bool mValueLineEdit = false; if ( diagramType == "Text" ) { } else if ( diagramType == "Pie" ) { } else { diagram = new QgsHistogramDiagram(); } #pragma region 设置diagram属性 QgsDiagramSettings ds; ds.transparency = 0; QList<QColor> categoryColors; QList<QString> categoryAttributes; QColor color = QColor( 255, 0, 0 ); color.setAlpha( 255 - ds.transparency ); categoryColors.append( color ); categoryAttributes.append( "ELEV" ); ds.categoryColors = categoryColors; ds.categoryAttributes = categoryAttributes; ds.size = QSizeF( 1, 1 ); ds.sizeType = static_cast<QgsDiagramSettings::SizeType>( 0 ); ds.labelPlacementMethod = static_cast<QgsDiagramSettings::LabelPlacementMethod>( 1 ); ds.scaleByArea = true; ds.minimumSize = 0; ds.backgroundColor = QColor( 0, 0, 0 ); ds.penColor = QColor( 0, 0, 0 ); ds.penWidth = 1; ds.minScaleDenominator = -1; ds.maxScaleDenominator = -1; ds.angleOffset = 1440; ds.diagramOrientation = static_cast<QgsDiagramSettings::DiagramOrientation>( 0 ); ds.barWidth = 5; #pragma endregion 设置diagram属性 QgsLinearlyInterpolatedDiagramRenderer* dr = new QgsLinearlyInterpolatedDiagramRenderer(); dr->setLowerValue( 0.0 ); dr->setLowerSize( QSizeF( 0.0, 0.0 ) ); dr->setUpperValue( 2 ); dr->setUpperSize( QSizeF( 2, 2 ) ); bool isExpression = true; dr->setClassificationAttributeIsExpression( isExpression ); dr->setClassificationAttributeExpression( "" ); dr->setDiagram( diagram ); dr->setDiagramSettings( ds ); layer->setDiagramRenderer( dr ); QgsDiagramLayerSettings dls; dls.dist = 0; dls.priority = 5; dls.xPosColumn = -1; dls.yPosColumn = -1; dls.placement = static_cast<QgsDiagramLayerSettings::Placement>( 0 ); dls.placementFlags = 0; layer->setDiagramLayerSettings( dls ); layer->setTitle( "" ); QgsVectorSimplifyMethod simplifyMethod = m_layer->simplifyMethod(); simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification ); simplifyMethod.setThreshold( 1 ); simplifyMethod.setForceLocalOptimization( true ); simplifyMethod.setMaximumScale( 1 ); layer->setSimplifyMethod( simplifyMethod ); layer->triggerRepaint(); m_mapCanvas->refresh(); }
|