28using namespace Qt::StringLiterals;
30QgsSfcgalGeometry::QgsSfcgalGeometry()
31 : mIsPrimitive( false )
36 : mIsPrimitive( false )
41 sfcgal::errorHandler()->clearText( &errorMsg );
42 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( qgsGeom, &errorMsg );
43 THROW_ON_ERROR( &errorMsg );
48 : mIsPrimitive( false )
51 sfcgal::errorHandler()->clearText( &errorMsg );
52 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( &qgsGeom, &errorMsg );
53 THROW_ON_ERROR( &errorMsg );
56QgsSfcgalGeometry::QgsSfcgalGeometry( sfcgal::shared_geom sfcgalGeom )
57 : mSfcgalGeom( sfcgalGeom ), mIsPrimitive( false )
61QgsSfcgalGeometry::QgsSfcgalGeometry( sfcgal::shared_prim sfcgalPrim, sfcgal::primitiveType type )
62 : mIsPrimitive( true )
64#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
65 mSfcgalPrim = sfcgalPrim;
70 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
74QgsSfcgalGeometry::QgsSfcgalGeometry(
const QgsGeometry &qgsGeom )
77 sfcgal::errorHandler()->clearText( &errorMsg );
78 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( qgsGeom.
constGet(), &errorMsg );
79 THROW_ON_ERROR( &errorMsg );
82QgsSfcgalGeometry::QgsSfcgalGeometry(
const QgsSfcgalGeometry &otherGeom )
85 sfcgal::errorHandler()->clearText( &errorMsg );
86 mIsPrimitive = otherGeom.mIsPrimitive;
87#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
88 mPrimType = otherGeom.mPrimType;
90 mSfcgalPrim = QgsSfcgalEngine::primitiveClone( otherGeom.mSfcgalPrim.get(), &errorMsg );
93 mSfcgalGeom = QgsSfcgalEngine::cloneGeometry( otherGeom.mSfcgalGeom.get(), &errorMsg );
94 THROW_ON_ERROR( &errorMsg );
97QgsSfcgalGeometry::QgsSfcgalGeometry(
const QString &wkt )
100 sfcgal::errorHandler()->clearText( &errorMsg );
101 mSfcgalGeom = QgsSfcgalEngine::fromWkt( wkt, &errorMsg );
102 THROW_ON_ERROR( &errorMsg );
105sfcgal::shared_geom QgsSfcgalGeometry::workingGeom()
const
107 sfcgal::shared_geom geom;
109#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
113 geom = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), mPrimTransform, &errorMsg );
114 THROW_ON_ERROR( &errorMsg );
127 sfcgal::errorHandler()->clearText( &errorMsg );
129#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
134 Qgis::WkbType out = QgsSfcgalEngine::wkbType( mSfcgalGeom.get(), &errorMsg );
135 THROW_ON_ERROR( &errorMsg );
139QString QgsSfcgalGeometry::geometryType()
const
142 sfcgal::errorHandler()->clearText( &errorMsg );
145#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
150 case sfcgal::primitiveType::SFCGAL_TYPE_CYLINDER:
153 case sfcgal::primitiveType::SFCGAL_TYPE_SPHERE:
156 case sfcgal::primitiveType::SFCGAL_TYPE_TORUS:
159 case sfcgal::primitiveType::SFCGAL_TYPE_BOX:
162 case sfcgal::primitiveType::SFCGAL_TYPE_CUBE:
165 case sfcgal::primitiveType::SFCGAL_TYPE_CONE:
169 sfcgal::errorHandler()->addText( u
"Type '%1' is unknown."_s.arg( mPrimType ) );
175 out = QgsSfcgalEngine::geometryType( mSfcgalGeom.get(), &errorMsg );
176 THROW_ON_ERROR( &errorMsg );
181std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::clone()
const
183 return std::make_unique<QgsSfcgalGeometry>( *
this );
186std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::fromWkb(
const QgsConstWkbPtr &wkbPtr )
194 sfcgal::shared_geom sfcgalGeom = QgsSfcgalEngine::fromWkb( wkbPtr, &errorMsg );
195 THROW_ON_ERROR( &errorMsg );
197 return std::make_unique<QgsSfcgalGeometry>( sfcgalGeom );
204 sfcgal::errorHandler()->clearText( &errorMsg );
206 sfcgal::shared_geom geom = workingGeom();
207 QByteArray wkbArray = QgsSfcgalEngine::toWkb( geom.get(), &errorMsg );
208 THROW_ON_ERROR( &errorMsg );
213QString QgsSfcgalGeometry::asWkt(
int precision )
const
216 sfcgal::errorHandler()->clearText( &errorMsg );
218 sfcgal::shared_geom geom = workingGeom();
219 QString out = QgsSfcgalEngine::toWkt( geom.get(), precision, &errorMsg );
220 THROW_ON_ERROR( &errorMsg );
225std::unique_ptr<QgsAbstractGeometry> QgsSfcgalGeometry::asQgisGeometry()
const
228 sfcgal::errorHandler()->clearText( &errorMsg );
230 sfcgal::shared_geom geom = workingGeom();
231 std::unique_ptr<QgsAbstractGeometry> out = QgsSfcgalEngine::toAbstractGeometry( geom.get(), &errorMsg );
232 THROW_ON_ERROR( &errorMsg );
236std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::boundary()
const
239 sfcgal::errorHandler()->clearText( &errorMsg );
241 sfcgal::shared_geom geom = workingGeom();
242 sfcgal::shared_geom boundary = QgsSfcgalEngine::boundary( geom.get(), &errorMsg );
243 THROW_ON_ERROR( &errorMsg );
245 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( boundary, &errorMsg );
246 THROW_ON_ERROR( &errorMsg );
250bool QgsSfcgalGeometry::operator==(
const QgsSfcgalGeometry &other )
const
252#if SFCGAL_VERSION_NUM < SFCGAL_MAKE_VERSION( 2, 1, 0 )
254 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.1 or later" ) );
259#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
260 if ( mIsPrimitive != other.mIsPrimitive )
265 out = QgsSfcgalEngine::primitiveIsEqual( mSfcgalPrim.get(), other.mSfcgalPrim.get(), -1.0, &errorMsg );
270 out = QgsSfcgalEngine::isEqual( mSfcgalGeom.get(), other.mSfcgalGeom.get(), -1.0, &errorMsg );
272 THROW_ON_ERROR( &errorMsg );
277bool QgsSfcgalGeometry::operator!=(
const QgsSfcgalGeometry &other )
const
279 return !( *
this == other );
282bool QgsSfcgalGeometry::fuzzyEqual(
const QgsSfcgalGeometry &other,
double epsilon )
const
285 sfcgal::errorHandler()->clearText( &errorMsg );
289#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
290 if ( mIsPrimitive != other.mIsPrimitive )
295 out = QgsSfcgalEngine::primitiveIsEqual( mSfcgalPrim.get(), other.mSfcgalPrim.get(), epsilon, &errorMsg );
300 out = QgsSfcgalEngine::isEqual( mSfcgalGeom.get(), other.mSfcgalGeom.get(), epsilon, &errorMsg );
303 THROW_ON_ERROR( &errorMsg );
307int QgsSfcgalGeometry::dimension()
const
310 sfcgal::errorHandler()->clearText( &errorMsg );
315 int result = QgsSfcgalEngine::dimension( mSfcgalGeom.get(), &errorMsg );
316 THROW_ON_ERROR( &errorMsg );
321std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::fromWkt(
const QString &wkt )
325 sfcgal::shared_geom sfcgalGeom = QgsSfcgalEngine::fromWkt( wkt, &errorMsg );
326 THROW_ON_ERROR( &errorMsg );
328 return std::make_unique<QgsSfcgalGeometry>( sfcgalGeom );
331int QgsSfcgalGeometry::partCount()
const
334 sfcgal::errorHandler()->clearText( &errorMsg );
339 int out = QgsSfcgalEngine::partCount( mSfcgalGeom.get(), &errorMsg );
340 THROW_ON_ERROR( &errorMsg );
345bool QgsSfcgalGeometry::addZValue(
double zValue )
348 sfcgal::errorHandler()->clearText( &errorMsg );
353 const bool added = QgsSfcgalEngine::addZValue( mSfcgalGeom.get(), zValue, &errorMsg );
354 THROW_ON_ERROR( &errorMsg );
361bool QgsSfcgalGeometry::addMValue(
double mValue )
364 sfcgal::errorHandler()->clearText( &errorMsg );
369 const bool added = QgsSfcgalEngine::addMValue( mSfcgalGeom.get(), mValue, &errorMsg );
370 THROW_ON_ERROR( &errorMsg );
377bool QgsSfcgalGeometry::dropZValue()
380 sfcgal::errorHandler()->clearText( &errorMsg );
385 const bool dropped = QgsSfcgalEngine::dropZValue( mSfcgalGeom.get(), &errorMsg );
386 THROW_ON_ERROR( &errorMsg );
393bool QgsSfcgalGeometry::dropMValue()
396 sfcgal::errorHandler()->clearText( &errorMsg );
401 const bool dropped = QgsSfcgalEngine::dropMValue( mSfcgalGeom.get(), &errorMsg );
402 THROW_ON_ERROR( &errorMsg );
409void QgsSfcgalGeometry::swapXy()
412 sfcgal::errorHandler()->clearText( &errorMsg );
417 QgsSfcgalEngine::swapXy( mSfcgalGeom.get(), &errorMsg );
418 THROW_ON_ERROR( &errorMsg );
423bool QgsSfcgalGeometry::isValid()
const
426 sfcgal::errorHandler()->clearText( &errorMsg );
431 const bool valid = QgsSfcgalEngine::isValid( mSfcgalGeom.get(), &errorMsg,
nullptr );
432 THROW_ON_ERROR( &errorMsg );
436void QgsSfcgalGeometry::clearCache()
const
440bool QgsSfcgalGeometry::isSimple()
const
443 sfcgal::errorHandler()->clearText( &errorMsg );
448 bool result = QgsSfcgalEngine::isSimple( mSfcgalGeom.get(), &errorMsg );
449 THROW_ON_ERROR( &errorMsg );
453QgsPoint QgsSfcgalGeometry::centroid()
const
456 sfcgal::errorHandler()->clearText( &errorMsg );
458 sfcgal::shared_geom geom = workingGeom();
459 return QgsSfcgalEngine::centroid( geom.get(), &errorMsg );
462bool QgsSfcgalGeometry::isEmpty()
const
465 sfcgal::errorHandler()->clearText( &errorMsg );
470 bool result = QgsSfcgalEngine::isEmpty( mSfcgalGeom.get(), &errorMsg );
471 THROW_ON_ERROR( &errorMsg );
476std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::translate(
const QgsVector3D &translation )
const
479 sfcgal::errorHandler()->clearText( &errorMsg );
481 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
482#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
485 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
486 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
487 resultGeom->setPrimitiveTranslate( translation );
492 sfcgal::shared_geom result = QgsSfcgalEngine::translate( mSfcgalGeom.get(), translation, &errorMsg );
493 THROW_ON_ERROR( &errorMsg );
494 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
497 THROW_ON_ERROR( &errorMsg );
501std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::scale(
const QgsVector3D &scaleFactor,
const QgsPoint ¢er )
const
504 sfcgal::errorHandler()->clearText( &errorMsg );
506 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
507#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
510 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
511 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
512 resultGeom->setPrimitiveScale( scaleFactor, center );
517 sfcgal::shared_geom result = QgsSfcgalEngine::scale( mSfcgalGeom.get(), scaleFactor, center, &errorMsg );
518 THROW_ON_ERROR( &errorMsg );
519 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
522 THROW_ON_ERROR( &errorMsg );
526std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate2D(
double angle,
const QgsPoint ¢er )
const
529 sfcgal::errorHandler()->clearText( &errorMsg );
531 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
532#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
535 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
536 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
537 resultGeom->setPrimitiveRotation( angle, { 0.0, 0.0, 1.0 }, center );
542 sfcgal::shared_geom result = QgsSfcgalEngine::rotate2D( mSfcgalGeom.get(), angle, center, &errorMsg );
543 THROW_ON_ERROR( &errorMsg );
545 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
548 THROW_ON_ERROR( &errorMsg );
552std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::transform(
const QMatrix4x4 &mat )
const
555 sfcgal::errorHandler()->clearText( &errorMsg );
557#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
558 sfcgal::shared_geom geom = workingGeom();
560 sfcgal::shared_geom result = QgsSfcgalEngine::transform( geom.get(), mat );
561 THROW_ON_ERROR( &errorMsg );
563 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
564 THROW_ON_ERROR( &errorMsg );
568 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
572std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate3D(
double angle,
const QgsVector3D &axisVector,
const QgsPoint ¢er )
const
575 sfcgal::errorHandler()->clearText( &errorMsg );
577 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
578#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
581 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
582 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
583 resultGeom->setPrimitiveRotation( angle, axisVector, center );
588 sfcgal::shared_geom result = QgsSfcgalEngine::rotate3D( mSfcgalGeom.get(), angle, axisVector, center, &errorMsg );
589 THROW_ON_ERROR( &errorMsg );
591 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
594 THROW_ON_ERROR( &errorMsg );
598double QgsSfcgalGeometry::area(
bool withDiscretization )
const
601 sfcgal::errorHandler()->clearText( &errorMsg );
604#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
607 result = QgsSfcgalEngine::primitiveArea( mSfcgalPrim.get(), withDiscretization, &errorMsg );
612 ( void ) withDiscretization;
613 result = QgsSfcgalEngine::area( mSfcgalGeom.get(), &errorMsg );
616 THROW_ON_ERROR( &errorMsg );
620double QgsSfcgalGeometry::length()
const
623 sfcgal::errorHandler()->clearText( &errorMsg );
628 double result = QgsSfcgalEngine::length( mSfcgalGeom.get(), &errorMsg );
629 THROW_ON_ERROR( &errorMsg );
634double QgsSfcgalGeometry::volume(
bool withDiscretization )
const
637 sfcgal::errorHandler()->clearText( &errorMsg );
643#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
644 result = QgsSfcgalEngine::primitiveVolume( mSfcgalPrim.get(), withDiscretization, &errorMsg );
646 ( void ) withDiscretization;
647 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
650 THROW_ON_ERROR( &errorMsg );
657 sfcgal::errorHandler()->clearText( &errorMsg );
658 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
659 THROW_ON_ERROR( &errorMsg );
661 sfcgal::shared_geom geom = workingGeom();
662 bool out = QgsSfcgalEngine::intersects( geom.get(), otherShared.get(), &errorMsg );
663 THROW_ON_ERROR( &errorMsg );
667bool QgsSfcgalGeometry::intersects(
const QgsSfcgalGeometry &otherGeom )
const
670 sfcgal::errorHandler()->clearText( &errorMsg );
672 sfcgal::shared_geom geom = workingGeom();
673 bool out = QgsSfcgalEngine::intersects( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
674 THROW_ON_ERROR( &errorMsg );
678std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection(
const QgsAbstractGeometry *otherGeom )
const
681 sfcgal::errorHandler()->clearText( &errorMsg );
682 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
683 THROW_ON_ERROR( &errorMsg );
685 sfcgal::shared_geom geom = workingGeom();
686 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherShared.get(), &errorMsg );
687 THROW_ON_ERROR( &errorMsg );
689 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
690 THROW_ON_ERROR( &errorMsg );
694std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection(
const QgsSfcgalGeometry &otherGeom )
const
697 sfcgal::errorHandler()->clearText( &errorMsg );
699 sfcgal::shared_geom geom = workingGeom();
700 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
701 THROW_ON_ERROR( &errorMsg );
703 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
704 THROW_ON_ERROR( &errorMsg );
708std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::combine(
const QVector<QgsAbstractGeometry *> &geomList )
const
711 sfcgal::errorHandler()->clearText( &errorMsg );
712 QVector<sfcgal::shared_geom> sfcgalGeomList;
714 sfcgal::shared_geom geom = workingGeom();
715 sfcgalGeomList.append( geom );
716 for ( QVector<QgsAbstractGeometry *>::const_iterator ite = geomList.constBegin(); ite != geomList.constEnd(); ++ite )
718 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( *ite, &errorMsg );
719 THROW_ON_ERROR( &errorMsg );
720 sfcgalGeomList.append( otherShared );
723 sfcgal::shared_geom result = QgsSfcgalEngine::combine( sfcgalGeomList, &errorMsg );
724 THROW_ON_ERROR( &errorMsg );
726 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
727 THROW_ON_ERROR( &errorMsg );
731std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference(
const QgsAbstractGeometry *otherGeom )
const
734 sfcgal::errorHandler()->clearText( &errorMsg );
735 sfcgal::shared_geom otherSharedr = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
736 THROW_ON_ERROR( &errorMsg );
738 sfcgal::shared_geom geom = workingGeom();
739 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherSharedr.get(), &errorMsg );
740 THROW_ON_ERROR( &errorMsg );
742 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
743 THROW_ON_ERROR( &errorMsg );
747std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference(
const QgsSfcgalGeometry &otherGeom )
const
750 sfcgal::errorHandler()->clearText( &errorMsg );
752 sfcgal::shared_geom geom = workingGeom();
753 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
754 THROW_ON_ERROR( &errorMsg );
756 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
757 THROW_ON_ERROR( &errorMsg );
761std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::triangulate()
const
764 sfcgal::errorHandler()->clearText( &errorMsg );
766 sfcgal::shared_geom geom = workingGeom();
767 sfcgal::shared_geom result = QgsSfcgalEngine::triangulate( geom.get(), &errorMsg );
768 THROW_ON_ERROR( &errorMsg );
770 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
771 THROW_ON_ERROR( &errorMsg );
775std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::convexHull()
const
778 sfcgal::errorHandler()->clearText( &errorMsg );
780 sfcgal::shared_geom geom = workingGeom();
781 sfcgal::shared_geom result = QgsSfcgalEngine::convexHull( geom.get(), &errorMsg );
782 THROW_ON_ERROR( &errorMsg );
784 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
785 THROW_ON_ERROR( &errorMsg );
789std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::envelope()
const
792 sfcgal::errorHandler()->clearText( &errorMsg );
794 sfcgal::shared_geom geom = workingGeom();
795 sfcgal::shared_geom result = QgsSfcgalEngine::envelope( geom.get(), &errorMsg );
796 THROW_ON_ERROR( &errorMsg );
798 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
799 THROW_ON_ERROR( &errorMsg );
803bool QgsSfcgalGeometry::covers(
const QgsSfcgalGeometry &otherGeom )
const
806 sfcgal::errorHandler()->clearText( &errorMsg );
808 sfcgal::shared_geom geom = workingGeom();
809 bool out = QgsSfcgalEngine::covers( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
810 THROW_ON_ERROR( &errorMsg );
814std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer3D(
double radius,
int segments,
Qgis::JoinStyle3D joinStyle3D )
const
817 sfcgal::errorHandler()->clearText( &errorMsg );
819 sfcgal::shared_geom geom = workingGeom();
820 sfcgal::shared_geom result = QgsSfcgalEngine::buffer3D( geom.get(), radius, segments, joinStyle3D, &errorMsg );
821 THROW_ON_ERROR( &errorMsg );
823 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
824 THROW_ON_ERROR( &errorMsg );
828std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer2D(
double radius,
int segments,
Qgis::JoinStyle joinStyle )
const
831 sfcgal::errorHandler()->clearText( &errorMsg );
833 sfcgal::shared_geom geom = workingGeom();
834 sfcgal::shared_geom result = QgsSfcgalEngine::buffer2D( geom.get(), radius, segments, joinStyle, &errorMsg );
835 THROW_ON_ERROR( &errorMsg );
837 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
838 THROW_ON_ERROR( &errorMsg );
842std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::simplify(
double tolerance,
bool preserveTopology )
const
845 sfcgal::errorHandler()->clearText( &errorMsg );
847 sfcgal::shared_geom geom = workingGeom();
848 sfcgal::shared_geom result = QgsSfcgalEngine::simplify( geom.get(), tolerance, preserveTopology, &errorMsg );
849 THROW_ON_ERROR( &errorMsg );
851 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
852 THROW_ON_ERROR( &errorMsg );
856std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::extrude(
const QgsVector3D &extrusion )
const
859 sfcgal::errorHandler()->clearText( &errorMsg );
861 sfcgal::shared_geom geom = workingGeom();
862 sfcgal::shared_geom result = QgsSfcgalEngine::extrude( geom.get(), extrusion, &errorMsg );
863 THROW_ON_ERROR( &errorMsg );
865 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
866 THROW_ON_ERROR( &errorMsg );
870std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::approximateMedialAxis()
const
873 sfcgal::errorHandler()->clearText( &errorMsg );
875 sfcgal::shared_geom geom = workingGeom();
876 sfcgal::shared_geom result = QgsSfcgalEngine::approximateMedialAxis( geom.get(), &errorMsg );
877 THROW_ON_ERROR( &errorMsg );
879 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
880 THROW_ON_ERROR( &errorMsg );
884std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCube(
double size )
886#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
888 sfcgal::errorHandler()->clearText( &errorMsg );
889 sfcgal::shared_prim result = QgsSfcgalEngine::createCube( size, &errorMsg );
890 THROW_ON_ERROR( &errorMsg );
892 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CUBE, &errorMsg );
893 THROW_ON_ERROR( &errorMsg );
897 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
901std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::primitiveAsPolyhedralSurface()
const
903#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
908 sfcgal::errorHandler()->clearText( &errorMsg );
909 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), mPrimTransform, &errorMsg );
910 THROW_ON_ERROR( &errorMsg );
912 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
913 THROW_ON_ERROR( &errorMsg );
916 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
920QMatrix4x4 QgsSfcgalGeometry::primitiveTransform()
const
922#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
926 return mPrimTransform;
928 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
932QList<std::pair<QString, QString>> QgsSfcgalGeometry::primitiveParameters()
const
934#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
939 sfcgal::errorHandler()->clearText( &errorMsg );
940 QVector<sfcgal::PrimitiveParameterDesc> result = QgsSfcgalEngine::primitiveParameters( mSfcgalPrim.get(), &errorMsg );
941 THROW_ON_ERROR( &errorMsg );
943 QList<QPair<QString, QString>> out;
944 for (
const auto ¶m : result )
946 out.append( std::pair<QString, QString>( QString::fromStdString( param.name ), QString::fromStdString( param.type ) ) );
951 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
955QVariant QgsSfcgalGeometry::primitiveParameter(
const QString &name )
const
957#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
962 sfcgal::errorHandler()->clearText( &errorMsg );
963 QVariant result = QgsSfcgalEngine::primitiveParameter( mSfcgalPrim.get(), name, &errorMsg );
964 THROW_ON_ERROR( &errorMsg );
969 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
973void QgsSfcgalGeometry::primitiveSetParameter(
const QString &name,
const QVariant &value )
975#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
980 sfcgal::errorHandler()->clearText( &errorMsg );
981 QgsSfcgalEngine::primitiveSetParameter( mSfcgalPrim.get(), name, value, &errorMsg );
982 THROW_ON_ERROR( &errorMsg );
987 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
992#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
993void QgsSfcgalGeometry::setPrimitiveTranslate(
const QgsVector3D &translation )
995 mPrimTransform.translate( mPrimTransform.column( 3 ).toVector3D() + translation.
toVector3D() );
998void QgsSfcgalGeometry::setPrimitiveScale(
const QgsVector3D &scaleFactor,
const QgsPoint ¢er )
1000 QVector3D qCenter( center.
x(), center.
y(), center.
z() );
1001 QVector3D prevTrans = mPrimTransform.column( 3 ).toVector3D();
1002 mPrimTransform.translate( prevTrans - qCenter );
1003 mPrimTransform.scale( scaleFactor.
toVector3D() );
1004 mPrimTransform.translate( prevTrans + qCenter );
1007void QgsSfcgalGeometry::setPrimitiveRotation(
double angle,
const QgsVector3D &axisVector,
const QgsPoint ¢er )
1009 QVector3D qCenter( center.
x(), center.
y(), center.
z() );
1010 QVector3D prevTrans = mPrimTransform.column( 3 ).toVector3D();
1011 mPrimTransform.translate( prevTrans - qCenter );
1013 mPrimTransform.rotate( QQuaternion::fromAxisAndAngle( axisVector.
toVector3D(), angle ) );
1014 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.
Custom exception class for SfCGAL related operations.
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.