本文整理汇总了C++中QgsVectorLayer::addTopologicalPoints方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::addTopologicalPoints方法的具体用法?C++ QgsVectorLayer::addTopologicalPoints怎么用?C++ QgsVectorLayer::addTopologicalPoints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::addTopologicalPoints方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: digitized
void QgsMapToolAddFeature::digitized( QgsFeature &f )
{
QgsVectorLayer *vlayer = currentVectorLayer();
bool res = addFeature( vlayer, &f, false );
if ( res && ( mode() == CaptureLine || mode() == CapturePolygon ) )
{
//add points to other features to keep topology up-to-date
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
//use always topological editing for avoidIntersection.
//Otherwise, no way to guarantee the geometries don't have a small gap in between.
QList<QgsVectorLayer *> intersectionLayers = QgsProject::instance()->avoidIntersectionsLayers();
bool avoidIntersection = !intersectionLayers.isEmpty();
if ( avoidIntersection ) //try to add topological points also to background layers
{
const auto constIntersectionLayers = intersectionLayers;
for ( QgsVectorLayer *vl : constIntersectionLayers )
{
//can only add topological points if background layer is editable...
if ( vl->geometryType() == QgsWkbTypes::PolygonGeometry && vl->isEditable() )
{
vl->addTopologicalPoints( f.geometry() );
}
}
}
else if ( topologicalEditing )
{
vlayer->addTopologicalPoints( f.geometry() );
}
}
}
示例2: addTopologicalPoints
int QgsMapToolEdit::addTopologicalPoints( const QList<QgsPoint>& geom )
{
if ( !mCanvas )
{
return 1;
}
//find out current vector layer
QgsVectorLayer *vlayer = currentVectorLayer();
if ( !vlayer )
{
return 2;
}
QList<QgsPoint>::const_iterator list_it = geom.constBegin();
for ( ; list_it != geom.constEnd(); ++list_it )
{
vlayer->addTopologicalPoints( *list_it );
}
return 0;
}
示例3: canvasReleaseEvent
//.........这里部分代码省略.........
//polygons: bail out if there are not at least two vertices
if ( mode() == CapturePolygon && size() < 3 )
{
stopCapturing();
return;
}
//create QgsFeature with wkb representation
QgsFeature* f = new QgsFeature( 0, "WKBLineString" );
QgsGeometry *g;
if ( mode() == CaptureLine )
{
if ( layerWKBType == QGis::WKBLineString || layerWKBType == QGis::WKBLineString25D )
{
g = QgsGeometry::fromPolyline( points().toVector() );
}
else if ( layerWKBType == QGis::WKBMultiLineString || layerWKBType == QGis::WKBMultiLineString25D )
{
g = QgsGeometry::fromMultiPolyline( QgsMultiPolyline() << points().toVector() );
}
else
{
QMessageBox::critical( 0, tr( "Error" ), tr( "Cannot add feature. Unknown WKB type" ) );
stopCapturing();
return; //unknown wkbtype
}
f->setGeometry( g );
}
else // polygon
{
if ( layerWKBType == QGis::WKBPolygon || layerWKBType == QGis::WKBPolygon25D )
{
g = QgsGeometry::fromPolygon( QgsPolygon() << points().toVector() );
}
else if ( layerWKBType == QGis::WKBMultiPolygon || layerWKBType == QGis::WKBMultiPolygon25D )
{
g = QgsGeometry::fromMultiPolygon( QgsMultiPolygon() << ( QgsPolygon() << points().toVector() ) );
}
else
{
QMessageBox::critical( 0, tr( "Error" ), tr( "Cannot add feature. Unknown WKB type" ) );
stopCapturing();
return; //unknown wkbtype
}
if ( !g )
{
stopCapturing();
delete f;
return; // invalid geometry; one possibility is from duplicate points
}
f->setGeometry( g );
int avoidIntersectionsReturn = f->geometry()->avoidIntersections();
if ( avoidIntersectionsReturn == 1 )
{
//not a polygon type. Impossible to get there
}
#if 0
else if ( avoidIntersectionsReturn == 2 ) //MH120131: disable this error message until there is a better way to cope with the single type / multi type problem
{
//bail out...
QMessageBox::critical( 0, tr( "Error" ), tr( "The feature could not be added because removing the polygon intersections would change the geometry type" ) );
delete f;
stopCapturing();
return;
}
#endif
else if ( avoidIntersectionsReturn == 3 )
{
QMessageBox::critical( 0, tr( "Error" ), tr( "An error was reported during intersection removal" ) );
}
}
vlayer->beginEditCommand( tr( "Feature added" ) );
if ( addFeature( vlayer, f ) )
{
//add points to other features to keep topology up-to-date
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
if ( topologicalEditing )
{
vlayer->addTopologicalPoints( f->geometry() );
}
vlayer->endEditCommand();
}
else
{
delete f;
vlayer->destroyEditCommand();
}
stopCapturing();
}
}
}
示例4: cadCanvasReleaseEvent
//.........这里部分代码省略.........
bool hasCurvedSegments = captureCurve()->hasCurvedSegments();
bool providerSupportsCurvedSegments = vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::CircularGeometries;
QgsCurveV2* curveToAdd = 0;
if ( hasCurvedSegments && providerSupportsCurvedSegments )
{
curveToAdd = captureCurve()->clone();
}
else
{
curveToAdd = captureCurve()->curveToLine();
}
if ( mode() == CaptureLine )
{
f->setGeometry( new QgsGeometry( curveToAdd ) );
}
else
{
QgsCurvePolygonV2* poly = 0;
if ( hasCurvedSegments && providerSupportsCurvedSegments )
{
poly = new QgsCurvePolygonV2();
}
else
{
poly = new QgsPolygonV2();
}
poly->setExteriorRing( curveToAdd );
f->setGeometry( new QgsGeometry( poly ) );
int avoidIntersectionsReturn = f->geometry()->avoidIntersections();
if ( avoidIntersectionsReturn == 1 )
{
//not a polygon type. Impossible to get there
}
#if 0
else if ( avoidIntersectionsReturn == 2 ) //MH120131: disable this error message until there is a better way to cope with the single type / multi type problem
{
//bail out...
emit messageEmitted( tr( "The feature could not be added because removing the polygon intersections would change the geometry type" ), QgsMessageBar::CRITICAL );
stopCapturing();
return;
}
#endif
else if ( avoidIntersectionsReturn == 3 )
{
emit messageEmitted( tr( "An error was reported during intersection removal" ), QgsMessageBar::CRITICAL );
}
if ( !f->constGeometry()->asWkb() ) //avoid intersection might have removed the whole geometry
{
QString reason;
if ( avoidIntersectionsReturn != 2 )
{
reason = tr( "The feature cannot be added because it's geometry is empty" );
}
else
{
reason = tr( "The feature cannot be added because it's geometry collapsed due to intersection avoidance" );
}
emit messageEmitted( reason, QgsMessageBar::CRITICAL );
stopCapturing();
return;
}
}
if ( addFeature( vlayer, f.data(), false ) )
{
//add points to other features to keep topology up-to-date
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
//use always topological editing for avoidIntersection.
//Otherwise, no way to guarantee the geometries don't have a small gap in between.
QStringList intersectionLayers = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList" );
bool avoidIntersection = !intersectionLayers.isEmpty();
if ( avoidIntersection ) //try to add topological points also to background layers
{
QStringList::const_iterator lIt = intersectionLayers.constBegin();
for ( ; lIt != intersectionLayers.constEnd(); ++lIt )
{
QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( *lIt );
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( ml );
//can only add topological points if background layer is editable...
if ( vl && vl->geometryType() == QGis::Polygon && vl->isEditable() )
{
vl->addTopologicalPoints( f->constGeometry() );
}
}
}
else if ( topologicalEditing )
{
vlayer->addTopologicalPoints( f->constGeometry() );
}
}
stopCapturing();
}
}
}