本文整理汇总了C++中QgsMultiPolyline类的典型用法代码示例。如果您正苦于以下问题:C++ QgsMultiPolyline类的具体用法?C++ QgsMultiPolyline怎么用?C++ QgsMultiPolyline使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QgsMultiPolyline类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QDomElement
QDomElement QgsWFSServer::createMultiLineStringElem( QgsGeometry* geom, QDomDocument& doc ) const
{
if ( !geom )
{
return QDomElement();
}
QDomElement multiLineStringElem = doc.createElement( "gml:MultiLineString" );
QgsMultiPolyline multiline = geom->asMultiPolyline();
QgsMultiPolyline::const_iterator multiLineIt = multiline.constBegin();
for ( ; multiLineIt != multiline.constEnd(); ++multiLineIt )
{
QgsGeometry* lineGeom = QgsGeometry::fromPolyline( *multiLineIt );
if ( lineGeom )
{
QDomElement lineStringMemberElem = doc.createElement( "gml:lineStringMember" );
QDomElement lineElem = createLineStringElem( lineGeom, doc );
lineStringMemberElem.appendChild( lineElem );
multiLineStringElem.appendChild( lineStringMemberElem );
}
delete lineGeom;
}
return multiLineStringElem;
}
示例2: closestMultilineElement
QgsGeometry* QgsTransectSample::closestMultilineElement( const QgsPoint& pt, QgsGeometry* multiLine )
{
if ( !multiLine || ( multiLine->wkbType() != QGis::WKBMultiLineString
&& multiLine->wkbType() != QGis::WKBMultiLineString25D ) )
{
return 0;
}
double minDist = DBL_MAX;
double currentDist = 0;
QgsGeometry* currentLine = 0;
QgsGeometry* closestLine = 0;
QgsGeometry* pointGeom = QgsGeometry::fromPoint( pt );
QgsMultiPolyline multiPolyline = multiLine->asMultiPolyline();
QgsMultiPolyline::const_iterator it = multiPolyline.constBegin();
for ( ; it != multiPolyline.constEnd(); ++it )
{
currentLine = QgsGeometry::fromPolyline( *it );
currentDist = pointGeom->distance( *currentLine );
if ( currentDist < minDist )
{
minDist = currentDist;
closestLine = currentLine;
}
else
{
delete currentLine;
}
}
delete pointGeom;
return closestLine;
}
示例3: if
QgsGeometry* QgsMapToolOffsetCurve::convertToSingleLine( QgsGeometry* geom, int vertex, bool& isMulti )
{
if ( !geom )
{
return 0;
}
isMulti = false;
QGis::WkbType geomType = geom->wkbType();
if ( geomType == QGis::WKBLineString || geomType == QGis::WKBLineString25D )
{
return geom;
}
else if ( geomType == QGis::WKBMultiLineString || geomType == QGis::WKBMultiLineString25D )
{
//search vertex
isMulti = true;
int currentVertex = 0;
QgsMultiPolyline multiLine = geom->asMultiPolyline();
QgsMultiPolyline::const_iterator it = multiLine.constBegin();
for ( ; it != multiLine.constEnd(); ++it )
{
currentVertex += it->size();
if ( vertex < currentVertex )
{
QgsGeometry* g = QgsGeometry::fromPolyline( *it );
delete geom;
return g;
}
}
}
delete geom;
return 0;
}
示例4: QgsGeometry
QgsGeometry QgsTransectSample::closestMultilineElement( const QgsPoint& pt, const QgsGeometry& multiLine )
{
if ( !multiLine || ( multiLine.wkbType() != QgsWkbTypes::MultiLineString
&& multiLine.wkbType() != QgsWkbTypes::MultiLineString25D ) )
{
return QgsGeometry();
}
double minDist = DBL_MAX;
double currentDist = 0;
QgsGeometry currentLine;
QgsGeometry closestLine;
QgsGeometry pointGeom = QgsGeometry::fromPoint( pt );
QgsMultiPolyline multiPolyline = multiLine.asMultiPolyline();
QgsMultiPolyline::const_iterator it = multiPolyline.constBegin();
for ( ; it != multiPolyline.constEnd(); ++it )
{
currentLine = QgsGeometry::fromPolyline( *it );
currentDist = pointGeom.distance( currentLine );
if ( currentDist < minDist )
{
minDist = currentDist;
closestLine = currentLine;
}
}
return closestLine;
}
示例5: mLine
std::unique_ptr<QgsMultiLineString> QgsGeometryFactory::fromMultiPolyline( const QgsMultiPolyline &multiline )
{
std::unique_ptr< QgsMultiLineString > mLine( new QgsMultiLineString() );
for ( int i = 0; i < multiline.size(); ++i )
{
mLine->addGeometry( fromPolyline( multiline.at( i ) ).release() );
}
return mLine;
}
示例6: switch
QgsGeometry *QgsRubberBand::asGeometry()
{
QgsGeometry *geom = NULL;
switch ( mGeometryType )
{
case QGis::Polygon:
{
QgsPolygon polygon;
QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
for ( ; it != mPoints.constEnd(); ++it )
{
polygon.append( getPolyline( *it ) );
}
geom = QgsGeometry::fromPolygon( polygon );
break;
}
case QGis::Point:
{
QgsMultiPoint multiPoint;
QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
for ( ; it != mPoints.constEnd(); ++it )
{
multiPoint += getPolyline( *it );
}
geom = QgsGeometry::fromMultiPoint( multiPoint );
break;
}
case QGis::Line:
default:
{
if ( mPoints.size() > 0 )
{
if ( mPoints.size() > 1 )
{
QgsMultiPolyline multiPolyline;
QList< QList<QgsPoint> >::const_iterator it = mPoints.constBegin();
for ( ; it != mPoints.constEnd(); ++it )
{
multiPolyline.append( getPolyline( *it ) );
}
geom = QgsGeometry::fromMultiPolyline( multiPolyline );
}
else
{
geom = QgsGeometry::fromPolyline( getPolyline( mPoints[0] ) );
}
}
break;
}
}
return geom;
}
示例7: switch
int QgsMapToolDeletePart::partNumberOfVertex( QgsGeometry* g, int beforeVertexNr )
{
int part;
switch ( g->wkbType() )
{
case QGis::WKBMultiPoint25D:
case QGis::WKBMultiPoint:
if ( beforeVertexNr < g->asMultiPoint().count() )
return beforeVertexNr;
else
return -1;
case QGis::WKBMultiLineString25D:
case QGis::WKBMultiLineString:
{
QgsMultiPolyline mline = g->asMultiPolyline();
for ( part = 0; part < mline.count(); part++ )
{
if ( beforeVertexNr < mline[part].count() )
return part;
beforeVertexNr -= mline[part].count();
}
return -1; // not found
}
case QGis::WKBMultiPolygon25D:
case QGis::WKBMultiPolygon:
{
QgsMultiPolygon mpolygon = g->asMultiPolygon();
for ( part = 0; part < mpolygon.count(); part++ ) // go through the polygons
{
const QgsPolygon& polygon = mpolygon[part];
for ( int ring = 0; ring < polygon.count(); ring++ ) // go through the rings
{
if ( beforeVertexNr < polygon[ring].count() )
return part;
beforeVertexNr -= polygon[ring].count();
}
}
return -1; // not found
}
default:
return -1;
}
}
示例8: locateBetweenMeasures
QgsGeometry* QgsGeometryAnalyzer::locateBetweenMeasures( double fromMeasure, double toMeasure, QgsGeometry* lineGeom )
{
if ( !lineGeom )
{
return 0;
}
QgsMultiPolyline resultGeom;
//need to go with WKB and z coordinate until QgsGeometry supports M values
unsigned char* lineWkb = lineGeom->asWkb();
unsigned char* ptr = lineWkb + 1;
QGis::WkbType wkbType;
memcpy( &wkbType, ptr, sizeof( wkbType ) );
ptr += sizeof( wkbType );
if ( wkbType != QGis::WKBLineString25D && wkbType != QGis::WKBMultiLineString25D )
{
return 0;
}
if ( wkbType == QGis::WKBLineString25D )
{
locateBetweenWkbString( ptr, resultGeom, fromMeasure, toMeasure );
}
else if ( wkbType == QGis::WKBMultiLineString25D )
{
int* nLines = ( int* )ptr;
ptr += sizeof( int );
for ( int i = 0; i < *nLines; ++i )
{
ptr += ( 1 + sizeof( wkbType ) );
ptr = locateBetweenWkbString( ptr, resultGeom, fromMeasure, toMeasure );
}
}
if ( resultGeom.size() < 1 )
{
return 0;
}
return QgsGeometry::fromMultiPolyline( resultGeom );
}
示例9: 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 );
}
}
//.........这里部分代码省略.........
示例10: switch
/*!
Draw the shape in response to an update event.
*/
void QgsHighlight::paint( QPainter* p )
{
if ( !mGeometry )
{
return;
}
p->setPen( mPen );
p->setBrush( mBrush );
switch ( mGeometry->wkbType() )
{
case QGis::WKBPoint:
case QGis::WKBPoint25D:
{
paintPoint( p, mGeometry->asPoint() );
}
break;
case QGis::WKBMultiPoint:
case QGis::WKBMultiPoint25D:
{
QgsMultiPoint m = mGeometry->asMultiPoint();
for ( int i = 0; i < m.size(); i++ )
{
paintPoint( p, m[i] );
}
}
break;
case QGis::WKBLineString:
case QGis::WKBLineString25D:
{
paintLine( p, mGeometry->asPolyline() );
}
break;
case QGis::WKBMultiLineString:
case QGis::WKBMultiLineString25D:
{
QgsMultiPolyline m = mGeometry->asMultiPolyline();
for ( int i = 0; i < m.size(); i++ )
{
paintLine( p, m[i] );
}
}
break;
case QGis::WKBPolygon:
case QGis::WKBPolygon25D:
{
paintPolygon( p, mGeometry->asPolygon() );
}
break;
case QGis::WKBMultiPolygon:
case QGis::WKBMultiPolygon25D:
{
QgsMultiPolygon m = mGeometry->asMultiPolygon();
for ( int i = 0; i < m.size(); i++ )
{
paintPolygon( p, m[i] );
}
}
break;
case QGis::WKBUnknown:
default:
return;
}
}
示例11: errorFound
void QgsGeometryValidator::run()
{
mErrorCount = 0;
QSettings settings;
if ( settings.value( QStringLiteral( "/qgis/digitizing/validate_geometries" ), 1 ).toInt() == 2 )
{
char *r = nullptr;
const GEOSGeometry *g0 = mG.asGeos();
GEOSContextHandle_t handle = QgsGeometry::getGEOSHandler();
if ( !g0 )
{
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:could not produce geometry for GEOS (check log window)" ) ) );
}
else
{
GEOSGeometry *g1 = nullptr;
if ( GEOSisValidDetail_r( handle, g0, GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g1 ) != 1 )
{
if ( g1 )
{
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( handle, g1 );
unsigned int n;
if ( GEOSCoordSeq_getSize_r( handle, cs, &n ) && n == 1 )
{
double x, y;
GEOSCoordSeq_getX_r( handle, cs, 0, &x );
GEOSCoordSeq_getY_r( handle, cs, 0, &y );
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ), QgsPoint( x, y ) ) );
mErrorCount++;
}
GEOSGeom_destroy_r( handle, g1 );
}
else
{
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ) ) );
mErrorCount++;
}
GEOSFree_r( handle, r );
}
}
return;
}
QgsDebugMsg( "validation thread started." );
QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( mG.wkbType() );
//if ( flatType == QgsWkbTypes::Point || flatType == QgsWkbTypes::MultiPoint )
// break;
if ( flatType == QgsWkbTypes::LineString )
{
validatePolyline( 0, mG.asPolyline() );
}
else if ( flatType == QgsWkbTypes::MultiLineString )
{
QgsMultiPolyline mp = mG.asMultiPolyline();
for ( int i = 0; !mStop && i < mp.size(); i++ )
validatePolyline( i, mp[i] );
}
else if ( flatType == QgsWkbTypes::Polygon )
{
validatePolygon( 0, mG.asPolygon() );
}
else if ( flatType == QgsWkbTypes::MultiPolygon )
{
QgsMultiPolygon mp = mG.asMultiPolygon();
for ( int i = 0; !mStop && i < mp.size(); i++ )
{
validatePolygon( i, mp[i] );
}
for ( int i = 0; !mStop && i < mp.size(); i++ )
{
if ( mp[i].isEmpty() )
{
emit errorFound( QgsGeometry::Error( QObject::tr( "polygon %1 has no rings" ).arg( i ) ) );
mErrorCount++;
continue;
}
for ( int j = i + 1; !mStop && j < mp.size(); j++ )
{
if ( mp[j].isEmpty() )
continue;
if ( ringInRing( mp[i][0], mp[j][0] ) )
{
emit errorFound( QgsGeometry::Error( QObject::tr( "polygon %1 inside polygon %2" ).arg( i ).arg( j ) ) );
mErrorCount++;
}
else if ( ringInRing( mp[j][0], mp[i][0] ) )
{
emit errorFound( QgsGeometry::Error( QObject::tr( "polygon %1 inside polygon %2" ).arg( j ).arg( i ) ) );
mErrorCount++;
}
else
{
//.........这里部分代码省略.........
示例12: Q_UNUSED
ErrorList topolTest::checkSegmentLength( double tolerance, QgsVectorLayer* layer1, QgsVectorLayer* layer2, bool isExtent )
{
Q_UNUSED( layer1 );
Q_UNUSED( layer2 );
Q_UNUSED( isExtent );
int i = 0;
ErrorList errorList;
QgsFeature f;
QList<FeatureLayer>::Iterator it;
QList<FeatureLayer>::ConstIterator FeatureListEnd = mFeatureList1.end();
QgsPolygon pol;
QgsMultiPolygon mpol;
QgsPolyline segm;
QgsPolyline ls;
QgsMultiPolyline mls;
QList<FeatureLayer> fls;
TopolErrorShort* err;
double distance;
for ( it = mFeatureList1.begin(); it != FeatureListEnd; ++it )
{
if ( !( ++i % 100 ) )
{
emit progress( i );
}
if ( testCancelled() )
{
break;
}
QgsGeometry* g1 = it->feature.geometry();
// switching by type here, because layer can contain both single and multi version geometries
switch ( g1->wkbType() )
{
case QGis::WKBLineString:
case QGis::WKBLineString25D:
ls = g1->asPolyline();
for ( int i = 1; i < ls.size(); ++i )
{
distance = sqrt( ls[i-1].sqrDist( ls[i] ) );
if ( distance < tolerance )
{
fls.clear();
fls << *it << *it;
segm.clear();
segm << ls[i-1] << ls[i];
QgsGeometry* conflict = QgsGeometry::fromPolyline( segm );
err = new TopolErrorShort( g1->boundingBox(), conflict, fls );
//err = new TopolErrorShort(g1->boundingBox(), QgsGeometry::fromPolyline(segm), fls);
errorList << err;
//break on getting the first error
break;
}
}
break;
case QGis::WKBPolygon:
case QGis::WKBPolygon25D:
pol = g1->asPolygon();
for ( int i = 0; i < pol.size(); ++i )
{
for ( int j = 1; j < pol[i].size(); ++j )
{
distance = sqrt( pol[i][j-1].sqrDist( pol[i][j] ) );
if ( distance < tolerance )
{
fls.clear();
fls << *it << *it;
segm.clear();
segm << pol[i][j-1] << pol[i][j];
QgsGeometry* conflict = QgsGeometry::fromPolyline( segm );
err = new TopolErrorShort( g1->boundingBox(), conflict, fls );
errorList << err;
//break on getting the first error
break;
}
}
}
break;
case QGis::WKBMultiLineString:
case QGis::WKBMultiLineString25D:
mls = g1->asMultiPolyline();
for ( int k = 0; k < mls.size(); ++k )
{
QgsPolyline& ls = mls[k];
for ( int i = 1; i < ls.size(); ++i )
//.........这里部分代码省略.........
示例13: QgsGeometry
QgsGeometry* QgsMapToolDeletePart::partUnderPoint( QPoint point, QgsFeatureId& fid, int& partNum )
{
QgsFeature f;
QgsGeometry* geomPart = new QgsGeometry();
switch ( vlayer->geometryType() )
{
case QGis::Point:
case QGis::Line:
{
QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToCurrentLayer( point, QgsPointLocator::Vertex | QgsPointLocator::Edge );
if ( !match.isValid() )
return geomPart;
int snapVertex = match.vertexIndex();
vlayer->getFeatures( QgsFeatureRequest().setFilterFid( match.featureId() ) ).nextFeature( f );
const QgsGeometry* g = f.constGeometry();
if ( !g->isMultipart() )
{
fid = match.featureId();
delete geomPart;
return QgsGeometry::fromPoint( match.point() );
}
if ( g->wkbType() == QGis::WKBMultiPoint || g->wkbType() == QGis::WKBMultiPoint25D )
{
fid = match.featureId();
partNum = snapVertex;
delete geomPart;
return QgsGeometry::fromPoint( match.point() );
}
if ( g->wkbType() == QGis::WKBMultiLineString || g->wkbType() == QGis::WKBMultiLineString25D )
{
QgsMultiPolyline mline = g->asMultiPolyline();
for ( int part = 0; part < mline.count(); part++ )
{
if ( snapVertex < mline[part].count() )
{
fid = match.featureId();
partNum = part;
delete geomPart;
return QgsGeometry::fromPolyline( mline[part] );
}
snapVertex -= mline[part].count();
}
}
break;
}
case QGis::Polygon:
{
QgsPoint layerCoords = toLayerCoordinates( vlayer, point );
double searchRadius = QgsTolerance::vertexSearchRadius( mCanvas->currentLayer(), mCanvas->mapSettings() );
QgsRectangle selectRect( layerCoords.x() - searchRadius, layerCoords.y() - searchRadius,
layerCoords.x() + searchRadius, layerCoords.y() + searchRadius );
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( selectRect ) );
fit.nextFeature( f );
const QgsGeometry* g = f.constGeometry();
if ( !g )
return geomPart;
if ( !g->isMultipart() )
{
fid = f.id();
return geomPart;
}
QgsMultiPolygon mpolygon = g->asMultiPolygon();
for ( int part = 0; part < mpolygon.count(); part++ ) // go through the polygons
{
const QgsPolygon& polygon = mpolygon[part];
QgsGeometry* partGeo = QgsGeometry::fromPolygon( polygon );
if ( partGeo->contains( &layerCoords ) )
{
fid = f.id();
partNum = part;
delete geomPart;
return partGeo;
}
delete partGeo;
}
break;
}
default:
{
break;
}
}
return geomPart;
}
示例14: myLayer
void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVector< QgsPoint >& additionalPoints,
QVector< QgsPoint >& tiedPoint ) const
{
QgsVectorLayer *vl = myLayer();
if ( vl == NULL )
return;
int featureCount = ( int ) vl->featureCount() * 2;
int step = 0;
QgsCoordinateTransform ct;
QgsDistanceArea da;
ct.setSourceCrs( vl->crs() );
if ( builder->coordinateTransformEnabled() )
{
ct.setDestCRS( builder->destinationCrs() );
da.setProjectionsEnabled( true );
//
//da.setSourceCrs( builder->destinationCrs().srsid() );
//
}
else
{
ct.setDestCRS( vl->crs() );
da.setProjectionsEnabled( false );
}
tiedPoint = QVector< QgsPoint >( additionalPoints.size(), QgsPoint( 0.0, 0.0 ) );
TiePointInfo tmpInfo;
tmpInfo.mLength = infinity();
QVector< TiePointInfo > pointLengthMap( additionalPoints.size(), tmpInfo );
QVector< TiePointInfo >::iterator pointLengthIt;
// begin: tie points to the graph
QgsAttributeList la;
vl->select( la );
QgsFeature feature;
while ( vl->nextFeature( feature ) )
{
QgsMultiPolyline mpl;
if ( feature.geometry()->wkbType() == QGis::WKBLineString )
{
mpl.push_back( feature.geometry()->asPolyline() );
}else if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString )
{
mpl = feature.geometry()->asMultiPolyline();
}
QgsMultiPolyline::iterator mplIt;
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
{
QgsPoint pt1, pt2;
bool isFirstPoint = true;
QgsPolyline::iterator pointIt;
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
{
pt2 = builder->addVertex( ct.transform( *pointIt ) );
if ( !isFirstPoint )
{
int i = 0;
for ( i = 0; i != additionalPoints.size(); ++i )
{
TiePointInfo info;
if ( pt1 == pt2 )
{
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
info.mTiedPoint = pt1;
}
else
{
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(), pt2.x(), pt2.y(), info.mTiedPoint );
}
if ( pointLengthMap[ i ].mLength > info.mLength )
{
info.mTiedPoint = builder->addVertex( info.mTiedPoint );
info.mFirstPoint = pt1;
info.mLastPoint = pt2;
pointLengthMap[ i ] = info;
tiedPoint[ i ] = info.mTiedPoint;
}
}
}
pt1 = pt2;
isFirstPoint = false;
}
}
emit buildProgress( ++step, featureCount );
}
// end: tie points to graph
if ( mDirectionFieldId != -1 )
{
la.push_back( mDirectionFieldId );
}
if ( mSpeedFieldId != -1 )
{
//.........这里部分代码省略.........
示例15: colorFromSymbolLayer
void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
{
const QgsFeature* fet = ctx.feature();
if ( !fet )
{
return;
}
QgsGeometry* geom = fet->geometry();
if ( geom )
{
int c = 0;
if ( mSymbologyExport != NoSymbology )
{
c = colorFromSymbolLayer( symbolLayer, ctx );
}
double width = -1;
if ( mSymbologyExport != NoSymbology && symbolLayer )
{
width = symbolLayer->dxfWidth( *this, ctx );
}
QString lineStyleName = "CONTINUOUS";
if ( mSymbologyExport != NoSymbology )
{
lineStyleName = lineStyleFromSymbolLayer( symbolLayer );
}
QGis::WkbType geometryType = geom->wkbType();
//single point
if ( geometryType == QGis::WKBPoint || geometryType == QGis::WKBPoint25D )
{
writePoint( geom->asPoint(), layer, c, fet, symbolLayer, symbol );
}
//multipoint
if ( geometryType == QGis::WKBMultiPoint || geometryType == QGis::WKBMultiPoint25D )
{
QgsMultiPoint multiPoint = geom->asMultiPoint();
QgsMultiPoint::const_iterator it = multiPoint.constBegin();
for ( ; it != multiPoint.constEnd(); ++it )
{
writePoint( *it, layer, c, fet, symbolLayer, symbol );
}
}
//single line
if ( geometryType == QGis::WKBLineString || geometryType == QGis::WKBLineString25D )
{
writePolyline( geom->asPolyline(), layer, lineStyleName, c, width, false );
}
//multiline
if ( geometryType == QGis::WKBMultiLineString || geometryType == QGis::WKBMultiLineString25D )
{
QgsMultiPolyline multiLine = geom->asMultiPolyline();
QgsMultiPolyline::const_iterator lIt = multiLine.constBegin();
for ( ; lIt != multiLine.constEnd(); ++lIt )
{
writePolyline( *lIt, layer, lineStyleName, c, width, false );
}
}
//polygon
if ( geometryType == QGis::WKBPolygon || geometryType == QGis::WKBPolygon25D )
{
QgsPolygon polygon = geom->asPolygon();
QgsPolygon::const_iterator polyIt = polygon.constBegin();
for ( ; polyIt != polygon.constEnd(); ++polyIt ) //iterate over rings
{
writePolyline( *polyIt, layer, lineStyleName, c, width, true );
}
}
//multipolygon or polygon
if ( geometryType == QGis::WKBMultiPolygon || geometryType == QGis::WKBMultiPolygon25D )
{
QgsMultiPolygon mp = geom->asMultiPolygon();
QgsMultiPolygon::const_iterator mpIt = mp.constBegin();
for ( ; mpIt != mp.constEnd(); ++mpIt )
{
QgsPolygon::const_iterator polyIt = mpIt->constBegin();
for ( ; polyIt != mpIt->constEnd(); ++polyIt )
{
writePolyline( *polyIt, layer, lineStyleName, c, width, true );
}
}
}
}
}