Qgis开发13-矢量空间分析

Qgis开发-矢量空间分析

[email protected]

2014年8月27日

 

1  概述

矢量分析是指两个或多个矢量元素之间的相互关系算法。

矢量分析包含关系测试,关系计算两类。

关系测试是指元素之间有无相关关系。

关系计算是指元素之间相互关系的确切几何结果。

 

2  原理

矢量计算包算常规的并、交、差、异或等各种关系。

2.1 关系测试

不相交disjoint:由QgsGeometry::disjoint()实现。(参考:http://en.wikipedia.org/wiki/Disjoint_sets

叠置overlaps:相交,但交集只是两个输入元素的一部分。由QgsGeometry::overlaps()实现

相交intersects:相交,比较宽泛的相交。由QgsGeometry::intersects()实现

包含contains:由QgsGeometry::contains()实现

相等equals:由QgsGeometry::equals()实现。

相切touches:由QgsGeometry::touches()实现。

内部within:与contains()相反。由QgsGeometry::within()实现。

经过crosses:由QgsGeometry::crosses()实现。

参考:ArcMapHelp:Relational functions for ST_Geometry

2.2 关系运算

并Union:指元素相互合并,相交部分从原元素中独立为单独元素。由QgsGeometry::difference()+QgsGeometry::intersection()实现。

交Intersection:表示两个几何图形之间共同的部分。交集多用来表示两个区域的重叠区域。由QgsGeometry::intersection()实现。注意:对于凹多边形,计算不准确。

差Difference:表示一个元素与另一个元素的不同之处。由QgsGeometry::difference()实现。

异或SymmatricDifference:表示两个元素中去除相交的部分。由QgsGeometry::symDifference()

融合Dissolve:多个元素合并为一个元素。由QgsGeometry::combine实现。

插值Interpolate:向指定的点按照一定的距离插值,形成一个新点。由由QgsGeometry::interpolate()实现。

缓冲区Buffer:表示向外缓冲一段距离。(参见Qgis开发10-缓冲区.docx)。由QgsGeometry::buffer()实现。

等距线offsetCurve:表示与指定线相等距离的线。由QgsGeometry::offsetCurve()实现。参考:http://www.w3school.com.cn/tags/canvas_miterlimit.asp

(参考:http://cagd.cs.byu.edu/~557/text/ch8.pdf

抽稀Simplify:将较多节点的实体减少节点。由QgsGeometry::simplify()实现。

加密Densify:将较少节点的实体增加节点。只能将元素点取出后逐个加密实现。

中心点Centroid:当前实体的中心点。由QgsGeometry::centroid()实现。

内部点PointOnSurface:因为多边形可能有孔,也可能有飞地,此函数保证返回一个在多边形内部的点。由QgsGeometry::pointOnSurface()实现。(参考:http://www.cnblogs.com/sillyemperor/archive/2009/12/03/1616042.html

外部多边形ConvexHull:外接多边形。由QgsGeometry::convexHull()实现。

 

参考:http://blog.csdn.net/cdl2008sky/article/details/7275949

 

3  方法

qgis2.4.0\python\plugins\processing\algs\qgis\ftools

所有的几何操作都在QgsGeometry中进行。

QgsGeometry::intersects()进行相交测试,如果为true,则相交。

QgsGeometry::intersection()返回相交的几何图形。

4  示例

1)       添加相应的action和界面元素

2)       声明SLOT函数

//xx.h

    voidbuffer(void);

 

3)       连接action的Signal和SLOT

//xx.cpp

    connect(ui->actionBuffer,SIGNAL(triggered()),this,SLOT(buffer()));

4)       实现SLOT函数

//xx.cpp

 

/**

 *@briefMainWindow::cetroid

 *

 *centroid.

 *@author[email protected]

 *@date2014-08-2718:44:17

 */

voidMainWindow::centroid(void)

{

    QgsVectorLayer*pVectorLayer=(QgsVectorLayer*)m_pMapCanvas->currentLayer();

    QgsFeatureIteratorfeatureIt=pVectorLayer->getFeatures();

    featureIt.rewind();

 

    QgsFeatureIdsids;

    QgsFeaturef;

    while(featureIt.nextFeature(f))

    {

        constQgsFields*pFields=f.fields();

        ids<<f.id();

 

        for(inti=0;i<pFields->size();++i){

            qDebug()<<"Feild["<<i<<"]="<<pFields->at(i).name()<<endl;

            qDebug()<<"Attribute["<<i<<"]="<<f.attribute(i).toString()<<endl;

        }

 

        QgsGeometry*pGeo=f.geometry();

        QgsGeometry*pResultGeo=pGeo->centroid();

        QgsRubberBand*pResultRubber=createRubberBand(m_pMapCanvas,pResultGeo,QColor(0,255,0));

        return;

    }

 

}

 

/**

 *@briefMainWindow::convexHull

 *

 *convexHull.

 *@author[email protected]

 *@date2014-08-2718:44:17

 */

voidMainWindow::convexHull(void)

{

    QgsVectorLayer*pVectorLayer=(QgsVectorLayer*)m_pMapCanvas->currentLayer();

    QgsFeatureIteratorfeatureIt=pVectorLayer->getFeatures();

    featureIt.rewind();

 

    QgsFeatureIdsids;

    QgsFeaturef;

    while(featureIt.nextFeature(f))

    {

        constQgsFields*pFields=f.fields();

        ids<<f.id();

 

        for(inti=0;i<pFields->size();++i){

            qDebug()<<"Feild["<<i<<"]="<<pFields->at(i).name()<<endl;

            qDebug()<<"Attribute["<<i<<"]="<<f.attribute(i).toString()<<endl;

        }

 

        QgsGeometry*pGeo=f.geometry();

        QgsGeometry*pOuter=pGeo->convexHull();

        QgsGeometry*pResultGeo=pOuter;

        QgsRubberBand*pResultRubber=createRubberBand(m_pMapCanvas,pResultGeo,QColor(0,255,0));

 

        return;

    }

}

 

/**

 *@briefMainWindow::pointOnSurface

 *

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

弗里曼的小伙伴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值