28using namespace Qt::StringLiterals;
30QgsSfcgalGeometry::QgsSfcgalGeometry()
31 : mIsPrimitive( false )
35 : mIsPrimitive( false )
40 sfcgal::errorHandler()->clearText( &errorMsg );
41 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( qgsGeom, &errorMsg );
42 THROW_ON_ERROR( &errorMsg );
47 : mIsPrimitive( false )
50 sfcgal::errorHandler()->clearText( &errorMsg );
51 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( &qgsGeom, &errorMsg );
52 THROW_ON_ERROR( &errorMsg );
55QgsSfcgalGeometry::QgsSfcgalGeometry( sfcgal::shared_geom sfcgalGeom )
56 : mSfcgalGeom( sfcgalGeom )
57 , mIsPrimitive( false )
60QgsSfcgalGeometry::QgsSfcgalGeometry( sfcgal::shared_prim sfcgalPrim, sfcgal::primitiveType type )
61 : mIsPrimitive( true )
63#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
64 mSfcgalPrim = sfcgalPrim;
69 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
73QgsSfcgalGeometry::QgsSfcgalGeometry(
const QgsGeometry &qgsGeom )
76 sfcgal::errorHandler()->clearText( &errorMsg );
77 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( qgsGeom.
constGet(), &errorMsg );
78 THROW_ON_ERROR( &errorMsg );
81QgsSfcgalGeometry::QgsSfcgalGeometry(
const QgsSfcgalGeometry &otherGeom )
84 sfcgal::errorHandler()->clearText( &errorMsg );
85 mIsPrimitive = otherGeom.mIsPrimitive;
86#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
87 mPrimType = otherGeom.mPrimType;
89 mSfcgalPrim = QgsSfcgalEngine::primitiveClone( otherGeom.mSfcgalPrim.get(), &errorMsg );
92 mSfcgalGeom = QgsSfcgalEngine::cloneGeometry( otherGeom.mSfcgalGeom.get(), &errorMsg );
93 THROW_ON_ERROR( &errorMsg );
96QgsSfcgalGeometry::QgsSfcgalGeometry(
const QString &wkt )
99 sfcgal::errorHandler()->clearText( &errorMsg );
100 mSfcgalGeom = QgsSfcgalEngine::fromWkt( wkt, &errorMsg );
101 THROW_ON_ERROR( &errorMsg );
104sfcgal::shared_geom QgsSfcgalGeometry::workingGeom()
const
106 sfcgal::shared_geom geom;
108#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
112 geom = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), &errorMsg );
113 THROW_ON_ERROR( &errorMsg );
126 sfcgal::errorHandler()->clearText( &errorMsg );
128#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
133 Qgis::WkbType out = QgsSfcgalEngine::wkbType( mSfcgalGeom.get(), &errorMsg );
134 THROW_ON_ERROR( &errorMsg );
138QString QgsSfcgalGeometry::geometryType()
const
141 sfcgal::errorHandler()->clearText( &errorMsg );
144#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
149 case sfcgal::primitiveType::SFCGAL_TYPE_CYLINDER:
152 case sfcgal::primitiveType::SFCGAL_TYPE_SPHERE:
155 case sfcgal::primitiveType::SFCGAL_TYPE_TORUS:
158 case sfcgal::primitiveType::SFCGAL_TYPE_BOX:
161 case sfcgal::primitiveType::SFCGAL_TYPE_CUBE:
164 case sfcgal::primitiveType::SFCGAL_TYPE_CONE:
168 sfcgal::errorHandler()->addText( u
"Type '%1' is unknown."_s.arg( mPrimType ) );
174 out = QgsSfcgalEngine::geometryType( mSfcgalGeom.get(), &errorMsg );
175 THROW_ON_ERROR( &errorMsg );
180std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::clone()
const
182 return std::make_unique<QgsSfcgalGeometry>( *
this );
185std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::fromWkb(
const QgsConstWkbPtr &wkbPtr )
193 sfcgal::shared_geom sfcgalGeom = QgsSfcgalEngine::fromWkb( wkbPtr, &errorMsg );
194 THROW_ON_ERROR( &errorMsg );
196 return std::make_unique<QgsSfcgalGeometry>( sfcgalGeom );
203 sfcgal::errorHandler()->clearText( &errorMsg );
205 sfcgal::shared_geom geom = workingGeom();
206 QByteArray wkbArray = QgsSfcgalEngine::toWkb( geom.get(), &errorMsg );
207 THROW_ON_ERROR( &errorMsg );
212QString QgsSfcgalGeometry::asWkt(
int precision )
const
215 sfcgal::errorHandler()->clearText( &errorMsg );
217 sfcgal::shared_geom geom = workingGeom();
218 QString out = QgsSfcgalEngine::toWkt( geom.get(), precision, &errorMsg );
219 THROW_ON_ERROR( &errorMsg );
224std::unique_ptr<QgsAbstractGeometry> QgsSfcgalGeometry::asQgisGeometry()
const
227 sfcgal::errorHandler()->clearText( &errorMsg );
229 sfcgal::shared_geom geom = workingGeom();
230 std::unique_ptr<QgsAbstractGeometry> out = QgsSfcgalEngine::toAbstractGeometry( geom.get(), &errorMsg );
231 THROW_ON_ERROR( &errorMsg );
235std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::boundary()
const
238 sfcgal::errorHandler()->clearText( &errorMsg );
240 sfcgal::shared_geom geom = workingGeom();
241 sfcgal::shared_geom boundary = QgsSfcgalEngine::boundary( geom.get(), &errorMsg );
242 THROW_ON_ERROR( &errorMsg );
244 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( boundary, &errorMsg );
245 THROW_ON_ERROR( &errorMsg );
249bool QgsSfcgalGeometry::operator==(
const QgsSfcgalGeometry &other )
const
251#if SFCGAL_VERSION_NUM < SFCGAL_MAKE_VERSION( 2, 1, 0 )
253 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.1 or later" ) );
256 sfcgal::errorHandler()->clearText( &errorMsg );
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
439bool QgsSfcgalGeometry::isSimple()
const
442 sfcgal::errorHandler()->clearText( &errorMsg );
447 bool result = QgsSfcgalEngine::isSimple( mSfcgalGeom.get(), &errorMsg );
448 THROW_ON_ERROR( &errorMsg );
452std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::geometryN(
unsigned int index )
const
455 sfcgal::errorHandler()->clearText( &errorMsg );
457 sfcgal::shared_geom geom = workingGeom();
458 sfcgal::shared_geom result = QgsSfcgalEngine::geometryN( geom.get(), index );
459 THROW_ON_ERROR( &errorMsg );
461 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
462 THROW_ON_ERROR( &errorMsg );
466QgsPoint QgsSfcgalGeometry::centroid()
const
469 sfcgal::errorHandler()->clearText( &errorMsg );
471 sfcgal::shared_geom geom = workingGeom();
472 return QgsSfcgalEngine::centroid( geom.get(), &errorMsg );
475bool QgsSfcgalGeometry::isEmpty()
const
478 sfcgal::errorHandler()->clearText( &errorMsg );
483 bool result = QgsSfcgalEngine::isEmpty( mSfcgalGeom.get(), &errorMsg );
484 THROW_ON_ERROR( &errorMsg );
489std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::translate(
const QgsVector3D &translation )
const
492 sfcgal::errorHandler()->clearText( &errorMsg );
494 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
495#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
498 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveTranslate( mSfcgalPrim.get(), translation, &errorMsg );
499 THROW_ON_ERROR( &errorMsg );
500 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, mPrimType, &errorMsg );
505 sfcgal::shared_geom result = QgsSfcgalEngine::translate( mSfcgalGeom.get(), translation, &errorMsg );
506 THROW_ON_ERROR( &errorMsg );
507 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
510 THROW_ON_ERROR( &errorMsg );
514std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::scale(
const QgsVector3D &scaleFactor,
const QgsPoint ¢er )
const
517 sfcgal::errorHandler()->clearText( &errorMsg );
519 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
520#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
523 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveScale( mSfcgalPrim.get(), scaleFactor, center, &errorMsg );
524 THROW_ON_ERROR( &errorMsg );
525 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, mPrimType, &errorMsg );
530 sfcgal::shared_geom result = QgsSfcgalEngine::scale( mSfcgalGeom.get(), scaleFactor, center, &errorMsg );
531 THROW_ON_ERROR( &errorMsg );
532 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
535 THROW_ON_ERROR( &errorMsg );
539std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate2D(
double angle,
const QgsPoint ¢er )
const
542 sfcgal::errorHandler()->clearText( &errorMsg );
544 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
545#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
548 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveRotate( mSfcgalPrim.get(), angle, { 0.0, 0.0, 1.0 }, center, &errorMsg );
549 THROW_ON_ERROR( &errorMsg );
550 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, mPrimType, &errorMsg );
551 THROW_ON_ERROR( &errorMsg );
557 sfcgal::shared_geom result = QgsSfcgalEngine::rotate2D( mSfcgalGeom.get(), angle, center, &errorMsg );
558 THROW_ON_ERROR( &errorMsg );
560 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
563 THROW_ON_ERROR( &errorMsg );
567std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::transform(
const QgsMatrix4x4 &mat )
const
570 sfcgal::errorHandler()->clearText( &errorMsg );
572#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
573 sfcgal::shared_geom geom = workingGeom();
575 sfcgal::shared_geom result = QgsSfcgalEngine::transform( geom.get(), mat );
576 THROW_ON_ERROR( &errorMsg );
578 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
579 THROW_ON_ERROR( &errorMsg );
583 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
587std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate3D(
double angle,
const QgsVector3D &axisVector,
const QgsPoint ¢er )
const
590 sfcgal::errorHandler()->clearText( &errorMsg );
592 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
593#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
596 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveRotate( mSfcgalPrim.get(), angle, axisVector, center, &errorMsg );
597 THROW_ON_ERROR( &errorMsg );
598 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, mPrimType, &errorMsg );
603 sfcgal::shared_geom result = QgsSfcgalEngine::rotate3D( mSfcgalGeom.get(), angle, axisVector, center, &errorMsg );
604 THROW_ON_ERROR( &errorMsg );
606 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
609 THROW_ON_ERROR( &errorMsg );
613double QgsSfcgalGeometry::area(
bool withDiscretization )
const
616 sfcgal::errorHandler()->clearText( &errorMsg );
619#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
622 result = QgsSfcgalEngine::primitiveArea( mSfcgalPrim.get(), withDiscretization, &errorMsg );
627 ( void ) withDiscretization;
628 result = QgsSfcgalEngine::area( mSfcgalGeom.get(), &errorMsg );
631 THROW_ON_ERROR( &errorMsg );
635double QgsSfcgalGeometry::length()
const
638 sfcgal::errorHandler()->clearText( &errorMsg );
643 double result = QgsSfcgalEngine::length( mSfcgalGeom.get(), &errorMsg );
644 THROW_ON_ERROR( &errorMsg );
649double QgsSfcgalGeometry::volume(
bool withDiscretization )
const
652 sfcgal::errorHandler()->clearText( &errorMsg );
658#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
659 result = QgsSfcgalEngine::primitiveVolume( mSfcgalPrim.get(), withDiscretization, &errorMsg );
661 ( void ) withDiscretization;
662 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
665 THROW_ON_ERROR( &errorMsg );
672 sfcgal::errorHandler()->clearText( &errorMsg );
673 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
674 THROW_ON_ERROR( &errorMsg );
676 sfcgal::shared_geom geom = workingGeom();
677 bool out = QgsSfcgalEngine::intersects( geom.get(), otherShared.get(), &errorMsg );
678 THROW_ON_ERROR( &errorMsg );
682bool QgsSfcgalGeometry::intersects(
const QgsSfcgalGeometry &otherGeom )
const
685 sfcgal::errorHandler()->clearText( &errorMsg );
687 sfcgal::shared_geom geom = workingGeom();
688 bool out = QgsSfcgalEngine::intersects( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
689 THROW_ON_ERROR( &errorMsg );
693std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection(
const QgsAbstractGeometry *otherGeom )
const
696 sfcgal::errorHandler()->clearText( &errorMsg );
697 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
698 THROW_ON_ERROR( &errorMsg );
700 sfcgal::shared_geom geom = workingGeom();
701 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherShared.get(), &errorMsg );
702 THROW_ON_ERROR( &errorMsg );
704 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
705 THROW_ON_ERROR( &errorMsg );
709std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection(
const QgsSfcgalGeometry &otherGeom )
const
712 sfcgal::errorHandler()->clearText( &errorMsg );
714 sfcgal::shared_geom geom = workingGeom();
715 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
716 THROW_ON_ERROR( &errorMsg );
718 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
719 THROW_ON_ERROR( &errorMsg );
723std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::combine(
const QVector<QgsAbstractGeometry *> &geomList )
const
726 sfcgal::errorHandler()->clearText( &errorMsg );
727 QVector<sfcgal::shared_geom> sfcgalGeomList;
729 sfcgal::shared_geom geom = workingGeom();
730 sfcgalGeomList.append( geom );
731 for ( QVector<QgsAbstractGeometry *>::const_iterator ite = geomList.constBegin(); ite != geomList.constEnd(); ++ite )
733 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( *ite, &errorMsg );
734 THROW_ON_ERROR( &errorMsg );
735 sfcgalGeomList.append( otherShared );
738 sfcgal::shared_geom result = QgsSfcgalEngine::combine( sfcgalGeomList, &errorMsg );
739 THROW_ON_ERROR( &errorMsg );
741 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
742 THROW_ON_ERROR( &errorMsg );
746std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference(
const QgsAbstractGeometry *otherGeom )
const
749 sfcgal::errorHandler()->clearText( &errorMsg );
750 sfcgal::shared_geom otherSharedr = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
751 THROW_ON_ERROR( &errorMsg );
753 sfcgal::shared_geom geom = workingGeom();
754 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherSharedr.get(), &errorMsg );
755 THROW_ON_ERROR( &errorMsg );
757 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
758 THROW_ON_ERROR( &errorMsg );
762std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference(
const QgsSfcgalGeometry &otherGeom )
const
765 sfcgal::errorHandler()->clearText( &errorMsg );
767 sfcgal::shared_geom geom = workingGeom();
768 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
769 THROW_ON_ERROR( &errorMsg );
771 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
772 THROW_ON_ERROR( &errorMsg );
776std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::triangulate()
const
779 sfcgal::errorHandler()->clearText( &errorMsg );
781 sfcgal::shared_geom geom = workingGeom();
782 sfcgal::shared_geom result = QgsSfcgalEngine::triangulate( geom.get(), &errorMsg );
783 THROW_ON_ERROR( &errorMsg );
785 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
786 THROW_ON_ERROR( &errorMsg );
790std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::convexHull()
const
793 sfcgal::errorHandler()->clearText( &errorMsg );
795 sfcgal::shared_geom geom = workingGeom();
796 sfcgal::shared_geom result = QgsSfcgalEngine::convexHull( geom.get(), &errorMsg );
797 THROW_ON_ERROR( &errorMsg );
799 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
800 THROW_ON_ERROR( &errorMsg );
804std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::envelope()
const
807 sfcgal::errorHandler()->clearText( &errorMsg );
809 sfcgal::shared_geom geom = workingGeom();
810 sfcgal::shared_geom result = QgsSfcgalEngine::envelope( geom.get(), &errorMsg );
811 THROW_ON_ERROR( &errorMsg );
813 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
814 THROW_ON_ERROR( &errorMsg );
818bool QgsSfcgalGeometry::covers(
const QgsSfcgalGeometry &otherGeom )
const
821 sfcgal::errorHandler()->clearText( &errorMsg );
823 sfcgal::shared_geom geom = workingGeom();
824 bool out = QgsSfcgalEngine::covers( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
825 THROW_ON_ERROR( &errorMsg );
829std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer3D(
double radius,
int segments,
Qgis::JoinStyle3D joinStyle3D )
const
832 sfcgal::errorHandler()->clearText( &errorMsg );
834 sfcgal::shared_geom geom = workingGeom();
835 sfcgal::shared_geom result = QgsSfcgalEngine::buffer3D( geom.get(), radius, segments, joinStyle3D, &errorMsg );
836 THROW_ON_ERROR( &errorMsg );
838 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
839 THROW_ON_ERROR( &errorMsg );
843std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer2D(
double radius,
int segments,
Qgis::JoinStyle joinStyle )
const
846 sfcgal::errorHandler()->clearText( &errorMsg );
848 sfcgal::shared_geom geom = workingGeom();
849 sfcgal::shared_geom result = QgsSfcgalEngine::buffer2D( geom.get(), radius, segments, joinStyle, &errorMsg );
850 THROW_ON_ERROR( &errorMsg );
852 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
853 THROW_ON_ERROR( &errorMsg );
857std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::simplify(
double tolerance,
bool preserveTopology )
const
860 sfcgal::errorHandler()->clearText( &errorMsg );
862 sfcgal::shared_geom geom = workingGeom();
863 sfcgal::shared_geom result = QgsSfcgalEngine::simplify( geom.get(), tolerance, preserveTopology, &errorMsg );
864 THROW_ON_ERROR( &errorMsg );
866 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
867 THROW_ON_ERROR( &errorMsg );
871std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::extrude(
const QgsVector3D &extrusion )
const
874 sfcgal::errorHandler()->clearText( &errorMsg );
876 sfcgal::shared_geom geom = workingGeom();
877 sfcgal::shared_geom result = QgsSfcgalEngine::extrude( geom.get(), extrusion, &errorMsg );
878 THROW_ON_ERROR( &errorMsg );
880 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
881 THROW_ON_ERROR( &errorMsg );
885std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::approximateMedialAxis(
bool extendToEdges )
const
888 sfcgal::errorHandler()->clearText( &errorMsg );
890 sfcgal::shared_geom geom = workingGeom();
891 sfcgal::shared_geom result = QgsSfcgalEngine::approximateMedialAxis( geom.get(), extendToEdges, &errorMsg );
892 THROW_ON_ERROR( &errorMsg );
894 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
895 THROW_ON_ERROR( &errorMsg );
899std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::toSolid()
const
902 sfcgal::errorHandler()->clearText( &errorMsg );
904 sfcgal::shared_geom geom = workingGeom();
905 sfcgal::shared_geom solid = QgsSfcgalEngine::toSolid( geom.get(), &errorMsg );
906 THROW_ON_ERROR( &errorMsg );
908 std::unique_ptr<QgsSfcgalGeometry> solidGeom = QgsSfcgalEngine::toSfcgalGeometry( solid, &errorMsg );
909 THROW_ON_ERROR( &errorMsg );
913std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::split3D(
const QgsPoint &planePoint,
const QgsVector3D &planeNormal,
bool closeGeometries )
const
916 sfcgal::errorHandler()->clearText( &errorMsg );
918#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
919 sfcgal::shared_geom geom = workingGeom();
921 sfcgal::shared_geom result = QgsSfcgalEngine::split3D( geom.get(), planePoint, planeNormal, closeGeometries );
922 THROW_ON_ERROR( &errorMsg );
924 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
925 THROW_ON_ERROR( &errorMsg );
928 Q_UNUSED( planePoint )
929 Q_UNUSED( planeNormal )
930 Q_UNUSED( closeGeometries )
931 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
935std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::toPolyhedralSurface()
const
938 sfcgal::errorHandler()->clearText( &errorMsg );
940 sfcgal::shared_geom geom = workingGeom();
941 sfcgal::shared_geom phs = QgsSfcgalEngine::toPolyhedralSurface( geom.get(), &errorMsg );
942 THROW_ON_ERROR( &errorMsg );
944 std::unique_ptr<QgsSfcgalGeometry> phsGeom = QgsSfcgalEngine::toSfcgalGeometry( phs, &errorMsg );
945 THROW_ON_ERROR( &errorMsg );
949std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createBox(
double sizeX,
double sizeY,
double sizeZ )
951#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
953 sfcgal::errorHandler()->clearText( &errorMsg );
954 sfcgal::shared_prim result = QgsSfcgalEngine::createBox( sizeX, sizeY, sizeZ, &errorMsg );
955 THROW_ON_ERROR( &errorMsg );
957 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_BOX, &errorMsg );
958 THROW_ON_ERROR( &errorMsg );
964 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
968std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCone(
double bottomRadius,
double height,
double topRadius,
unsigned int radial )
970#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
972 sfcgal::errorHandler()->clearText( &errorMsg );
973 sfcgal::shared_prim result = QgsSfcgalEngine::createCone( bottomRadius, height, topRadius, radial, &errorMsg );
974 THROW_ON_ERROR( &errorMsg );
976 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CONE, &errorMsg );
977 THROW_ON_ERROR( &errorMsg );
980 ( void ) bottomRadius;
984 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
988std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCube(
double size )
990#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
992 sfcgal::errorHandler()->clearText( &errorMsg );
993 sfcgal::shared_prim result = QgsSfcgalEngine::createCube( size, &errorMsg );
994 THROW_ON_ERROR( &errorMsg );
996 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CUBE, &errorMsg );
997 THROW_ON_ERROR( &errorMsg );
1001 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1005std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCylinder(
double radius,
double height,
unsigned int radial )
1007#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
1009 sfcgal::errorHandler()->clearText( &errorMsg );
1010 sfcgal::shared_prim result = QgsSfcgalEngine::createCylinder( radius, height, radial, &errorMsg );
1011 THROW_ON_ERROR( &errorMsg );
1013 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CYLINDER, &errorMsg );
1014 THROW_ON_ERROR( &errorMsg );
1020 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1024std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createSphere(
double radius,
unsigned int subdivisions )
1026#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
1028 sfcgal::errorHandler()->clearText( &errorMsg );
1029 sfcgal::shared_prim result = QgsSfcgalEngine::createSphere( radius, subdivisions, &errorMsg );
1030 THROW_ON_ERROR( &errorMsg );
1032 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_SPHERE, &errorMsg );
1033 THROW_ON_ERROR( &errorMsg );
1037 ( void ) subdivisions;
1038 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1042std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createTorus(
double mainRadius,
double tubeRadius,
unsigned int mainRadial,
unsigned int tubeRadial )
1044#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
1046 sfcgal::errorHandler()->clearText( &errorMsg );
1047 sfcgal::shared_prim result = QgsSfcgalEngine::createTorus( mainRadius, tubeRadius, mainRadial, tubeRadial, &errorMsg );
1048 THROW_ON_ERROR( &errorMsg );
1050 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_TORUS, &errorMsg );
1051 THROW_ON_ERROR( &errorMsg );
1054 ( void ) mainRadius;
1055 ( void ) tubeRadius;
1056 ( void ) mainRadial;
1057 ( void ) tubeRadial;
1058 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1062std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::primitiveAsPolyhedralSurface()
const
1064#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
1065 if ( !mIsPrimitive )
1069 sfcgal::errorHandler()->clearText( &errorMsg );
1070 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), &errorMsg );
1071 THROW_ON_ERROR( &errorMsg );
1073 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
1074 THROW_ON_ERROR( &errorMsg );
1077 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1081QgsMatrix4x4 QgsSfcgalGeometry::primitiveTransform()
const
1083#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
1084 if ( !mIsPrimitive )
1090 sfcgal::errorHandler()->clearText( &errorMsg );
1091 double *data = sfcgal_primitive_transformation( mSfcgalPrim.get() );
1092 THROW_ON_ERROR( &errorMsg );
1098 data[0], data[4], data[8], data[12],
1099 data[1], data[5], data[9], data[13],
1100 data[2], data[6], data[10], data[14],
1101 data[3], data[7], data[11], data[15]
1104 sfcgal_free_buffer( data );
1105 return transformMatrix;
1107 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1111QList<std::pair<QString, QString>> QgsSfcgalGeometry::primitiveParameters()
const
1113#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
1114 if ( !mIsPrimitive )
1118 sfcgal::errorHandler()->clearText( &errorMsg );
1119 QVector<sfcgal::PrimitiveParameterDesc> result = QgsSfcgalEngine::primitiveParameters( mSfcgalPrim.get(), &errorMsg );
1120 THROW_ON_ERROR( &errorMsg );
1122 QList<QPair<QString, QString>> out;
1123 for (
const auto ¶m : result )
1125 out.append( std::pair<QString, QString>( QString::fromStdString( param.name ), QString::fromStdString( param.type ) ) );
1130 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1134QVariant QgsSfcgalGeometry::primitiveParameter(
const QString &name )
const
1136#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
1137 if ( !mIsPrimitive )
1141 sfcgal::errorHandler()->clearText( &errorMsg );
1142 QVariant result = QgsSfcgalEngine::primitiveParameter( mSfcgalPrim.get(), name, &errorMsg );
1143 THROW_ON_ERROR( &errorMsg );
1148 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1152void QgsSfcgalGeometry::primitiveSetParameter(
const QString &name,
const QVariant &value )
1154#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
1155 if ( !mIsPrimitive )
1159 sfcgal::errorHandler()->clearText( &errorMsg );
1160 QgsSfcgalEngine::primitiveSetParameter( mSfcgalPrim.get(), name, value, &errorMsg );
1161 THROW_ON_ERROR( &errorMsg );
1166 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...