本文整理汇总了C++中QgsVectorLayer::updateExtents方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::updateExtents方法的具体用法?C++ QgsVectorLayer::updateExtents怎么用?C++ QgsVectorLayer::updateExtents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::updateExtents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportPath
void RgShortestPathWidget::exportPath()
{
RgExportDlg dlg( this );
if ( !dlg.exec() )
return;
QgsVectorLayer *vl = dlg.mapLayer();
if ( vl == NULL )
return;
QgsPoint p1, p2;
QgsGraph *path = getPath( p1, p2 );
if ( path == NULL )
return;
QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapSettings().destinationCrs(),
vl->crs() );
int startVertexIdx = path->findVertex( p1 );
int stopVertexIdx = path->findVertex( p2 );
double time = 0.0;
double cost = 0.0;
Unit timeUnit = Unit::byName( mPlugin->timeUnitName() );
Unit distanceUnit = Unit::byName( mPlugin->distanceUnitName() );
QgsPolyline p;
while ( startVertexIdx != stopVertexIdx )
{
if ( stopVertexIdx < 0 )
break;
QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc();
if ( l.empty() )
break;
const QgsGraphArc& e = path->arc( l.front() );
cost += e.property( 0 ).toDouble();
time += e.property( 1 ).toDouble();
p.push_front( ct.transform( path->vertex( e.inVertex() ).point() ) );
stopVertexIdx = e.outVertex();
}
p.push_front( ct.transform( p1 ) );
QgsFeature f;
f.initAttributes( vl->pendingFields().count() );
f.setGeometry( QgsGeometry::fromPolyline( p ) );
f.setAttribute( 0, cost / distanceUnit.multipler() );
f.setAttribute( 1, time / timeUnit.multipler() );
QgsFeatureList features;
features << f;
vl->dataProvider()->addFeatures( features );
vl->updateExtents();
mPlugin->iface()->mapCanvas()->update();
delete path;
}
示例2: exportPath
void RgShortestPathWidget::exportPath()
{
RgExportDlg dlg( this );
if ( !dlg.exec() )
return;
QgsVectorLayer *vl = dlg.mapLayer();
if ( vl == NULL )
return;
QgsPoint p1, p2;
QgsGraph *path = getPath( p1, p2 );
if ( path == NULL )
return;
QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
vl->crs() );
int startVertexIdx = path->findVertex( p1 );
int stopVertexIdx = path->findVertex( p2 );
QgsPolyline p;
while ( startVertexIdx != stopVertexIdx )
{
QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc();
if ( l.empty() )
break;
const QgsGraphArc& e = path->arc( l.front() );
p.push_front( ct.transform( path->vertex( e.inVertex() ).point() ) );
stopVertexIdx = e.outVertex();
}
p.push_front( ct.transform( p1 ) );
vl->startEditing();
QgsFeature f;
f.setGeometry( QgsGeometry::fromPolyline( p ) );
vl->addFeature( f );
vl->updateExtents();
mPlugin->iface()->mapCanvas()->update();
delete path;
}