22using namespace Qt::StringLiterals;
33QgsSfcgalGeometry::QgsSfcgalGeometry()
34 : mIsPrimitive( false )
38 : mIsPrimitive( false )
43 sfcgal::errorHandler()->clearText( &errorMsg );
44 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( qgsGeom, &errorMsg );
45 THROW_ON_ERROR( &errorMsg );
50 : mIsPrimitive( false )
53 sfcgal::errorHandler()->clearText( &errorMsg );
54 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( &qgsGeom, &errorMsg );
55 THROW_ON_ERROR( &errorMsg );
58QgsSfcgalGeometry::QgsSfcgalGeometry( sfcgal::shared_geom sfcgalGeom )
59 : mSfcgalGeom( sfcgalGeom )
60 , mIsPrimitive( false )
63QgsSfcgalGeometry::QgsSfcgalGeometry( sfcgal::shared_prim sfcgalPrim, sfcgal::primitiveType type )
64 : mIsPrimitive( true )
66#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
67 mSfcgalPrim = sfcgalPrim;
72 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
76QgsSfcgalGeometry::QgsSfcgalGeometry(
const QgsGeometry &qgsGeom )
79 sfcgal::errorHandler()->clearText( &errorMsg );
80 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( qgsGeom.
constGet(), &errorMsg );
81 THROW_ON_ERROR( &errorMsg );
84QgsSfcgalGeometry::QgsSfcgalGeometry(
const QgsSfcgalGeometry &otherGeom )
87 sfcgal::errorHandler()->clearText( &errorMsg );
88 mIsPrimitive = otherGeom.mIsPrimitive;
89#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
90 mPrimType = otherGeom.mPrimType;
92 mSfcgalPrim = QgsSfcgalEngine::primitiveClone( otherGeom.mSfcgalPrim.get(), &errorMsg );
95 mSfcgalGeom = QgsSfcgalEngine::cloneGeometry( otherGeom.mSfcgalGeom.get(), &errorMsg );
96 THROW_ON_ERROR( &errorMsg );
99QgsSfcgalGeometry::QgsSfcgalGeometry(
const QString &wkt )
102 sfcgal::errorHandler()->clearText( &errorMsg );
103 mSfcgalGeom = QgsSfcgalEngine::fromWkt( wkt, &errorMsg );
104 THROW_ON_ERROR( &errorMsg );
107sfcgal::shared_geom QgsSfcgalGeometry::workingGeom()
const
109 sfcgal::shared_geom geom;
111#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
115 geom = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), &errorMsg );
116 THROW_ON_ERROR( &errorMsg );
129 sfcgal::errorHandler()->clearText( &errorMsg );
131#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
136 Qgis::WkbType out = QgsSfcgalEngine::wkbType( mSfcgalGeom.get(), &errorMsg );
137 THROW_ON_ERROR( &errorMsg );
141QString QgsSfcgalGeometry::geometryType()
const
144 sfcgal::errorHandler()->clearText( &errorMsg );
147#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
152 case sfcgal::primitiveType::SFCGAL_TYPE_CYLINDER:
155 case sfcgal::primitiveType::SFCGAL_TYPE_SPHERE:
158 case sfcgal::primitiveType::SFCGAL_TYPE_TORUS:
161 case sfcgal::primitiveType::SFCGAL_TYPE_BOX:
164 case sfcgal::primitiveType::SFCGAL_TYPE_CUBE:
167 case sfcgal::primitiveType::SFCGAL_TYPE_CONE:
171 sfcgal::errorHandler()->addText( u
"Type '%1' is unknown."_s.arg( mPrimType ) );
177 out = QgsSfcgalEngine::geometryType( mSfcgalGeom.get(), &errorMsg );
178 THROW_ON_ERROR( &errorMsg );
183std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::clone()
const
185 return std::make_unique<QgsSfcgalGeometry>( *
this );
188std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::fromWkb(
const QgsConstWkbPtr &wkbPtr )
196 sfcgal::shared_geom sfcgalGeom = QgsSfcgalEngine::fromWkb( wkbPtr, &errorMsg );
197 THROW_ON_ERROR( &errorMsg );
199 return std::make_unique<QgsSfcgalGeometry>( sfcgalGeom );
206 sfcgal::errorHandler()->clearText( &errorMsg );
208 sfcgal::shared_geom geom = workingGeom();
209 QByteArray wkbArray = QgsSfcgalEngine::toWkb( geom.get(), &errorMsg );
210 THROW_ON_ERROR( &errorMsg );
215QString QgsSfcgalGeometry::asWkt(
int precision )
const
218 sfcgal::errorHandler()->clearText( &errorMsg );
220 sfcgal::shared_geom geom = workingGeom();
221 QString out = QgsSfcgalEngine::toWkt( geom.get(), precision, &errorMsg );
222 THROW_ON_ERROR( &errorMsg );
227std::unique_ptr<QgsAbstractGeometry> QgsSfcgalGeometry::asQgisGeometry()
const
230 sfcgal::errorHandler()->clearText( &errorMsg );
232 sfcgal::shared_geom geom = workingGeom();
233 std::unique_ptr<QgsAbstractGeometry> out = QgsSfcgalEngine::toAbstractGeometry( geom.get(), &errorMsg );
234 THROW_ON_ERROR( &errorMsg );
238std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::boundary()
const
241 sfcgal::errorHandler()->clearText( &errorMsg );
243 sfcgal::shared_geom geom = workingGeom();
244 sfcgal::shared_geom boundary = QgsSfcgalEngine::boundary( geom.get(), &errorMsg );
245 THROW_ON_ERROR( &errorMsg );
247 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( boundary, &errorMsg );
248 THROW_ON_ERROR( &errorMsg );
252bool QgsSfcgalGeometry::operator==(
const QgsSfcgalGeometry &other )
const
254#if SFCGAL_VERSION_NUM < SFCGAL_COMPUTE_VERSION( 2, 1, 0 )
256 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.1 or later" ) );
259 sfcgal::errorHandler()->clearText( &errorMsg );
262#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
263 if ( mIsPrimitive != other.mIsPrimitive )
268 out = QgsSfcgalEngine::primitiveIsEqual( mSfcgalPrim.get(), other.mSfcgalPrim.get(), -1.0, &errorMsg );
273 out = QgsSfcgalEngine::isEqual( mSfcgalGeom.get(), other.mSfcgalGeom.get(), -1.0, &errorMsg );
275 THROW_ON_ERROR( &errorMsg );
280bool QgsSfcgalGeometry::operator!=(
const QgsSfcgalGeometry &other )
const
282 return !( *
this == other );
285bool QgsSfcgalGeometry::fuzzyEqual(
const QgsSfcgalGeometry &other,
double epsilon )
const
288 sfcgal::errorHandler()->clearText( &errorMsg );
292#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
293 if ( mIsPrimitive != other.mIsPrimitive )
298 out = QgsSfcgalEngine::primitiveIsEqual( mSfcgalPrim.get(), other.mSfcgalPrim.get(), epsilon, &errorMsg );
303 out = QgsSfcgalEngine::isEqual( mSfcgalGeom.get(), other.mSfcgalGeom.get(), epsilon, &errorMsg );
306 THROW_ON_ERROR( &errorMsg );
310int QgsSfcgalGeometry::dimension()
const
313 sfcgal::errorHandler()->clearText( &errorMsg );
318 int result = QgsSfcgalEngine::dimension( mSfcgalGeom.get(), &errorMsg );
319 THROW_ON_ERROR( &errorMsg );
324std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::fromWkt(
const QString &wkt )
328 sfcgal::shared_geom sfcgalGeom = QgsSfcgalEngine::fromWkt( wkt, &errorMsg );
329 THROW_ON_ERROR( &errorMsg );
331 return std::make_unique<QgsSfcgalGeometry>( sfcgalGeom );
334int QgsSfcgalGeometry::partCount()
const
337 sfcgal::errorHandler()->clearText( &errorMsg );
342 int out = QgsSfcgalEngine::partCount( mSfcgalGeom.get(), &errorMsg );
343 THROW_ON_ERROR( &errorMsg );
348bool QgsSfcgalGeometry::addZValue(
double zValue )
351 sfcgal::errorHandler()->clearText( &errorMsg );
356 const bool added = QgsSfcgalEngine::addZValue( mSfcgalGeom.get(), zValue, &errorMsg );
357 THROW_ON_ERROR( &errorMsg );
364bool QgsSfcgalGeometry::addMValue(
double mValue )
367 sfcgal::errorHandler()->clearText( &errorMsg );
372 const bool added = QgsSfcgalEngine::addMValue( mSfcgalGeom.get(), mValue, &errorMsg );
373 THROW_ON_ERROR( &errorMsg );
380bool QgsSfcgalGeometry::dropZValue()
383 sfcgal::errorHandler()->clearText( &errorMsg );
388 const bool dropped = QgsSfcgalEngine::dropZValue( mSfcgalGeom.get(), &errorMsg );
389 THROW_ON_ERROR( &errorMsg );
396bool QgsSfcgalGeometry::dropMValue()
399 sfcgal::errorHandler()->clearText( &errorMsg );
404 const bool dropped = QgsSfcgalEngine::dropMValue( mSfcgalGeom.get(), &errorMsg );
405 THROW_ON_ERROR( &errorMsg );
412void QgsSfcgalGeometry::swapXy()
415 sfcgal::errorHandler()->clearText( &errorMsg );
420 QgsSfcgalEngine::swapXy( mSfcgalGeom.get(), &errorMsg );
421 THROW_ON_ERROR( &errorMsg );
426bool QgsSfcgalGeometry::isValid()
const
429 sfcgal::errorHandler()->clearText( &errorMsg );
434 const bool valid = QgsSfcgalEngine::isValid( mSfcgalGeom.get(), &errorMsg,
nullptr );
435 THROW_ON_ERROR( &errorMsg );
439void QgsSfcgalGeometry::clearCache()
const
442bool QgsSfcgalGeometry::isSimple()
const
445 sfcgal::errorHandler()->clearText( &errorMsg );
450 bool result = QgsSfcgalEngine::isSimple( mSfcgalGeom.get(), &errorMsg );
451 THROW_ON_ERROR( &errorMsg );
455std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::geometryN(
unsigned int index )
const
458 sfcgal::errorHandler()->clearText( &errorMsg );
460 sfcgal::shared_geom geom = workingGeom();
461 sfcgal::shared_geom result = QgsSfcgalEngine::geometryN( geom.get(), index );
462 THROW_ON_ERROR( &errorMsg );
464 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
465 THROW_ON_ERROR( &errorMsg );
469QgsPoint QgsSfcgalGeometry::centroid()
const
472 sfcgal::errorHandler()->clearText( &errorMsg );
474 sfcgal::shared_geom geom = workingGeom();
475 return QgsSfcgalEngine::centroid( geom.get(), &errorMsg );
478bool QgsSfcgalGeometry::isEmpty()
const
481 sfcgal::errorHandler()->clearText( &errorMsg );
486 bool result = QgsSfcgalEngine::isEmpty( mSfcgalGeom.get(), &errorMsg );
487 THROW_ON_ERROR( &errorMsg );
492std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::translate(
const QgsVector3D &translation )
const
495 sfcgal::errorHandler()->clearText( &errorMsg );
497 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
498#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
501 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveTranslate( mSfcgalPrim.get(), translation, &errorMsg );
502 THROW_ON_ERROR( &errorMsg );
503 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, mPrimType, &errorMsg );
508 sfcgal::shared_geom result = QgsSfcgalEngine::translate( mSfcgalGeom.get(), translation, &errorMsg );
509 THROW_ON_ERROR( &errorMsg );
510 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
513 THROW_ON_ERROR( &errorMsg );
517std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::scale(
const QgsVector3D &scaleFactor,
const QgsPoint ¢er )
const
520 sfcgal::errorHandler()->clearText( &errorMsg );
522 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
523#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
526 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveScale( mSfcgalPrim.get(), scaleFactor, center, &errorMsg );
527 THROW_ON_ERROR( &errorMsg );
528 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, mPrimType, &errorMsg );
533 sfcgal::shared_geom result = QgsSfcgalEngine::scale( mSfcgalGeom.get(), scaleFactor, center, &errorMsg );
534 THROW_ON_ERROR( &errorMsg );
535 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
538 THROW_ON_ERROR( &errorMsg );
542std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate2D(
double angle,
const QgsPoint ¢er )
const
545 sfcgal::errorHandler()->clearText( &errorMsg );
547 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
548#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
551 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveRotate( mSfcgalPrim.get(), angle, { 0.0, 0.0, 1.0 }, center, &errorMsg );
552 THROW_ON_ERROR( &errorMsg );
553 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, mPrimType, &errorMsg );
554 THROW_ON_ERROR( &errorMsg );
560 sfcgal::shared_geom result = QgsSfcgalEngine::rotate2D( mSfcgalGeom.get(), angle, center, &errorMsg );
561 THROW_ON_ERROR( &errorMsg );
563 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
566 THROW_ON_ERROR( &errorMsg );
570std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::transform(
const QgsMatrix4x4 &mat )
const
573 sfcgal::errorHandler()->clearText( &errorMsg );
575#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
576 sfcgal::shared_geom geom = workingGeom();
578 sfcgal::shared_geom result = QgsSfcgalEngine::transform( geom.get(), mat );
579 THROW_ON_ERROR( &errorMsg );
581 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
582 THROW_ON_ERROR( &errorMsg );
586 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
590std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate3D(
double angle,
const QgsVector3D &axisVector,
const QgsPoint ¢er )
const
593 sfcgal::errorHandler()->clearText( &errorMsg );
595 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
596#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
599 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveRotate( mSfcgalPrim.get(), angle, axisVector, center, &errorMsg );
600 THROW_ON_ERROR( &errorMsg );
601 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, mPrimType, &errorMsg );
606 sfcgal::shared_geom result = QgsSfcgalEngine::rotate3D( mSfcgalGeom.get(), angle, axisVector, center, &errorMsg );
607 THROW_ON_ERROR( &errorMsg );
609 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
612 THROW_ON_ERROR( &errorMsg );
616double QgsSfcgalGeometry::area(
bool withDiscretization )
const
619 sfcgal::errorHandler()->clearText( &errorMsg );
622#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
625 result = QgsSfcgalEngine::primitiveArea( mSfcgalPrim.get(), withDiscretization, &errorMsg );
630 ( void ) withDiscretization;
631 result = QgsSfcgalEngine::area( mSfcgalGeom.get(), &errorMsg );
634 THROW_ON_ERROR( &errorMsg );
638double QgsSfcgalGeometry::length()
const
641 sfcgal::errorHandler()->clearText( &errorMsg );
646 double result = QgsSfcgalEngine::length( mSfcgalGeom.get(), &errorMsg );
647 THROW_ON_ERROR( &errorMsg );
652double QgsSfcgalGeometry::volume(
bool withDiscretization )
const
655 sfcgal::errorHandler()->clearText( &errorMsg );
661#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
662 result = QgsSfcgalEngine::primitiveVolume( mSfcgalPrim.get(), withDiscretization, &errorMsg );
664 ( void ) withDiscretization;
665 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
668 THROW_ON_ERROR( &errorMsg );
675 sfcgal::errorHandler()->clearText( &errorMsg );
676 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
677 THROW_ON_ERROR( &errorMsg );
679 sfcgal::shared_geom geom = workingGeom();
680 bool out = QgsSfcgalEngine::intersects( geom.get(), otherShared.get(), &errorMsg );
681 THROW_ON_ERROR( &errorMsg );
685bool QgsSfcgalGeometry::intersects(
const QgsSfcgalGeometry &otherGeom )
const
688 sfcgal::errorHandler()->clearText( &errorMsg );
690 sfcgal::shared_geom geom = workingGeom();
691 bool out = QgsSfcgalEngine::intersects( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
692 THROW_ON_ERROR( &errorMsg );
696std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection(
const QgsAbstractGeometry *otherGeom )
const
699 sfcgal::errorHandler()->clearText( &errorMsg );
700 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
701 THROW_ON_ERROR( &errorMsg );
703 sfcgal::shared_geom geom = workingGeom();
704 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherShared.get(), &errorMsg );
705 THROW_ON_ERROR( &errorMsg );
707 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
708 THROW_ON_ERROR( &errorMsg );
712std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection(
const QgsSfcgalGeometry &otherGeom )
const
715 sfcgal::errorHandler()->clearText( &errorMsg );
717 sfcgal::shared_geom geom = workingGeom();
718 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
719 THROW_ON_ERROR( &errorMsg );
721 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
722 THROW_ON_ERROR( &errorMsg );
726std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::combine(
const QVector<QgsAbstractGeometry *> &geomList )
const
729 sfcgal::errorHandler()->clearText( &errorMsg );
730 QVector<sfcgal::shared_geom> sfcgalGeomList;
732 sfcgal::shared_geom geom = workingGeom();
733 sfcgalGeomList.append( geom );
734 for ( QVector<QgsAbstractGeometry *>::const_iterator ite = geomList.constBegin(); ite != geomList.constEnd(); ++ite )
736 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( *ite, &errorMsg );
737 THROW_ON_ERROR( &errorMsg );
738 sfcgalGeomList.append( otherShared );
741 sfcgal::shared_geom result = QgsSfcgalEngine::combine( sfcgalGeomList, &errorMsg );
742 THROW_ON_ERROR( &errorMsg );
744 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
745 THROW_ON_ERROR( &errorMsg );
749std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference(
const QgsAbstractGeometry *otherGeom )
const
752 sfcgal::errorHandler()->clearText( &errorMsg );
753 sfcgal::shared_geom otherSharedr = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
754 THROW_ON_ERROR( &errorMsg );
756 sfcgal::shared_geom geom = workingGeom();
757 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherSharedr.get(), &errorMsg );
758 THROW_ON_ERROR( &errorMsg );
760 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
761 THROW_ON_ERROR( &errorMsg );
765std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference(
const QgsSfcgalGeometry &otherGeom )
const
768 sfcgal::errorHandler()->clearText( &errorMsg );
770 sfcgal::shared_geom geom = workingGeom();
771 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
772 THROW_ON_ERROR( &errorMsg );
774 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
775 THROW_ON_ERROR( &errorMsg );
779std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::triangulate()
const
782 sfcgal::errorHandler()->clearText( &errorMsg );
784 sfcgal::shared_geom geom = workingGeom();
785 sfcgal::shared_geom result = QgsSfcgalEngine::triangulate( geom.get(), &errorMsg );
786 THROW_ON_ERROR( &errorMsg );
788 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
789 THROW_ON_ERROR( &errorMsg );
793std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::convexHull()
const
796 sfcgal::errorHandler()->clearText( &errorMsg );
798 sfcgal::shared_geom geom = workingGeom();
799 sfcgal::shared_geom result = QgsSfcgalEngine::convexHull( geom.get(), &errorMsg );
800 THROW_ON_ERROR( &errorMsg );
802 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
803 THROW_ON_ERROR( &errorMsg );
807std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::envelope()
const
810 sfcgal::errorHandler()->clearText( &errorMsg );
812 sfcgal::shared_geom geom = workingGeom();
813 sfcgal::shared_geom result = QgsSfcgalEngine::envelope( geom.get(), &errorMsg );
814 THROW_ON_ERROR( &errorMsg );
816 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
817 THROW_ON_ERROR( &errorMsg );
821bool QgsSfcgalGeometry::covers(
const QgsSfcgalGeometry &otherGeom )
const
824 sfcgal::errorHandler()->clearText( &errorMsg );
826 sfcgal::shared_geom geom = workingGeom();
827 bool out = QgsSfcgalEngine::covers( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
828 THROW_ON_ERROR( &errorMsg );
832std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer3D(
double radius,
int segments,
Qgis::JoinStyle3D joinStyle3D )
const
835 sfcgal::errorHandler()->clearText( &errorMsg );
837 sfcgal::shared_geom geom = workingGeom();
838 sfcgal::shared_geom result = QgsSfcgalEngine::buffer3D( geom.get(), radius, segments, joinStyle3D, &errorMsg );
839 THROW_ON_ERROR( &errorMsg );
841 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
842 THROW_ON_ERROR( &errorMsg );
846std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer2D(
double radius,
int segments,
Qgis::JoinStyle joinStyle )
const
849 sfcgal::errorHandler()->clearText( &errorMsg );
851 sfcgal::shared_geom geom = workingGeom();
852 sfcgal::shared_geom result = QgsSfcgalEngine::buffer2D( geom.get(), radius, segments, joinStyle, &errorMsg );
853 THROW_ON_ERROR( &errorMsg );
855 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
856 THROW_ON_ERROR( &errorMsg );
860std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::simplify(
double tolerance,
bool preserveTopology )
const
863 sfcgal::errorHandler()->clearText( &errorMsg );
865 sfcgal::shared_geom geom = workingGeom();
866 sfcgal::shared_geom result = QgsSfcgalEngine::simplify( geom.get(), tolerance, preserveTopology, &errorMsg );
867 THROW_ON_ERROR( &errorMsg );
869 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
870 THROW_ON_ERROR( &errorMsg );
874std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::extrude(
const QgsVector3D &extrusion )
const
877 sfcgal::errorHandler()->clearText( &errorMsg );
879 sfcgal::shared_geom geom = workingGeom();
880 sfcgal::shared_geom result = QgsSfcgalEngine::extrude( geom.get(), extrusion, &errorMsg );
881 THROW_ON_ERROR( &errorMsg );
883 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
884 THROW_ON_ERROR( &errorMsg );
888std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::approximateMedialAxis(
bool extendToEdges )
const
891 sfcgal::errorHandler()->clearText( &errorMsg );
893 sfcgal::shared_geom geom = workingGeom();
894 sfcgal::shared_geom result = QgsSfcgalEngine::approximateMedialAxis( geom.get(), extendToEdges, &errorMsg );
895 THROW_ON_ERROR( &errorMsg );
897 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
898 THROW_ON_ERROR( &errorMsg );
902std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::toSolid()
const
905 sfcgal::errorHandler()->clearText( &errorMsg );
907 sfcgal::shared_geom geom = workingGeom();
908 sfcgal::shared_geom solid = QgsSfcgalEngine::toSolid( geom.get(), &errorMsg );
909 THROW_ON_ERROR( &errorMsg );
911 std::unique_ptr<QgsSfcgalGeometry> solidGeom = QgsSfcgalEngine::toSfcgalGeometry( solid, &errorMsg );
912 THROW_ON_ERROR( &errorMsg );
916std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::split3D(
const QgsPoint &planePoint,
const QgsVector3D &planeNormal,
bool closeGeometries )
const
919 sfcgal::errorHandler()->clearText( &errorMsg );
921#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
922 sfcgal::shared_geom geom = workingGeom();
924 sfcgal::shared_geom result = QgsSfcgalEngine::split3D( geom.get(), planePoint, planeNormal, closeGeometries );
925 THROW_ON_ERROR( &errorMsg );
927 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
928 THROW_ON_ERROR( &errorMsg );
931 Q_UNUSED( planePoint )
932 Q_UNUSED( planeNormal )
933 Q_UNUSED( closeGeometries )
934 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
938std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::toPolyhedralSurface()
const
941 sfcgal::errorHandler()->clearText( &errorMsg );
943 sfcgal::shared_geom geom = workingGeom();
944 sfcgal::shared_geom phs = QgsSfcgalEngine::toPolyhedralSurface( geom.get(), &errorMsg );
945 THROW_ON_ERROR( &errorMsg );
947 std::unique_ptr<QgsSfcgalGeometry> phsGeom = QgsSfcgalEngine::toSfcgalGeometry( phs, &errorMsg );
948 THROW_ON_ERROR( &errorMsg );
952std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createBox(
double sizeX,
double sizeY,
double sizeZ )
954#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
956 sfcgal::errorHandler()->clearText( &errorMsg );
957 sfcgal::shared_prim result = QgsSfcgalEngine::createBox( sizeX, sizeY, sizeZ, &errorMsg );
958 THROW_ON_ERROR( &errorMsg );
960 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_BOX, &errorMsg );
961 THROW_ON_ERROR( &errorMsg );
967 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
971std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCone(
double bottomRadius,
double height,
double topRadius,
unsigned int radial )
973#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
975 sfcgal::errorHandler()->clearText( &errorMsg );
976 sfcgal::shared_prim result = QgsSfcgalEngine::createCone( bottomRadius, height, topRadius, radial, &errorMsg );
977 THROW_ON_ERROR( &errorMsg );
979 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CONE, &errorMsg );
980 THROW_ON_ERROR( &errorMsg );
983 ( void ) bottomRadius;
987 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
991std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCube(
double size )
993#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
995 sfcgal::errorHandler()->clearText( &errorMsg );
996 sfcgal::shared_prim result = QgsSfcgalEngine::createCube( size, &errorMsg );
997 THROW_ON_ERROR( &errorMsg );
999 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CUBE, &errorMsg );
1000 THROW_ON_ERROR( &errorMsg );
1004 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1008std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCylinder(
double radius,
double height,
unsigned int radial )
1010#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1012 sfcgal::errorHandler()->clearText( &errorMsg );
1013 sfcgal::shared_prim result = QgsSfcgalEngine::createCylinder( radius, height, radial, &errorMsg );
1014 THROW_ON_ERROR( &errorMsg );
1016 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CYLINDER, &errorMsg );
1017 THROW_ON_ERROR( &errorMsg );
1023 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1027std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createSphere(
double radius,
unsigned int subdivisions )
1029#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1031 sfcgal::errorHandler()->clearText( &errorMsg );
1032 sfcgal::shared_prim result = QgsSfcgalEngine::createSphere( radius, subdivisions, &errorMsg );
1033 THROW_ON_ERROR( &errorMsg );
1035 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_SPHERE, &errorMsg );
1036 THROW_ON_ERROR( &errorMsg );
1040 ( void ) subdivisions;
1041 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1045std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createTorus(
double mainRadius,
double tubeRadius,
unsigned int mainRadial,
unsigned int tubeRadial )
1047#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1049 sfcgal::errorHandler()->clearText( &errorMsg );
1050 sfcgal::shared_prim result = QgsSfcgalEngine::createTorus( mainRadius, tubeRadius, mainRadial, tubeRadial, &errorMsg );
1051 THROW_ON_ERROR( &errorMsg );
1053 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_TORUS, &errorMsg );
1054 THROW_ON_ERROR( &errorMsg );
1057 ( void ) mainRadius;
1058 ( void ) tubeRadius;
1059 ( void ) mainRadial;
1060 ( void ) tubeRadial;
1061 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1065std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::primitiveAsPolyhedralSurface()
const
1067#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1068 if ( !mIsPrimitive )
1072 sfcgal::errorHandler()->clearText( &errorMsg );
1073 sfcgal::shared_geom result = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), &errorMsg );
1074 THROW_ON_ERROR( &errorMsg );
1076 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
1077 THROW_ON_ERROR( &errorMsg );
1080 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1084QgsMatrix4x4 QgsSfcgalGeometry::primitiveTransform()
const
1086#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1087 if ( !mIsPrimitive )
1093 sfcgal::errorHandler()->clearText( &errorMsg );
1094 double *data = sfcgal_primitive_transformation( mSfcgalPrim.get() );
1095 THROW_ON_ERROR( &errorMsg );
1101 data[0], data[4], data[8], data[12],
1102 data[1], data[5], data[9], data[13],
1103 data[2], data[6], data[10], data[14],
1104 data[3], data[7], data[11], data[15]
1107 sfcgal_free_buffer( data );
1108 return transformMatrix;
1110 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1114QList<std::pair<QString, QString>> QgsSfcgalGeometry::primitiveParameters()
const
1116#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1117 if ( !mIsPrimitive )
1121 sfcgal::errorHandler()->clearText( &errorMsg );
1122 QVector<sfcgal::PrimitiveParameterDesc> result = QgsSfcgalEngine::primitiveParameters( mSfcgalPrim.get(), &errorMsg );
1123 THROW_ON_ERROR( &errorMsg );
1125 QList<QPair<QString, QString>> out;
1126 for (
const auto ¶m : result )
1128 out.append( std::pair<QString, QString>( QString::fromStdString( param.name ), QString::fromStdString( param.type ) ) );
1133 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1137QVariant QgsSfcgalGeometry::primitiveParameter(
const QString &name )
const
1139#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1140 if ( !mIsPrimitive )
1144 sfcgal::errorHandler()->clearText( &errorMsg );
1145 QVariant result = QgsSfcgalEngine::primitiveParameter( mSfcgalPrim.get(), name, &errorMsg );
1146 THROW_ON_ERROR( &errorMsg );
1151 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1155void QgsSfcgalGeometry::primitiveSetParameter(
const QString &name,
const QVariant &value )
1157#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1158 if ( !mIsPrimitive )
1162 sfcgal::errorHandler()->clearText( &errorMsg );
1163 QgsSfcgalEngine::primitiveSetParameter( mSfcgalPrim.get(), name, value, &errorMsg );
1164 THROW_ON_ERROR( &errorMsg );
1169 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
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.
A simple 4x4 matrix implementation useful for transformation in 3D space.
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...