首页 技术 正文
技术 2022年11月17日
0 收藏 596 点赞 3,137 浏览 2278 个字

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(,,));
pRubber->setWidth();
constQgsMapToPixel*pM2PTransform=pMapCanvas->getCoordinateTransform();
QgsPointpt1=pM2PTransform->toMapCoordinates(,);
QgsPointpt2=pM2PTransform->toMapCoordinates(,);
QgsPointpt3=pM2PTransform->toMapCoordinates(,);
QgsPointpt4=pM2PTransform->toMapCoordinates(,);
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(,,));
pRubber->setWidth();
constQgsMapToPixel*pM2PTransform=pMapCanvas->getCoordinateTransform();
QgsPointpt1=pM2PTransform->toMapCoordinates(,);
QgsPointpt2=pM2PTransform->toMapCoordinates(,);
QgsPointpt3=pM2PTransform->toMapCoordinates(,);
QgsPointpt4=pM2PTransform->toMapCoordinates(,);
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(,,));
pRubber->setWidth();
pRubber->setIcon(QgsRubberBand::ICON_CROSS);
pRubber->setIconSize();
constQgsMapToPixel*pM2PTransform=pMapCanvas->getCoordinateTransform();
QgsPointpt1=pM2PTransform->toMapCoordinates(,);
pRubber->addPoint(pt1,true);
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,023
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,360
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,143
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,774
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,852