Qgis开发6-临时图形-QgsRubberBand
来源:互联网 发布:出差日历行程软件 编辑:程序博客网 时间:2024/05/19 19:42
Qgis开发6-临时图形
QgsRubberBand
sf2gis@163.com
2014年8月22日
2014年8月26日添加addGeometry
1 概述
临时图形Rubberband主要用于高亮显示、交互绘制等情况下。
2 原理
临时图形是在一个底色透明的图层(顶层)上,添加已有的几何元素或者创建一个几何元素(临时图形),可以设置相应的样式,并在图层的最上层叠加显示。
3 使用方法
QgsRubberBand用于显示临时图形。可以显示点、线、面等所有类型。由于在交互绘制时,可能需要高亮显示节点,所以本类也可以设置不同的IconType来显示不同的节点样式(只能在点类型时起作用)。
生成对象后可以完成操作所有的属性,如几何元素、样式等。
setWidth():设置画笔宽度。
setIconSize():设置icon的宽度(高度)。
addGeometry():添加已有的Geometry。注意:第二个参数为vectorlayer,用途是将Geometry按照此layer的crs与mapcanvas的crs进行坐标转换,如果此为NULL,则不转换。参见Qgis开发12-读取矢量元素.docx
特别要注意:mapcanvas在显示之前各种参数都不确定,一定要在mapcanvas渲染结束之后再进行坐标转换之类的操作。
示例:
//xx.cpp
………….
connect(m_pMapCanvas,SIGNAL(xyCoordinates(QgsPoint)),this,SLOT(showMousePoint(QgsPoint)));
…………..
/**
*@briefMainWindow::initialMapCanvas
*
*initializewhenmapcanvaspaintfinished.
*@authorsf2gis@163.com
*@date2014-08-2222:31:24
*/
voidMainWindow::initialMapCanvas()
{
createRubberBand(m_pMapCanvas);
}
/**
*@briefMainWindow::createRubberBand
*
*createrubberband.
*@parampMapCanvas
*@authorsf2gis@163.com
*@date2014-08-2222:32:30
*/
voidMainWindow::createRubberBand(QgsMapCanvas*pMapCanvas)
{
{//line
QgsRubberBand*pRubber=newQgsRubberBand(pMapCanvas,QGis::Line);
pRubber->setColor(QColor(0,255,0));
pRubber->setWidth(2);
constQgsMapToPixel*pM2PTransform=pMapCanvas->getCoordinateTransform();
QgsPointpt1=pM2PTransform->toMapCoordinates(0,0);
QgsPointpt2=pM2PTransform->toMapCoordinates(100,0);
QgsPointpt3=pM2PTransform->toMapCoordinates(100,100);
QgsPointpt4=pM2PTransform->toMapCoordinates(0,100);
pRubber->addPoint(pt1,false);
pRubber->addPoint(pt2,false);
pRubber->addPoint(pt3,false);
pRubber->addPoint(pt4,true);
}
{//polygon
QgsRubberBand*pRubber=newQgsRubberBand(pMapCanvas,QGis::Polygon);
pRubber->setColor(QColor(255,0,0));
pRubber->setWidth(2);
constQgsMapToPixel*pM2PTransform=pMapCanvas->getCoordinateTransform();
QgsPointpt1=pM2PTransform->toMapCoordinates(10,10);
QgsPointpt2=pM2PTransform->toMapCoordinates(90,10);
QgsPointpt3=pM2PTransform->toMapCoordinates(90,90);
QgsPointpt4=pM2PTransform->toMapCoordinates(10,90);
pRubber->addPoint(pt1,false);
pRubber->addPoint(pt2,false);
pRubber->addPoint(pt3,false);
pRubber->addPoint(pt4,true);
}
{//point
QgsRubberBand*pRubber=newQgsRubberBand(pMapCanvas,QGis::Point);
pRubber->setColor(QColor(0,255,0));
pRubber->setWidth(10);
pRubber->setIcon(QgsRubberBand::ICON_CROSS);
pRubber->setIconSize(20);
constQgsMapToPixel*pM2PTransform=pMapCanvas->getCoordinateTransform();
QgsPointpt1=pM2PTransform->toMapCoordinates(50,50);
pRubber->addPoint(pt1,true);
}
}
0 0
- Qgis开发6-临时图形-QgsRubberBand
- Qgis开发1:总则
- qgis 插件开发
- Qgis开发17-日志
- QGIS python开发手册
- QgsRubberBand类
- Qgis开发2-工程组织
- Qgis开发8-显示GUI
- Qgis开发10-缓冲区分析
- python开发qgis插件之一
- qgis
- 在QGIS下开发python插件
- Qgis开发4-地图交互工具
- Qgis开发9-显示当前鼠标坐标
- Qgis开发11-地理实体抽象
- Qgis开发12-读取矢量元素
- Qgis开发13-矢量空间分析
- Qgis开发15-自定义地图工具
- C语言结构体用法
- 协议森林06 瑞士军刀 (ICMP协议)
- 记第1次DIY装机
- 引用,指针
- 协议森林07 傀儡 (UDP协议)
- Qgis开发6-临时图形-QgsRubberBand
- 协议森林08 不放弃 (TCP协议与流通信)
- 浅谈 C++ 中的 new/delete 和 new[]/delete[]
- LeetCode: Balanced Binary Tree
- Fat Jar打包插件方法
- Qgis开发7-坐标系统CRS 设置和转换
- 协议森林09 爱的传声筒 (TCP连接)
- Xamarin iOS开发实战(内部资料)
- 在yii中使用memcache