QString QgsMultiSurface::asJSON( int precision ) const { // GeoJSON does not support curves QString json = QStringLiteral( "{\"type\": \"MultiPolygon\", \"coordinates\": [" ); Q_FOREACH ( const QgsAbstractGeometry *geom, mGeometries ) { if ( dynamic_cast<const QgsSurface*>( geom ) ) { json += '['; QgsPolygonV2* polygon = static_cast<const QgsSurface*>( geom )->surfaceToPolygon(); QgsLineString* exteriorLineString = polygon->exteriorRing()->curveToLine(); QgsPointSequence exteriorPts; exteriorLineString->points( exteriorPts ); json += QgsGeometryUtils::pointsToJSON( exteriorPts, precision ) + ", "; delete exteriorLineString; for ( int i = 0, n = polygon->numInteriorRings(); i < n; ++i ) { QgsLineString* interiorLineString = polygon->interiorRing( i )->curveToLine(); QgsPointSequence interiorPts; interiorLineString->points( interiorPts ); json += QgsGeometryUtils::pointsToJSON( interiorPts, precision ) + ", "; delete interiorLineString; } if ( json.endsWith( QLatin1String( ", " ) ) ) { json.chop( 2 ); // Remove last ", " } delete polygon; json += QLatin1String( "], " ); } } if ( json.endsWith( QLatin1String( ", " ) ) ) { json.chop( 2 ); // Remove last ", " } json += QLatin1String( "] }" ); return json; }
int QgsMapToolCapture::addCurve( QgsCurve *c ) { if ( !c ) { return 1; } if ( !mRubberBand ) { mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry ); } QgsLineString *lineString = c->curveToLine(); QgsPointSequence linePoints; lineString->points( linePoints ); delete lineString; QgsPointSequence::const_iterator ptIt = linePoints.constBegin(); for ( ; ptIt != linePoints.constEnd(); ++ptIt ) { mRubberBand->addPoint( QgsPointXY( ptIt->x(), ptIt->y() ) ); } if ( !mTempRubberBand ) { mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true ); } else { mTempRubberBand->reset(); } QgsPoint endPt = c->endPoint(); mTempRubberBand->addPoint( QgsPointXY( 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() ); QgsCoordinateTransform ct = mCanvas->mapSettings().layerTransform( vlayer ); if ( ct.isValid() ) { c->transform( ct, QgsCoordinateTransform::ReverseTransform ); } mCaptureCurve.addCurve( c ); for ( int i = 0; i < c->length(); ++i ) mSnappingMatches.append( QgsPointLocator::Match() ); return 0; }