27QgsSfcgalGeometry::QgsSfcgalGeometry()
28 : mIsPrimitive( false )
33 : mIsPrimitive( false )
38 sfcgal::errorHandler()->clearText( &errorMsg );
39 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( qgsGeom, &errorMsg );
40 THROW_ON_ERROR( &errorMsg );
45 : mIsPrimitive( false )
48 sfcgal::errorHandler()->clearText( &errorMsg );
49 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( &qgsGeom, &errorMsg );
50 THROW_ON_ERROR( &errorMsg );
53QgsSfcgalGeometry::QgsSfcgalGeometry( sfcgal::shared_geom sfcgalGeom )
54 : mSfcgalGeom( sfcgalGeom ), mIsPrimitive( false )
58QgsSfcgalGeometry::QgsSfcgalGeometry( sfcgal::shared_prim sfcgalPrim, sfcgal::primitiveType type )
59 : mIsPrimitive( true )
61#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
62 mSfcgalPrim = sfcgalPrim;
67 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
71QgsSfcgalGeometry::QgsSfcgalGeometry(
const QgsGeometry &qgsGeom )
74 sfcgal::errorHandler()->clearText( &errorMsg );
75 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( qgsGeom.
constGet(), &errorMsg );
76 THROW_ON_ERROR( &errorMsg );
79QgsSfcgalGeometry::QgsSfcgalGeometry(
const QgsSfcgalGeometry &otherGeom )
82 sfcgal::errorHandler()->clearText( &errorMsg );
83 mIsPrimitive = otherGeom.mIsPrimitive;
84#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
85 mPrimType = otherGeom.mPrimType;
87 mSfcgalPrim = QgsSfcgalEngine::primitiveClone( otherGeom.mSfcgalPrim.get(), &errorMsg );
90 mSfcgalGeom = QgsSfcgalEngine::cloneGeometry( otherGeom.mSfcgalGeom.get(), &errorMsg );
91 THROW_ON_ERROR( &errorMsg );
94QgsSfcgalGeometry::QgsSfcgalGeometry(
const QString &wkt )
97 sfcgal::errorHandler()->clearText( &errorMsg );
98 mSfcgalGeom = QgsSfcgalEngine::fromWkt( wkt, &errorMsg );
99 THROW_ON_ERROR( &errorMsg );
102sfcgal::shared_geom QgsSfcgalGeometry::workingGeom()
const
104 sfcgal::shared_geom geom;
106#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
110 geom = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), mPrimTransform, &errorMsg );
111 THROW_ON_ERROR( &errorMsg );
124 sfcgal::errorHandler()->clearText( &errorMsg );
126#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
131 Qgis::WkbType out = QgsSfcgalEngine::wkbType( mSfcgalGeom.get(), &errorMsg );
132 THROW_ON_ERROR( &errorMsg );
136QString QgsSfcgalGeometry::geometryType()
const
139 sfcgal::errorHandler()->clearText( &errorMsg );
142#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
147 case sfcgal::primitiveType::SFCGAL_TYPE_CYLINDER:
150 case sfcgal::primitiveType::SFCGAL_TYPE_SPHERE:
153 case sfcgal::primitiveType::SFCGAL_TYPE_TORUS:
156 case sfcgal::primitiveType::SFCGAL_TYPE_BOX:
159 case sfcgal::primitiveType::SFCGAL_TYPE_CUBE:
162 case sfcgal::primitiveType::SFCGAL_TYPE_CONE:
166 sfcgal::errorHandler()->addText( QStringLiteral(
"Type '%1' is unknown." ).arg( mPrimType ) );
172 out = QgsSfcgalEngine::geometryType( mSfcgalGeom.get(), &errorMsg );
173 THROW_ON_ERROR( &errorMsg );
178std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::clone()
const
180 return std::make_unique<QgsSfcgalGeometry>( *
this );
183std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::fromWkb(
const QgsConstWkbPtr &wkbPtr )
191 sfcgal::shared_geom sfcgalGeom = QgsSfcgalEngine::fromWkb( wkbPtr, &errorMsg );
192 THROW_ON_ERROR( &errorMsg );
194 return std::make_unique<QgsSfcgalGeometry>( sfcgalGeom );
201 sfcgal::errorHandler()->clearText( &errorMsg );
203 sfcgal::shared_geom geom = workingGeom();
204 QByteArray wkbArray = QgsSfcgalEngine::toWkb( geom.get(), &errorMsg );
205 THROW_ON_ERROR( &errorMsg );
210QString QgsSfcgalGeometry::asWkt(
int precision )
const
213 sfcgal::errorHandler()->clearText( &errorMsg );
215 sfcgal::shared_geom geom = workingGeom();
216 QString out = QgsSfcgalEngine::toWkt( geom.get(), precision, &errorMsg );
217 THROW_ON_ERROR( &errorMsg );
222std::unique_ptr<QgsAbstractGeometry> QgsSfcgalGeometry::asQgisGeometry()
const
225 sfcgal::errorHandler()->clearText( &errorMsg );
227 sfcgal::shared_geom geom = workingGeom();
228 std::unique_ptr<QgsAbstractGeometry> out = QgsSfcgalEngine::toAbstractGeometry( geom.get(), &errorMsg );
229 THROW_ON_ERROR( &errorMsg );
233std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::boundary()
const
236 sfcgal::errorHandler()->clearText( &errorMsg );
238 sfcgal::shared_geom geom = workingGeom();
239 sfcgal::shared_geom boundary = QgsSfcgalEngine::boundary( geom.get(), &errorMsg );
240 THROW_ON_ERROR( &errorMsg );
242 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( boundary, &errorMsg );
243 THROW_ON_ERROR( &errorMsg );
247bool QgsSfcgalGeometry::operator==(
const QgsSfcgalGeometry &other )
const
249#if SFCGAL_VERSION < SFCGAL_MAKE_VERSION( 2, 1, 0 )
251 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.1 or later" ) );
256#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
257 if ( mIsPrimitive != other.mIsPrimitive )
262 out = QgsSfcgalEngine::primitiveIsEqual( mSfcgalPrim.get(), other.mSfcgalPrim.get(), -1.0, &errorMsg );
267 out = QgsSfcgalEngine::isEqual( mSfcgalGeom.get(), other.mSfcgalGeom.get(), -1.0, &errorMsg );
269 THROW_ON_ERROR( &errorMsg );
274bool QgsSfcgalGeometry::operator!=(
const QgsSfcgalGeometry &other )
const
276 return !( *
this == other );
279bool QgsSfcgalGeometry::fuzzyEqual(
const QgsSfcgalGeometry &other,
double epsilon )
const
282 sfcgal::errorHandler()->clearText( &errorMsg );
286#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
287 if ( mIsPrimitive != other.mIsPrimitive )
292 out = QgsSfcgalEngine::primitiveIsEqual( mSfcgalPrim.get(), other.mSfcgalPrim.get(), epsilon, &errorMsg );
297 out = QgsSfcgalEngine::isEqual( mSfcgalGeom.get(), other.mSfcgalGeom.get(), epsilon, &errorMsg );
300 THROW_ON_ERROR( &errorMsg );
304int QgsSfcgalGeometry::dimension()
const
307 sfcgal::errorHandler()->clearText( &errorMsg );
312 int result = QgsSfcgalEngine::dimension( mSfcgalGeom.get(), &errorMsg );
313 THROW_ON_ERROR( &errorMsg );
318std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::fromWkt(
const QString &wkt )
322 sfcgal::shared_geom sfcgalGeom = QgsSfcgalEngine::fromWkt( wkt, &errorMsg );
323 THROW_ON_ERROR( &errorMsg );
325 return std::make_unique<QgsSfcgalGeometry>( sfcgalGeom );
328int QgsSfcgalGeometry::partCount()
const
331 sfcgal::errorHandler()->clearText( &errorMsg );
336 int out = QgsSfcgalEngine::partCount( mSfcgalGeom.get(), &errorMsg );
337 THROW_ON_ERROR( &errorMsg );
342bool QgsSfcgalGeometry::addZValue(
double zValue )
345 sfcgal::errorHandler()->clearText( &errorMsg );
350 const bool added = QgsSfcgalEngine::addZValue( mSfcgalGeom.get(), zValue, &errorMsg );
351 THROW_ON_ERROR( &errorMsg );
358bool QgsSfcgalGeometry::addMValue(
double mValue )
361 sfcgal::errorHandler()->clearText( &errorMsg );
366 const bool added = QgsSfcgalEngine::addMValue( mSfcgalGeom.get(), mValue, &errorMsg );
367 THROW_ON_ERROR( &errorMsg );
374bool QgsSfcgalGeometry::dropZValue()
377 sfcgal::errorHandler()->clearText( &errorMsg );
382 const bool dropped = QgsSfcgalEngine::dropZValue( mSfcgalGeom.get(), &errorMsg );
383 THROW_ON_ERROR( &errorMsg );
390bool QgsSfcgalGeometry::dropMValue()
393 sfcgal::errorHandler()->clearText( &errorMsg );
398 const bool dropped = QgsSfcgalEngine::dropMValue( mSfcgalGeom.get(), &errorMsg );
399 THROW_ON_ERROR( &errorMsg );
406void QgsSfcgalGeometry::swapXy()
409 sfcgal::errorHandler()->clearText( &errorMsg );
414 QgsSfcgalEngine::swapXy( mSfcgalGeom.get(), &errorMsg );
415 THROW_ON_ERROR( &errorMsg );
420bool QgsSfcgalGeometry::isValid()
const
423 sfcgal::errorHandler()->clearText( &errorMsg );
428 const bool valid = QgsSfcgalEngine::isValid( mSfcgalGeom.get(), &errorMsg,
nullptr );
429 THROW_ON_ERROR( &errorMsg );
433void QgsSfcgalGeometry::clearCache()
const
437bool QgsSfcgalGeometry::isSimple()
const
440 sfcgal::errorHandler()->clearText( &errorMsg );
445 bool result = QgsSfcgalEngine::isSimple( mSfcgalGeom.get(), &errorMsg );
446 THROW_ON_ERROR( &errorMsg );
450QgsPoint QgsSfcgalGeometry::centroid()
const
453 sfcgal::errorHandler()->clearText( &errorMsg );
455 sfcgal::shared_geom geom = workingGeom();
456 return QgsSfcgalEngine::centroid( geom.get(), &errorMsg );
459bool QgsSfcgalGeometry::isEmpty()
const
462 sfcgal::errorHandler()->clearText( &errorMsg );
467 bool result = QgsSfcgalEngine::isEmpty( mSfcgalGeom.get(), &errorMsg );
468 THROW_ON_ERROR( &errorMsg );
473std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::translate(
const QgsVector3D &translation )
const
476 sfcgal::errorHandler()->clearText( &errorMsg );
478 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
479#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
482 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
483 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
484 resultGeom->setPrimitiveTranslate( translation );
489 sfcgal::shared_geom result = QgsSfcgalEngine::translate( mSfcgalGeom.get(), translation, &errorMsg );
490 THROW_ON_ERROR( &errorMsg );
491 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
494 THROW_ON_ERROR( &errorMsg );
498std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::scale(
const QgsVector3D &scaleFactor,
const QgsPoint ¢er )
const
501 sfcgal::errorHandler()->clearText( &errorMsg );
503 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
504#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
507 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
508 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
509 resultGeom->setPrimitiveScale( scaleFactor, center );
514 sfcgal::shared_geom result = QgsSfcgalEngine::scale( mSfcgalGeom.get(), scaleFactor, center, &errorMsg );
515 THROW_ON_ERROR( &errorMsg );
516 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
519 THROW_ON_ERROR( &errorMsg );
523std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate2D(
double angle,
const QgsPoint ¢er )
const
526 sfcgal::errorHandler()->clearText( &errorMsg );
528 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
529#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
532 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
533 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
534 resultGeom->setPrimitiveRotation( angle, { 0.0, 0.0, 1.0 }, center );
539 sfcgal::shared_geom result = QgsSfcgalEngine::rotate2D( mSfcgalGeom.get(), angle, center, &errorMsg );
540 THROW_ON_ERROR( &errorMsg );
542 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
545 THROW_ON_ERROR( &errorMsg );
549std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::transform(
const QMatrix4x4 &mat )
const
552 sfcgal::errorHandler()->clearText( &errorMsg );
554#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
555 sfcgal::shared_geom geom = workingGeom();
557 sfcgal::shared_geom result = QgsSfcgalEngine::transform( geom.get(), mat );
558 THROW_ON_ERROR( &errorMsg );
560 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
561 THROW_ON_ERROR( &errorMsg );
565 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
569std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate3D(
double angle,
const QgsVector3D &axisVector,
const QgsPoint ¢er )
const
572 sfcgal::errorHandler()->clearText( &errorMsg );
574 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
575#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
578 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
579 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
580 resultGeom->setPrimitiveRotation( angle, axisVector, center );
585 sfcgal::shared_geom result = QgsSfcgalEngine::rotate3D( mSfcgalGeom.get(), angle, axisVector, center, &errorMsg );
586 THROW_ON_ERROR( &errorMsg );
588 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
591 THROW_ON_ERROR( &errorMsg );
595double QgsSfcgalGeometry::area(
bool withDiscretization )
const
598 sfcgal::errorHandler()->clearText( &errorMsg );
601#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
604 result = QgsSfcgalEngine::primitiveArea( mSfcgalPrim.get(), withDiscretization, &errorMsg );
609 ( void ) withDiscretization;
610 result = QgsSfcgalEngine::area( mSfcgalGeom.get(), &errorMsg );
613 THROW_ON_ERROR( &errorMsg );
617double QgsSfcgalGeometry::length()
const
620 sfcgal::errorHandler()->clearText( &errorMsg );
625 double result = QgsSfcgalEngine::length( mSfcgalGeom.get(), &errorMsg );
626 THROW_ON_ERROR( &errorMsg );
631double QgsSfcgalGeometry::volume(
bool withDiscretization )
const
634 sfcgal::errorHandler()->clearText( &errorMsg );
640#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
641 result = QgsSfcgalEngine::primitiveVolume( mSfcgalPrim.get(), withDiscretization, &errorMsg );
643 ( void ) withDiscretization;
644 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
647 THROW_ON_ERROR( &errorMsg );
654 sfcgal::errorHandler()->clearText( &errorMsg );
655 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
656 THROW_ON_ERROR( &errorMsg );
658 sfcgal::shared_geom geom = workingGeom();
659 bool out = QgsSfcgalEngine::intersects( geom.get(), otherShared.get(), &errorMsg );
660 THROW_ON_ERROR( &errorMsg );
664bool QgsSfcgalGeometry::intersects(
const QgsSfcgalGeometry &otherGeom )
const
667 sfcgal::errorHandler()->clearText( &errorMsg );
669 sfcgal::shared_geom geom = workingGeom();
670 bool out = QgsSfcgalEngine::intersects( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
671 THROW_ON_ERROR( &errorMsg );
675std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection(
const QgsAbstractGeometry *otherGeom )
const
678 sfcgal::errorHandler()->clearText( &errorMsg );
679 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
680 THROW_ON_ERROR( &errorMsg );
682 sfcgal::shared_geom geom = workingGeom();
683 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherShared.get(), &errorMsg );
684 THROW_ON_ERROR( &errorMsg );
686 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
687 THROW_ON_ERROR( &errorMsg );
691std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection(
const QgsSfcgalGeometry &otherGeom )
const
694 sfcgal::errorHandler()->clearText( &errorMsg );
696 sfcgal::shared_geom geom = workingGeom();
697 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
698 THROW_ON_ERROR( &errorMsg );
700 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
701 THROW_ON_ERROR( &errorMsg );
705std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::combine(
const QVector<QgsAbstractGeometry *> &geomList )
const
708 sfcgal::errorHandler()->clearText( &errorMsg );
709 QVector<sfcgal::shared_geom> sfcgalGeomList;
711 sfcgal::shared_geom geom = workingGeom();
712 sfcgalGeomList.append( geom );
713 for ( QVector<QgsAbstractGeometry *>::const_iterator ite = geomList.constBegin(); ite != geomList.constEnd(); ++ite )
715 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( *ite, &errorMsg );
716 THROW_ON_ERROR( &errorMsg );
717 sfcgalGeomList.append( otherShared );
720 sfcgal::shared_geom result = QgsSfcgalEngine::combine( sfcgalGeomList, &errorMsg );
721 THROW_ON_ERROR( &errorMsg );
723 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
724 THROW_ON_ERROR( &errorMsg );
728std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference(
const QgsAbstractGeometry *otherGeom )
const
731 sfcgal::errorHandler()->clearText( &errorMsg );
732 sfcgal::shared_geom otherSharedr = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
733 THROW_ON_ERROR( &errorMsg );
735 sfcgal::shared_geom geom = workingGeom();
736 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherSharedr.get(), &errorMsg );
737 THROW_ON_ERROR( &errorMsg );
739 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
740 THROW_ON_ERROR( &errorMsg );
744std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference(
const QgsSfcgalGeometry &otherGeom )
const
747 sfcgal::errorHandler()->clearText( &errorMsg );
749 sfcgal::shared_geom geom = workingGeom();
750 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
751 THROW_ON_ERROR( &errorMsg );
753 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
754 THROW_ON_ERROR( &errorMsg );
758std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::triangulate()
const
761 sfcgal::errorHandler()->clearText( &errorMsg );
763 sfcgal::shared_geom geom = workingGeom();
764 sfcgal::shared_geom result = QgsSfcgalEngine::triangulate( geom.get(), &errorMsg );
765 THROW_ON_ERROR( &errorMsg );
767 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
768 THROW_ON_ERROR( &errorMsg );
772std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::convexHull()
const
775 sfcgal::errorHandler()->clearText( &errorMsg );
777 sfcgal::shared_geom geom = workingGeom();
778 sfcgal::shared_geom result = QgsSfcgalEngine::convexHull( geom.get(), &errorMsg );
779 THROW_ON_ERROR( &errorMsg );
781 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
782 THROW_ON_ERROR( &errorMsg );
786std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::envelope()
const
789 sfcgal::errorHandler()->clearText( &errorMsg );
791 sfcgal::shared_geom geom = workingGeom();
792 sfcgal::shared_geom result = QgsSfcgalEngine::envelope( geom.get(), &errorMsg );
793 THROW_ON_ERROR( &errorMsg );
795 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
796 THROW_ON_ERROR( &errorMsg );
800bool QgsSfcgalGeometry::covers(
const QgsSfcgalGeometry &otherGeom )
const
803 sfcgal::errorHandler()->clearText( &errorMsg );
805 sfcgal::shared_geom geom = workingGeom();
806 bool out = QgsSfcgalEngine::covers( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
807 THROW_ON_ERROR( &errorMsg );
811std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer3D(
double radius,
int segments,
Qgis::JoinStyle3D joinStyle3D )
const
814 sfcgal::errorHandler()->clearText( &errorMsg );
816 sfcgal::shared_geom geom = workingGeom();
817 sfcgal::shared_geom result = QgsSfcgalEngine::buffer3D( geom.get(), radius, segments, joinStyle3D, &errorMsg );
818 THROW_ON_ERROR( &errorMsg );
820 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
821 THROW_ON_ERROR( &errorMsg );
825std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer2D(
double radius,
int segments,
Qgis::JoinStyle joinStyle )
const
828 sfcgal::errorHandler()->clearText( &errorMsg );
830 sfcgal::shared_geom geom = workingGeom();
831 sfcgal::shared_geom result = QgsSfcgalEngine::buffer2D( geom.get(), radius, segments, joinStyle, &errorMsg );
832 THROW_ON_ERROR( &errorMsg );
834 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
835 THROW_ON_ERROR( &errorMsg );
839std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::simplify(
double tolerance,
bool preserveTopology )
const
842 sfcgal::errorHandler()->clearText( &errorMsg );
844 sfcgal::shared_geom geom = workingGeom();
845 sfcgal::shared_geom result = QgsSfcgalEngine::simplify( geom.get(), tolerance, preserveTopology, &errorMsg );
846 THROW_ON_ERROR( &errorMsg );
848 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
849 THROW_ON_ERROR( &errorMsg );
853std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::extrude(
const QgsVector3D &extrusion )
const
856 sfcgal::errorHandler()->clearText( &errorMsg );
858 sfcgal::shared_geom geom = workingGeom();
859 sfcgal::shared_geom result = QgsSfcgalEngine::extrude( geom.get(), extrusion, &errorMsg );
860 THROW_ON_ERROR( &errorMsg );
862 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
863 THROW_ON_ERROR( &errorMsg );
867std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::approximateMedialAxis()
const
870 sfcgal::errorHandler()->clearText( &errorMsg );
872 sfcgal::shared_geom geom = workingGeom();
873 sfcgal::shared_geom result = QgsSfcgalEngine::approximateMedialAxis( geom.get(), &errorMsg );
874 THROW_ON_ERROR( &errorMsg );
876 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
877 THROW_ON_ERROR( &errorMsg );
881std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCube(
double size )
883#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
885 sfcgal::errorHandler()->clearText( &errorMsg );
886 sfcgal::shared_prim result = QgsSfcgalEngine::createCube( size, &errorMsg );
887 THROW_ON_ERROR( &errorMsg );
889 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CUBE, &errorMsg );
890 THROW_ON_ERROR( &errorMsg );
894 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
898std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::primitiveAsPolyhedralSurface()
const
900#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
902 throw QgsSfcgalException(
"Need primitive geometry to operate." );
905 sfcgal::errorHandler()->clearText( &errorMsg );
906 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), mPrimTransform, &errorMsg );
907 THROW_ON_ERROR( &errorMsg );
909 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
910 THROW_ON_ERROR( &errorMsg );
913 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
917QMatrix4x4 QgsSfcgalGeometry::primitiveTransform()
const
919#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
921 throw QgsSfcgalException(
"Need primitive geometry to operate." );
923 return mPrimTransform;
925 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
929QList<std::pair<QString, QString>> QgsSfcgalGeometry::primitiveParameters()
const
931#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
933 throw QgsSfcgalException(
"Need primitive geometry to operate." );
936 sfcgal::errorHandler()->clearText( &errorMsg );
937 QVector<sfcgal::PrimitiveParameterDesc> result = QgsSfcgalEngine::primitiveParameters( mSfcgalPrim.get(), &errorMsg );
938 THROW_ON_ERROR( &errorMsg );
940 QList<QPair<QString, QString>> out;
941 for (
const auto ¶m : result )
943 out.append( std::pair<QString, QString>( QString::fromStdString( param.name ), QString::fromStdString( param.type ) ) );
948 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
952QVariant QgsSfcgalGeometry::primitiveParameter(
const QString &name )
const
954#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
956 throw QgsSfcgalException(
"Need primitive geometry to operate." );
959 sfcgal::errorHandler()->clearText( &errorMsg );
960 QVariant result = QgsSfcgalEngine::primitiveParameter( mSfcgalPrim.get(), name, &errorMsg );
961 THROW_ON_ERROR( &errorMsg );
966 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
970void QgsSfcgalGeometry::primitiveSetParameter(
const QString &name,
const QVariant &value )
972#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
974 throw QgsSfcgalException(
"Need primitive geometry to operate." );
977 sfcgal::errorHandler()->clearText( &errorMsg );
978 QgsSfcgalEngine::primitiveSetParameter( mSfcgalPrim.get(), name, value, &errorMsg );
979 THROW_ON_ERROR( &errorMsg );
984 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
989#if SFCGAL_VERSION >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
990void QgsSfcgalGeometry::setPrimitiveTranslate(
const QgsVector3D &translation )
992 mPrimTransform.translate( mPrimTransform.column( 3 ).toVector3D() + translation.
toVector3D() );
995void QgsSfcgalGeometry::setPrimitiveScale(
const QgsVector3D &scaleFactor,
const QgsPoint ¢er )
997 QVector3D qCenter( center.
x(), center.
y(), center.
z() );
998 QVector3D prevTrans = mPrimTransform.column( 3 ).toVector3D();
999 mPrimTransform.translate( prevTrans - qCenter );
1000 mPrimTransform.scale( scaleFactor.
toVector3D() );
1001 mPrimTransform.translate( prevTrans + qCenter );
1004void QgsSfcgalGeometry::setPrimitiveRotation(
double angle,
const QgsVector3D &axisVector,
const QgsPoint ¢er )
1006 QVector3D qCenter( center.
x(), center.
y(), center.
z() );
1007 QVector3D prevTrans = mPrimTransform.column( 3 ).toVector3D();
1008 mPrimTransform.translate( prevTrans - qCenter );
1010 mPrimTransform.rotate( QQuaternion::fromAxisAndAngle( axisVector.
toVector3D(), angle ) );
1011 mPrimTransform.translate( prevTrans + qCenter );
JoinStyle3D
Join styles for 3D buffers.
JoinStyle
Join styles for buffers.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ PolyhedralSurfaceZ
PolyhedralSurfaceZ.
Abstract base class for all geometries.
QFlags< WkbFlag > WkbFlags
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Custom exception class which is raised when an operation is not supported.
Point geometry type, with support for z-dimension and m-values.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
QVector3D toVector3D() const
Converts the current object to QVector3D.