本文整理汇总了C++中QgsMultiPolyline::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsMultiPolyline::reserve方法的具体用法?C++ QgsMultiPolyline::reserve怎么用?C++ QgsMultiPolyline::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsMultiPolyline
的用法示例。
在下文中一共展示了QgsMultiPolyline::reserve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clipBufferLine
QgsGeometry* QgsTransectSample::clipBufferLine( const QgsGeometry& stratumGeom, QgsGeometry* clippedBaseline, double tolerance )
{
if ( !stratumGeom || !clippedBaseline || clippedBaseline->wkbType() == QgsWkbTypes::Unknown )
{
return nullptr;
}
QgsGeometry usedBaseline = *clippedBaseline;
if ( mBaselineSimplificationTolerance >= 0 )
{
//int verticesBefore = usedBaseline->asMultiPolyline().count();
usedBaseline = clippedBaseline->simplify( mBaselineSimplificationTolerance );
if ( usedBaseline.isEmpty() )
{
return nullptr;
}
//int verticesAfter = usedBaseline->asMultiPolyline().count();
//debug: write to file
/*QgsVectorFileWriter debugWriter( "/tmp/debug.shp", "utf-8", QgsFields(), QgsWkbTypes::LineString, &( mStrataLayer->crs() ) );
QgsFeature debugFeature; debugFeature.setGeometry( usedBaseline );
debugWriter.addFeature( debugFeature );*/
}
double currentBufferDist = tolerance;
int maxLoops = 10;
for ( int i = 0; i < maxLoops; ++i )
{
//loop with tolerance: create buffer, convert buffer to line, clip line by stratum, test if result is (single) line
QgsGeometry clipBaselineBuffer = usedBaseline.buffer( currentBufferDist, 8 );
if ( clipBaselineBuffer.isEmpty() )
{
continue;
}
//it is also possible that clipBaselineBuffer is a multipolygon
QgsGeometry bufferLine; //buffer line or multiline
QgsGeometry bufferLineClipped;
QgsMultiPolyline mpl;
if ( clipBaselineBuffer.isMultipart() )
{
QgsMultiPolygon bufferMultiPolygon = clipBaselineBuffer.asMultiPolygon();
if ( bufferMultiPolygon.size() < 1 )
{
continue;
}
for ( int j = 0; j < bufferMultiPolygon.size(); ++j )
{
int size = bufferMultiPolygon.at( j ).size();
for ( int k = 0; k < size; ++k )
{
mpl.append( bufferMultiPolygon.at( j ).at( k ) );
}
}
bufferLine = QgsGeometry::fromMultiPolyline( mpl );
}
else
{
QgsPolygon bufferPolygon = clipBaselineBuffer.asPolygon();
if ( bufferPolygon.size() < 1 )
{
continue;
}
int size = bufferPolygon.size();
mpl.reserve( size );
for ( int j = 0; j < size; ++j )
{
mpl.append( bufferPolygon[j] );
}
bufferLine = QgsGeometry::fromMultiPolyline( mpl );
}
bufferLineClipped = bufferLine.intersection( stratumGeom );
if ( bufferLineClipped.isEmpty() && bufferLineClipped.type() == QgsWkbTypes::LineGeometry )
{
//if stratumGeom is a multipolygon, bufferLineClipped must intersect each part
bool bufferLineClippedIntersectsStratum = true;
if ( stratumGeom.wkbType() == QgsWkbTypes::MultiPolygon || stratumGeom.wkbType() == QgsWkbTypes::MultiPolygon25D )
{
QVector<QgsPolygon> multiPoly = stratumGeom.asMultiPolygon();
QVector<QgsPolygon>::const_iterator multiIt = multiPoly.constBegin();
for ( ; multiIt != multiPoly.constEnd(); ++multiIt )
{
QgsGeometry poly = QgsGeometry::fromPolygon( *multiIt );
if ( !poly.intersects( bufferLineClipped ) )
{
bufferLineClippedIntersectsStratum = false;
break;
}
}
}
if ( bufferLineClippedIntersectsStratum )
{
return new QgsGeometry( bufferLineClipped );
}
}
//.........这里部分代码省略.........