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(), mPrimTransform, &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 auto 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" ) );
258#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
259 if ( mIsPrimitive != other.mIsPrimitive )
264 out = QgsSfcgalEngine::primitiveIsEqual( mSfcgalPrim.get(), other.mSfcgalPrim.get(), -1.0, &errorMsg );
269 out = QgsSfcgalEngine::isEqual( mSfcgalGeom.get(), other.mSfcgalGeom.get(), -1.0, &errorMsg );
271 THROW_ON_ERROR( &errorMsg );
276bool QgsSfcgalGeometry::operator!=(
const QgsSfcgalGeometry &other )
const
278 return !( *
this == other );
281bool QgsSfcgalGeometry::fuzzyEqual(
const QgsSfcgalGeometry &other,
double epsilon )
const
284 sfcgal::errorHandler()->clearText( &errorMsg );
288#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
289 if ( mIsPrimitive != other.mIsPrimitive )
294 out = QgsSfcgalEngine::primitiveIsEqual( mSfcgalPrim.get(), other.mSfcgalPrim.get(), epsilon, &errorMsg );
299 out = QgsSfcgalEngine::isEqual( mSfcgalGeom.get(), other.mSfcgalGeom.get(), epsilon, &errorMsg );
302 THROW_ON_ERROR( &errorMsg );
306int QgsSfcgalGeometry::dimension()
const
309 sfcgal::errorHandler()->clearText( &errorMsg );
314 int result = QgsSfcgalEngine::dimension( mSfcgalGeom.get(), &errorMsg );
315 THROW_ON_ERROR( &errorMsg );
320std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::fromWkt(
const QString &wkt )
324 sfcgal::shared_geom sfcgalGeom = QgsSfcgalEngine::fromWkt( wkt, &errorMsg );
325 THROW_ON_ERROR( &errorMsg );
327 return std::make_unique<QgsSfcgalGeometry>( sfcgalGeom );
330int QgsSfcgalGeometry::partCount()
const
333 sfcgal::errorHandler()->clearText( &errorMsg );
338 int out = QgsSfcgalEngine::partCount( mSfcgalGeom.get(), &errorMsg );
339 THROW_ON_ERROR( &errorMsg );
344bool QgsSfcgalGeometry::addZValue(
double zValue )
347 sfcgal::errorHandler()->clearText( &errorMsg );
352 const bool added = QgsSfcgalEngine::addZValue( mSfcgalGeom.get(), zValue, &errorMsg );
353 THROW_ON_ERROR( &errorMsg );
360bool QgsSfcgalGeometry::addMValue(
double mValue )
363 sfcgal::errorHandler()->clearText( &errorMsg );
368 const bool added = QgsSfcgalEngine::addMValue( mSfcgalGeom.get(), mValue, &errorMsg );
369 THROW_ON_ERROR( &errorMsg );
376bool QgsSfcgalGeometry::dropZValue()
379 sfcgal::errorHandler()->clearText( &errorMsg );
384 const bool dropped = QgsSfcgalEngine::dropZValue( mSfcgalGeom.get(), &errorMsg );
385 THROW_ON_ERROR( &errorMsg );
392bool QgsSfcgalGeometry::dropMValue()
395 sfcgal::errorHandler()->clearText( &errorMsg );
400 const bool dropped = QgsSfcgalEngine::dropMValue( mSfcgalGeom.get(), &errorMsg );
401 THROW_ON_ERROR( &errorMsg );
408void QgsSfcgalGeometry::swapXy()
411 sfcgal::errorHandler()->clearText( &errorMsg );
416 QgsSfcgalEngine::swapXy( mSfcgalGeom.get(), &errorMsg );
417 THROW_ON_ERROR( &errorMsg );
422bool QgsSfcgalGeometry::isValid()
const
425 sfcgal::errorHandler()->clearText( &errorMsg );
430 const bool valid = QgsSfcgalEngine::isValid( mSfcgalGeom.get(), &errorMsg,
nullptr );
431 THROW_ON_ERROR( &errorMsg );
435void QgsSfcgalGeometry::clearCache()
const
438bool QgsSfcgalGeometry::isSimple()
const
441 sfcgal::errorHandler()->clearText( &errorMsg );
446 bool result = QgsSfcgalEngine::isSimple( mSfcgalGeom.get(), &errorMsg );
447 THROW_ON_ERROR( &errorMsg );
451QgsPoint QgsSfcgalGeometry::centroid()
const
454 sfcgal::errorHandler()->clearText( &errorMsg );
456 sfcgal::shared_geom geom = workingGeom();
457 return QgsSfcgalEngine::centroid( geom.get(), &errorMsg );
460bool QgsSfcgalGeometry::isEmpty()
const
463 sfcgal::errorHandler()->clearText( &errorMsg );
468 bool result = QgsSfcgalEngine::isEmpty( mSfcgalGeom.get(), &errorMsg );
469 THROW_ON_ERROR( &errorMsg );
474std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::translate(
const QgsVector3D &translation )
const
477 sfcgal::errorHandler()->clearText( &errorMsg );
479 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
480#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
483 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
484 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
485 resultGeom->setPrimitiveTranslate( translation );
490 sfcgal::shared_geom result = QgsSfcgalEngine::translate( mSfcgalGeom.get(), translation, &errorMsg );
491 THROW_ON_ERROR( &errorMsg );
492 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
495 THROW_ON_ERROR( &errorMsg );
499std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::scale(
const QgsVector3D &scaleFactor,
const QgsPoint ¢er )
const
502 sfcgal::errorHandler()->clearText( &errorMsg );
504 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
505#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
508 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
509 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
510 resultGeom->setPrimitiveScale( scaleFactor, center );
515 sfcgal::shared_geom result = QgsSfcgalEngine::scale( mSfcgalGeom.get(), scaleFactor, center, &errorMsg );
516 THROW_ON_ERROR( &errorMsg );
517 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
520 THROW_ON_ERROR( &errorMsg );
524std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate2D(
double angle,
const QgsPoint ¢er )
const
527 sfcgal::errorHandler()->clearText( &errorMsg );
529 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
530#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
533 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
534 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
535 resultGeom->setPrimitiveRotation( angle, { 0.0, 0.0, 1.0 }, center );
540 sfcgal::shared_geom result = QgsSfcgalEngine::rotate2D( mSfcgalGeom.get(), angle, center, &errorMsg );
541 THROW_ON_ERROR( &errorMsg );
543 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
546 THROW_ON_ERROR( &errorMsg );
550std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::transform(
const QMatrix4x4 &mat )
const
553 sfcgal::errorHandler()->clearText( &errorMsg );
555#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
556 sfcgal::shared_geom geom = workingGeom();
558 sfcgal::shared_geom result = QgsSfcgalEngine::transform( geom.get(), mat );
559 THROW_ON_ERROR( &errorMsg );
561 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
562 THROW_ON_ERROR( &errorMsg );
566 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
570std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate3D(
double angle,
const QgsVector3D &axisVector,
const QgsPoint ¢er )
const
573 sfcgal::errorHandler()->clearText( &errorMsg );
575 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
576#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
579 sfcgal::shared_prim prim = QgsSfcgalEngine::primitiveClone( mSfcgalPrim.get(), &errorMsg );
580 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( prim, mPrimType, &errorMsg );
581 resultGeom->setPrimitiveRotation( angle, axisVector, center );
586 sfcgal::shared_geom result = QgsSfcgalEngine::rotate3D( mSfcgalGeom.get(), angle, axisVector, center, &errorMsg );
587 THROW_ON_ERROR( &errorMsg );
589 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
592 THROW_ON_ERROR( &errorMsg );
596double QgsSfcgalGeometry::area(
bool withDiscretization )
const
599 sfcgal::errorHandler()->clearText( &errorMsg );
602#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
605 result = QgsSfcgalEngine::primitiveArea( mSfcgalPrim.get(), withDiscretization, &errorMsg );
610 ( void ) withDiscretization;
611 result = QgsSfcgalEngine::area( mSfcgalGeom.get(), &errorMsg );
614 THROW_ON_ERROR( &errorMsg );
618double QgsSfcgalGeometry::length()
const
621 sfcgal::errorHandler()->clearText( &errorMsg );
626 double result = QgsSfcgalEngine::length( mSfcgalGeom.get(), &errorMsg );
627 THROW_ON_ERROR( &errorMsg );
632double QgsSfcgalGeometry::volume(
bool withDiscretization )
const
635 sfcgal::errorHandler()->clearText( &errorMsg );
641#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
642 result = QgsSfcgalEngine::primitiveVolume( mSfcgalPrim.get(), withDiscretization, &errorMsg );
644 ( void ) withDiscretization;
645 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
648 THROW_ON_ERROR( &errorMsg );
655 sfcgal::errorHandler()->clearText( &errorMsg );
656 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
657 THROW_ON_ERROR( &errorMsg );
659 sfcgal::shared_geom geom = workingGeom();
660 bool out = QgsSfcgalEngine::intersects( geom.get(), otherShared.get(), &errorMsg );
661 THROW_ON_ERROR( &errorMsg );
665bool QgsSfcgalGeometry::intersects(
const QgsSfcgalGeometry &otherGeom )
const
668 sfcgal::errorHandler()->clearText( &errorMsg );
670 sfcgal::shared_geom geom = workingGeom();
671 bool out = QgsSfcgalEngine::intersects( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
672 THROW_ON_ERROR( &errorMsg );
676std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection(
const QgsAbstractGeometry *otherGeom )
const
679 sfcgal::errorHandler()->clearText( &errorMsg );
680 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
681 THROW_ON_ERROR( &errorMsg );
683 sfcgal::shared_geom geom = workingGeom();
684 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherShared.get(), &errorMsg );
685 THROW_ON_ERROR( &errorMsg );
687 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
688 THROW_ON_ERROR( &errorMsg );
692std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection(
const QgsSfcgalGeometry &otherGeom )
const
695 sfcgal::errorHandler()->clearText( &errorMsg );
697 sfcgal::shared_geom geom = workingGeom();
698 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
699 THROW_ON_ERROR( &errorMsg );
701 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
702 THROW_ON_ERROR( &errorMsg );
706std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::combine(
const QVector<QgsAbstractGeometry *> &geomList )
const
709 sfcgal::errorHandler()->clearText( &errorMsg );
710 QVector<sfcgal::shared_geom> sfcgalGeomList;
712 sfcgal::shared_geom geom = workingGeom();
713 sfcgalGeomList.append( geom );
714 for ( QVector<QgsAbstractGeometry *>::const_iterator ite = geomList.constBegin(); ite != geomList.constEnd(); ++ite )
716 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( *ite, &errorMsg );
717 THROW_ON_ERROR( &errorMsg );
718 sfcgalGeomList.append( otherShared );
721 sfcgal::shared_geom result = QgsSfcgalEngine::combine( sfcgalGeomList, &errorMsg );
722 THROW_ON_ERROR( &errorMsg );
724 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
725 THROW_ON_ERROR( &errorMsg );
729std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference(
const QgsAbstractGeometry *otherGeom )
const
732 sfcgal::errorHandler()->clearText( &errorMsg );
733 sfcgal::shared_geom otherSharedr = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
734 THROW_ON_ERROR( &errorMsg );
736 sfcgal::shared_geom geom = workingGeom();
737 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherSharedr.get(), &errorMsg );
738 THROW_ON_ERROR( &errorMsg );
740 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
741 THROW_ON_ERROR( &errorMsg );
745std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference(
const QgsSfcgalGeometry &otherGeom )
const
748 sfcgal::errorHandler()->clearText( &errorMsg );
750 sfcgal::shared_geom geom = workingGeom();
751 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
752 THROW_ON_ERROR( &errorMsg );
754 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
755 THROW_ON_ERROR( &errorMsg );
759std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::triangulate()
const
762 sfcgal::errorHandler()->clearText( &errorMsg );
764 sfcgal::shared_geom geom = workingGeom();
765 sfcgal::shared_geom result = QgsSfcgalEngine::triangulate( geom.get(), &errorMsg );
766 THROW_ON_ERROR( &errorMsg );
768 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
769 THROW_ON_ERROR( &errorMsg );
773std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::convexHull()
const
776 sfcgal::errorHandler()->clearText( &errorMsg );
778 sfcgal::shared_geom geom = workingGeom();
779 sfcgal::shared_geom result = QgsSfcgalEngine::convexHull( geom.get(), &errorMsg );
780 THROW_ON_ERROR( &errorMsg );
782 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
783 THROW_ON_ERROR( &errorMsg );
787std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::envelope()
const
790 sfcgal::errorHandler()->clearText( &errorMsg );
792 sfcgal::shared_geom geom = workingGeom();
793 sfcgal::shared_geom result = QgsSfcgalEngine::envelope( geom.get(), &errorMsg );
794 THROW_ON_ERROR( &errorMsg );
796 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
797 THROW_ON_ERROR( &errorMsg );
801bool QgsSfcgalGeometry::covers(
const QgsSfcgalGeometry &otherGeom )
const
804 sfcgal::errorHandler()->clearText( &errorMsg );
806 sfcgal::shared_geom geom = workingGeom();
807 bool out = QgsSfcgalEngine::covers( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
808 THROW_ON_ERROR( &errorMsg );
812std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer3D(
double radius,
int segments,
Qgis::JoinStyle3D joinStyle3D )
const
815 sfcgal::errorHandler()->clearText( &errorMsg );
817 sfcgal::shared_geom geom = workingGeom();
818 sfcgal::shared_geom result = QgsSfcgalEngine::buffer3D( geom.get(), radius, segments, joinStyle3D, &errorMsg );
819 THROW_ON_ERROR( &errorMsg );
821 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
822 THROW_ON_ERROR( &errorMsg );
826std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer2D(
double radius,
int segments,
Qgis::JoinStyle joinStyle )
const
829 sfcgal::errorHandler()->clearText( &errorMsg );
831 sfcgal::shared_geom geom = workingGeom();
832 sfcgal::shared_geom result = QgsSfcgalEngine::buffer2D( geom.get(), radius, segments, joinStyle, &errorMsg );
833 THROW_ON_ERROR( &errorMsg );
835 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
836 THROW_ON_ERROR( &errorMsg );
840std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::simplify(
double tolerance,
bool preserveTopology )
const
843 sfcgal::errorHandler()->clearText( &errorMsg );
845 sfcgal::shared_geom geom = workingGeom();
846 sfcgal::shared_geom result = QgsSfcgalEngine::simplify( geom.get(), tolerance, preserveTopology, &errorMsg );
847 THROW_ON_ERROR( &errorMsg );
849 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
850 THROW_ON_ERROR( &errorMsg );
854std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::extrude(
const QgsVector3D &extrusion )
const
857 sfcgal::errorHandler()->clearText( &errorMsg );
859 sfcgal::shared_geom geom = workingGeom();
860 sfcgal::shared_geom result = QgsSfcgalEngine::extrude( geom.get(), extrusion, &errorMsg );
861 THROW_ON_ERROR( &errorMsg );
863 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
864 THROW_ON_ERROR( &errorMsg );
868std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::approximateMedialAxis()
const
871 sfcgal::errorHandler()->clearText( &errorMsg );
873 sfcgal::shared_geom geom = workingGeom();
874 sfcgal::shared_geom result = QgsSfcgalEngine::approximateMedialAxis( geom.get(), &errorMsg );
875 THROW_ON_ERROR( &errorMsg );
877 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
878 THROW_ON_ERROR( &errorMsg );
882std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCube(
double size )
884#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
886 sfcgal::errorHandler()->clearText( &errorMsg );
887 sfcgal::shared_prim result = QgsSfcgalEngine::createCube( size, &errorMsg );
888 THROW_ON_ERROR( &errorMsg );
890 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CUBE, &errorMsg );
891 THROW_ON_ERROR( &errorMsg );
895 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
899std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::primitiveAsPolyhedralSurface()
const
901#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
906 sfcgal::errorHandler()->clearText( &errorMsg );
907 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), mPrimTransform, &errorMsg );
908 THROW_ON_ERROR( &errorMsg );
910 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
911 THROW_ON_ERROR( &errorMsg );
914 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
918QMatrix4x4 QgsSfcgalGeometry::primitiveTransform()
const
920#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
924 return mPrimTransform;
926 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
930QList<std::pair<QString, QString>> QgsSfcgalGeometry::primitiveParameters()
const
932#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
937 sfcgal::errorHandler()->clearText( &errorMsg );
938 QVector<sfcgal::PrimitiveParameterDesc> result = QgsSfcgalEngine::primitiveParameters( mSfcgalPrim.get(), &errorMsg );
939 THROW_ON_ERROR( &errorMsg );
941 QList<QPair<QString, QString>> out;
942 for (
const auto ¶m : result )
944 out.append( std::pair<QString, QString>( QString::fromStdString( param.name ), QString::fromStdString( param.type ) ) );
949 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
953QVariant QgsSfcgalGeometry::primitiveParameter(
const QString &name )
const
955#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
960 sfcgal::errorHandler()->clearText( &errorMsg );
961 QVariant result = QgsSfcgalEngine::primitiveParameter( mSfcgalPrim.get(), name, &errorMsg );
962 THROW_ON_ERROR( &errorMsg );
967 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
971void QgsSfcgalGeometry::primitiveSetParameter(
const QString &name,
const QVariant &value )
973#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
978 sfcgal::errorHandler()->clearText( &errorMsg );
979 QgsSfcgalEngine::primitiveSetParameter( mSfcgalPrim.get(), name, value, &errorMsg );
980 THROW_ON_ERROR( &errorMsg );
985 throw QgsNotSupportedException( QObject::tr(
"This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
990#if SFCGAL_VERSION_NUM >= SFCGAL_MAKE_VERSION( 2, 3, 0 )
991void QgsSfcgalGeometry::setPrimitiveTranslate(
const QgsVector3D &translation )
993 mPrimTransform.translate( mPrimTransform.column( 3 ).toVector3D() + translation.
toVector3D() );
996void QgsSfcgalGeometry::setPrimitiveScale(
const QgsVector3D &scaleFactor,
const QgsPoint ¢er )
998 QVector3D qCenter( center.
x(), center.
y(), center.
z() );
999 QVector3D prevTrans = mPrimTransform.column( 3 ).toVector3D();
1000 mPrimTransform.translate( prevTrans - qCenter );
1001 mPrimTransform.scale( scaleFactor.
toVector3D() );
1002 mPrimTransform.translate( prevTrans + qCenter );
1005void QgsSfcgalGeometry::setPrimitiveRotation(
double angle,
const QgsVector3D &axisVector,
const QgsPoint ¢er )
1007 QVector3D qCenter( center.
x(), center.
y(), center.
z() );
1008 QVector3D prevTrans = mPrimTransform.column( 3 ).toVector3D();
1009 mPrimTransform.translate( prevTrans - qCenter );
1011 mPrimTransform.rotate( QQuaternion::fromAxisAndAngle( axisVector.
toVector3D(), angle ) );
1012 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.