QgsLineStringV2* QgsCircularStringV2::curveToLine( double tolerance, SegmentationToleranceType toleranceType ) const { QgsLineStringV2* line = new QgsLineStringV2(); QgsPointSequenceV2 points; int nPoints = numPoints(); for ( int i = 0; i < ( nPoints - 2 ) ; i += 2 ) { segmentize( pointN( i ), pointN( i + 1 ), pointN( i + 2 ), points, tolerance, toleranceType ); } line->setPoints( points ); return line; }
QgsLineStringV2* QgsLineStringV2::reversed() const { QgsLineStringV2* copy = clone(); std::reverse( copy->mX.begin(), copy->mX.end() ); std::reverse( copy->mY.begin(), copy->mY.end() ); if ( copy->is3D() ) { std::reverse( copy->mZ.begin(), copy->mZ.end() ); } if ( copy->isMeasure() ) { std::reverse( copy->mM.begin(), copy->mM.end() ); } return copy; }
int QgsMapToolCapture::addCurve( QgsCurveV2* c ) { if ( !c ) { return 1; } if ( !mRubberBand ) { mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line ); } QgsLineStringV2* lineString = c->curveToLine(); QList<QgsPointV2> linePoints; lineString->points( linePoints ); delete lineString; QList<QgsPointV2>::const_iterator ptIt = linePoints.constBegin(); for ( ; ptIt != linePoints.constEnd(); ++ptIt ) { mRubberBand->addPoint( QgsPoint( ptIt->x(), ptIt->y() ) ); } if ( !mTempRubberBand ) { mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QGis::Polygon : QGis::Line, true ); } else { mTempRubberBand->reset(); } QgsPointV2 endPt = c->endPoint(); mTempRubberBand->addPoint( QgsPoint( endPt.x(), endPt.y() ) ); //add last point of c //transform back to layer CRS in case map CRS and layer CRS are different QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ); const QgsCoordinateTransform* ct = mCanvas->mapSettings().layerTransform( vlayer ); if ( ct ) { c->transform( *ct, QgsCoordinateTransform::ReverseTransform ); } mCaptureCurve.addCurve( c ); return 0; }
QString QgsMultiSurfaceV2::asJSON( int precision ) const { // GeoJSON does not support curves QString json = "{\"type\": \"MultiPolygon\", \"coordinates\": ["; Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries ) { if ( dynamic_cast<const QgsSurfaceV2*>( geom ) ) { json += "["; QgsPolygonV2* polygon = static_cast<const QgsSurfaceV2*>( geom )->surfaceToPolygon(); QgsLineStringV2* exteriorLineString = polygon->exteriorRing()->curveToLine(); QList<QgsPointV2> exteriorPts; exteriorLineString->points( exteriorPts ); json += QgsGeometryUtils::pointsToJSON( exteriorPts, precision ) + ", "; delete exteriorLineString; for ( int i = 0, n = polygon->numInteriorRings(); i < n; ++i ) { QgsLineStringV2* interiorLineString = polygon->interiorRing( i )->curveToLine(); QList<QgsPointV2> interiorPts; interiorLineString->points( interiorPts ); json += QgsGeometryUtils::pointsToJSON( interiorPts, precision ) + ", "; delete interiorLineString; } if ( json.endsWith( ", " ) ) { json.chop( 2 ); // Remove last ", " } delete polygon; json += "], "; } } if ( json.endsWith( ", " ) ) { json.chop( 2 ); // Remove last ", " } json += "] }"; return json; }
QDomElement QgsMultiCurveV2::asGML2( QDomDocument& doc, int precision, const QString& ns ) const { // GML2 does not support curves QDomElement elemMultiLineString = doc.createElementNS( ns, "MultiLineString" ); Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries ) { if ( dynamic_cast<const QgsCurveV2*>( geom ) ) { QgsLineStringV2* lineString = static_cast<const QgsCurveV2*>( geom )->curveToLine(); QDomElement elemLineStringMember = doc.createElementNS( ns, "lineStringMember" ); elemLineStringMember.appendChild( lineString->asGML2( doc, precision, ns ) ); elemMultiLineString.appendChild( elemLineStringMember ); delete lineString; } } return elemMultiLineString; }
QgsAbstractGeometryV2* QgsGeometryImport::fromPolygon( const QgsPolygon& polygon ) { QgsPolygonV2* poly = new QgsPolygonV2(); QList<QgsCurveV2*> holes; for ( int i = 0; i < polygon.size(); ++i ) { QgsLineStringV2* l = linestringFromPolyline( polygon.at( i ) ); l->close(); if ( i == 0 ) { poly->setExteriorRing( l ); } else { holes.push_back( l ); } } poly->setInteriorRings( holes ); return poly; }
QString QgsMultiCurveV2::asJSON( int precision ) const { // GeoJSON does not support curves QString json = "{\"type\": \"MultiLineString\", \"coordinates\": ["; Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries ) { if ( dynamic_cast<const QgsCurveV2*>( geom ) ) { QgsLineStringV2* lineString = static_cast<const QgsCurveV2*>( geom )->curveToLine(); QgsPointSequenceV2 pts; lineString->points( pts ); json += QgsGeometryUtils::pointsToJSON( pts, precision ) + ", "; delete lineString; } } if ( json.endsWith( ", " ) ) { json.chop( 2 ); // Remove last ", " } json += "] }"; return json; }