QGIS API Documentation 4.5.0-Master (7108d05adee)
Loading...
Searching...
No Matches
qgssfcgalgeometry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssfcgalGeometry.cpp
3 ----------------
4 begin : May 2025
5 copyright : (C) 2025 by Oslandia
6 email : benoit dot de dot mezzo at oslandia dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsconfig.h"
19
20#include <QString>
21
22using namespace Qt::StringLiterals;
23
24#ifdef HAVE_SFCGAL
25
26#include "qgssfcgalgeometry.h"
27
28#include "qgsvector3d.h"
29#include "qgswkbptr.h"
30
31#include <QByteArray>
32
33QgsSfcgalGeometry::QgsSfcgalGeometry()
34 : mIsPrimitive( false )
35{}
36
37QgsSfcgalGeometry::QgsSfcgalGeometry( const QgsAbstractGeometry *qgsGeom )
38 : mIsPrimitive( false )
39{
40 if ( qgsGeom )
41 {
42 QString errorMsg;
43 sfcgal::errorHandler()->clearText( &errorMsg );
44 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( qgsGeom, &errorMsg );
45 THROW_ON_ERROR( &errorMsg );
46 }
47}
48
49QgsSfcgalGeometry::QgsSfcgalGeometry( const QgsAbstractGeometry &qgsGeom )
50 : mIsPrimitive( false )
51{
52 QString errorMsg;
53 sfcgal::errorHandler()->clearText( &errorMsg );
54 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( &qgsGeom, &errorMsg );
55 THROW_ON_ERROR( &errorMsg );
56}
57
58QgsSfcgalGeometry::QgsSfcgalGeometry( sfcgal::shared_geom sfcgalGeom )
59 : mSfcgalGeom( sfcgalGeom )
60 , mIsPrimitive( false )
61{}
62
63QgsSfcgalGeometry::QgsSfcgalGeometry( sfcgal::shared_prim sfcgalPrim, sfcgal::primitiveType type )
64 : mIsPrimitive( true )
65{
66#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
67 mSfcgalPrim = sfcgalPrim;
68 mPrimType = type;
69#else
70 ( void ) sfcgalPrim;
71 ( void ) type;
72 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
73#endif
74}
75
76QgsSfcgalGeometry::QgsSfcgalGeometry( const QgsGeometry &qgsGeom )
77{
78 QString errorMsg;
79 sfcgal::errorHandler()->clearText( &errorMsg );
80 mSfcgalGeom = QgsSfcgalEngine::fromAbstractGeometry( qgsGeom.constGet(), &errorMsg );
81 THROW_ON_ERROR( &errorMsg );
82}
83
84QgsSfcgalGeometry::QgsSfcgalGeometry( const QgsSfcgalGeometry &otherGeom )
85{
86 QString errorMsg;
87 sfcgal::errorHandler()->clearText( &errorMsg );
88 mIsPrimitive = otherGeom.mIsPrimitive;
89#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
90 mPrimType = otherGeom.mPrimType;
91 if ( mIsPrimitive )
92 mSfcgalPrim = QgsSfcgalEngine::primitiveClone( otherGeom.mSfcgalPrim.get(), &errorMsg );
93 else
94#endif
95 mSfcgalGeom = QgsSfcgalEngine::cloneGeometry( otherGeom.mSfcgalGeom.get(), &errorMsg );
96 THROW_ON_ERROR( &errorMsg );
97}
98
99QgsSfcgalGeometry::QgsSfcgalGeometry( const QString &wkt )
100{
101 QString errorMsg;
102 sfcgal::errorHandler()->clearText( &errorMsg );
103 mSfcgalGeom = QgsSfcgalEngine::fromWkt( wkt, &errorMsg );
104 THROW_ON_ERROR( &errorMsg );
105}
106
107sfcgal::shared_geom QgsSfcgalGeometry::workingGeom() const
108{
109 sfcgal::shared_geom geom;
110
111#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
112 if ( mIsPrimitive )
113 {
114 QString errorMsg;
115 geom = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), &errorMsg );
116 THROW_ON_ERROR( &errorMsg );
117 }
118 else
119#endif
120 geom = mSfcgalGeom;
121
122 return geom;
123}
124
125
126Qgis::WkbType QgsSfcgalGeometry::wkbType() const
127{
128 QString errorMsg;
129 sfcgal::errorHandler()->clearText( &errorMsg );
130
131#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
132 if ( mIsPrimitive )
134#endif
135
136 Qgis::WkbType out = QgsSfcgalEngine::wkbType( mSfcgalGeom.get(), &errorMsg );
137 THROW_ON_ERROR( &errorMsg );
138 return out;
139}
140
141QString QgsSfcgalGeometry::geometryType() const
142{
143 QString errorMsg;
144 sfcgal::errorHandler()->clearText( &errorMsg );
145
146 QString out;
147#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
148 if ( mIsPrimitive )
149 {
150 switch ( mPrimType )
151 {
152 case sfcgal::primitiveType::SFCGAL_TYPE_CYLINDER:
153 out = "cylinder";
154 break;
155 case sfcgal::primitiveType::SFCGAL_TYPE_SPHERE:
156 out = "sphere";
157 break;
158 case sfcgal::primitiveType::SFCGAL_TYPE_TORUS:
159 out = "torus";
160 break;
161 case sfcgal::primitiveType::SFCGAL_TYPE_BOX:
162 out = "box";
163 break;
164 case sfcgal::primitiveType::SFCGAL_TYPE_CUBE:
165 out = "cube";
166 break;
167 case sfcgal::primitiveType::SFCGAL_TYPE_CONE:
168 out = "cone";
169 break;
170 default:
171 sfcgal::errorHandler()->addText( u"Type '%1' is unknown."_s.arg( mPrimType ) );
172 }
173 }
174 else
175#endif
176 {
177 out = QgsSfcgalEngine::geometryType( mSfcgalGeom.get(), &errorMsg );
178 THROW_ON_ERROR( &errorMsg );
179 }
180 return out;
181}
182
183std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::clone() const
184{
185 return std::make_unique<QgsSfcgalGeometry>( *this );
186}
187
188std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::fromWkb( const QgsConstWkbPtr &wkbPtr )
189{
190 if ( !wkbPtr )
191 {
192 return nullptr;
193 }
194
195 QString errorMsg;
196 sfcgal::shared_geom sfcgalGeom = QgsSfcgalEngine::fromWkb( wkbPtr, &errorMsg );
197 THROW_ON_ERROR( &errorMsg );
198
199 return std::make_unique<QgsSfcgalGeometry>( sfcgalGeom );
200}
201
202
203QByteArray QgsSfcgalGeometry::asWkb( QgsAbstractGeometry::WkbFlags ) const
204{
205 QString errorMsg;
206 sfcgal::errorHandler()->clearText( &errorMsg );
207
208 sfcgal::shared_geom geom = workingGeom();
209 QByteArray wkbArray = QgsSfcgalEngine::toWkb( geom.get(), &errorMsg );
210 THROW_ON_ERROR( &errorMsg );
211
212 return wkbArray;
213}
214
215QString QgsSfcgalGeometry::asWkt( int precision ) const
216{
217 QString errorMsg;
218 sfcgal::errorHandler()->clearText( &errorMsg );
219
220 sfcgal::shared_geom geom = workingGeom();
221 QString out = QgsSfcgalEngine::toWkt( geom.get(), precision, &errorMsg );
222 THROW_ON_ERROR( &errorMsg );
223
224 return out;
225}
226
227std::unique_ptr<QgsAbstractGeometry> QgsSfcgalGeometry::asQgisGeometry() const
228{
229 QString errorMsg;
230 sfcgal::errorHandler()->clearText( &errorMsg );
231
232 sfcgal::shared_geom geom = workingGeom();
233 std::unique_ptr<QgsAbstractGeometry> out = QgsSfcgalEngine::toAbstractGeometry( geom.get(), &errorMsg );
234 THROW_ON_ERROR( &errorMsg );
235 return out;
236}
237
238std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::boundary() const
239{
240 QString errorMsg;
241 sfcgal::errorHandler()->clearText( &errorMsg );
242
243 sfcgal::shared_geom geom = workingGeom();
244 sfcgal::shared_geom boundary = QgsSfcgalEngine::boundary( geom.get(), &errorMsg );
245 THROW_ON_ERROR( &errorMsg );
246
247 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( boundary, &errorMsg );
248 THROW_ON_ERROR( &errorMsg );
249 return resultGeom;
250}
251
252bool QgsSfcgalGeometry::operator==( const QgsSfcgalGeometry &other ) const
253{
254#if SFCGAL_VERSION_NUM < SFCGAL_COMPUTE_VERSION( 2, 1, 0 )
255 ( void ) other;
256 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.1 or later" ) );
257#else
258 QString errorMsg;
259 sfcgal::errorHandler()->clearText( &errorMsg );
260 bool out;
261
262#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
263 if ( mIsPrimitive != other.mIsPrimitive )
264 return false;
265
266 if ( mIsPrimitive )
267 {
268 out = QgsSfcgalEngine::primitiveIsEqual( mSfcgalPrim.get(), other.mSfcgalPrim.get(), -1.0, &errorMsg );
269 }
270 else
271#endif
272 {
273 out = QgsSfcgalEngine::isEqual( mSfcgalGeom.get(), other.mSfcgalGeom.get(), -1.0, &errorMsg );
274 }
275 THROW_ON_ERROR( &errorMsg );
276 return out;
277#endif
278}
279
280bool QgsSfcgalGeometry::operator!=( const QgsSfcgalGeometry &other ) const
281{
282 return !( *this == other );
283}
284
285bool QgsSfcgalGeometry::fuzzyEqual( const QgsSfcgalGeometry &other, double epsilon ) const
286{
287 QString errorMsg;
288 sfcgal::errorHandler()->clearText( &errorMsg );
289
290 bool out;
291
292#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
293 if ( mIsPrimitive != other.mIsPrimitive )
294 return false;
295
296 if ( mIsPrimitive )
297 {
298 out = QgsSfcgalEngine::primitiveIsEqual( mSfcgalPrim.get(), other.mSfcgalPrim.get(), epsilon, &errorMsg );
299 }
300 else
301#endif
302 {
303 out = QgsSfcgalEngine::isEqual( mSfcgalGeom.get(), other.mSfcgalGeom.get(), epsilon, &errorMsg );
304 }
305
306 THROW_ON_ERROR( &errorMsg );
307 return out;
308}
309
310int QgsSfcgalGeometry::dimension() const
311{
312 QString errorMsg;
313 sfcgal::errorHandler()->clearText( &errorMsg );
314
315 if ( mIsPrimitive )
316 return 3;
317
318 int result = QgsSfcgalEngine::dimension( mSfcgalGeom.get(), &errorMsg );
319 THROW_ON_ERROR( &errorMsg );
320
321 return result;
322}
323
324std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::fromWkt( const QString &wkt )
325{
326 QString errorMsg;
327
328 sfcgal::shared_geom sfcgalGeom = QgsSfcgalEngine::fromWkt( wkt, &errorMsg );
329 THROW_ON_ERROR( &errorMsg );
330
331 return std::make_unique<QgsSfcgalGeometry>( sfcgalGeom );
332}
333
334int QgsSfcgalGeometry::partCount() const
335{
336 QString errorMsg;
337 sfcgal::errorHandler()->clearText( &errorMsg );
338
339 if ( mIsPrimitive )
340 return 1;
341
342 int out = QgsSfcgalEngine::partCount( mSfcgalGeom.get(), &errorMsg );
343 THROW_ON_ERROR( &errorMsg );
344
345 return out;
346}
347
348bool QgsSfcgalGeometry::addZValue( double zValue )
349{
350 QString errorMsg;
351 sfcgal::errorHandler()->clearText( &errorMsg );
352
353 if ( mIsPrimitive )
354 throw QgsNotSupportedException( QObject::tr( "Operation '%1' does not apply to primitive." ).arg( "addZValue" ) );
355
356 const bool added = QgsSfcgalEngine::addZValue( mSfcgalGeom.get(), zValue, &errorMsg );
357 THROW_ON_ERROR( &errorMsg );
358
359 clearCache();
360
361 return added;
362}
363
364bool QgsSfcgalGeometry::addMValue( double mValue )
365{
366 QString errorMsg;
367 sfcgal::errorHandler()->clearText( &errorMsg );
368
369 if ( mIsPrimitive )
370 throw QgsNotSupportedException( QObject::tr( "Operation '%1' does not apply to primitive." ).arg( "addMValue" ) );
371
372 const bool added = QgsSfcgalEngine::addMValue( mSfcgalGeom.get(), mValue, &errorMsg );
373 THROW_ON_ERROR( &errorMsg );
374
375 clearCache();
376
377 return added;
378}
379
380bool QgsSfcgalGeometry::dropZValue()
381{
382 QString errorMsg;
383 sfcgal::errorHandler()->clearText( &errorMsg );
384
385 if ( mIsPrimitive )
386 throw QgsNotSupportedException( QObject::tr( "Operation '%1' does not apply to primitive." ).arg( "dropZValue" ) );
387
388 const bool dropped = QgsSfcgalEngine::dropZValue( mSfcgalGeom.get(), &errorMsg );
389 THROW_ON_ERROR( &errorMsg );
390
391 clearCache();
392
393 return dropped;
394}
395
396bool QgsSfcgalGeometry::dropMValue()
397{
398 QString errorMsg;
399 sfcgal::errorHandler()->clearText( &errorMsg );
400
401 if ( mIsPrimitive )
402 throw QgsNotSupportedException( QObject::tr( "Operation '%1' does not apply to primitive." ).arg( "dropMValue" ) );
403
404 const bool dropped = QgsSfcgalEngine::dropMValue( mSfcgalGeom.get(), &errorMsg );
405 THROW_ON_ERROR( &errorMsg );
406
407 clearCache();
408
409 return dropped;
410}
411
412void QgsSfcgalGeometry::swapXy()
413{
414 QString errorMsg;
415 sfcgal::errorHandler()->clearText( &errorMsg );
416
417 if ( mIsPrimitive )
418 throw QgsNotSupportedException( QObject::tr( "Operation '%1' does not apply to primitive." ).arg( "swapXy" ) );
419
420 QgsSfcgalEngine::swapXy( mSfcgalGeom.get(), &errorMsg );
421 THROW_ON_ERROR( &errorMsg );
422
423 clearCache();
424}
425
426bool QgsSfcgalGeometry::isValid() const
427{
428 QString errorMsg;
429 sfcgal::errorHandler()->clearText( &errorMsg );
430
431 if ( mIsPrimitive )
432 return true;
433
434 const bool valid = QgsSfcgalEngine::isValid( mSfcgalGeom.get(), &errorMsg, nullptr );
435 THROW_ON_ERROR( &errorMsg );
436 return valid;
437}
438
439void QgsSfcgalGeometry::clearCache() const
440{}
441
442bool QgsSfcgalGeometry::isSimple() const
443{
444 QString errorMsg;
445 sfcgal::errorHandler()->clearText( &errorMsg );
446
447 if ( mIsPrimitive )
448 return true;
449
450 bool result = QgsSfcgalEngine::isSimple( mSfcgalGeom.get(), &errorMsg );
451 THROW_ON_ERROR( &errorMsg );
452 return result;
453}
454
455std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::geometryN( unsigned int index ) const
456{
457 QString errorMsg;
458 sfcgal::errorHandler()->clearText( &errorMsg );
459
460 sfcgal::shared_geom geom = workingGeom();
461 sfcgal::shared_geom result = QgsSfcgalEngine::geometryN( geom.get(), index );
462 THROW_ON_ERROR( &errorMsg );
463
464 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
465 THROW_ON_ERROR( &errorMsg );
466 return resultGeom;
467}
468
469QgsPoint QgsSfcgalGeometry::centroid() const
470{
471 QString errorMsg;
472 sfcgal::errorHandler()->clearText( &errorMsg );
473
474 sfcgal::shared_geom geom = workingGeom();
475 return QgsSfcgalEngine::centroid( geom.get(), &errorMsg );
476}
477
478bool QgsSfcgalGeometry::isEmpty() const
479{
480 QString errorMsg;
481 sfcgal::errorHandler()->clearText( &errorMsg );
482
483 if ( mIsPrimitive )
484 return false;
485
486 bool result = QgsSfcgalEngine::isEmpty( mSfcgalGeom.get(), &errorMsg );
487 THROW_ON_ERROR( &errorMsg );
488
489 return result;
490}
491
492std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::translate( const QgsVector3D &translation ) const
493{
494 QString errorMsg;
495 sfcgal::errorHandler()->clearText( &errorMsg );
496
497 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
498#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
499 if ( mIsPrimitive )
500 {
501 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveTranslate( mSfcgalPrim.get(), translation, &errorMsg );
502 THROW_ON_ERROR( &errorMsg );
503 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, mPrimType, &errorMsg );
504 }
505 else
506#endif
507 {
508 sfcgal::shared_geom result = QgsSfcgalEngine::translate( mSfcgalGeom.get(), translation, &errorMsg );
509 THROW_ON_ERROR( &errorMsg );
510 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
511 }
512
513 THROW_ON_ERROR( &errorMsg );
514 return resultGeom;
515}
516
517std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::scale( const QgsVector3D &scaleFactor, const QgsPoint &center ) const
518{
519 QString errorMsg;
520 sfcgal::errorHandler()->clearText( &errorMsg );
521
522 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
523#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
524 if ( mIsPrimitive )
525 {
526 sfcgal::shared_prim result = QgsSfcgalEngine::primitiveScale( mSfcgalPrim.get(), scaleFactor, center, &errorMsg );
527 THROW_ON_ERROR( &errorMsg );
528 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, mPrimType, &errorMsg );
529 }
530 else
531#endif
532 {
533 sfcgal::shared_geom result = QgsSfcgalEngine::scale( mSfcgalGeom.get(), scaleFactor, center, &errorMsg );
534 THROW_ON_ERROR( &errorMsg );
535 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
536 }
537
538 THROW_ON_ERROR( &errorMsg );
539 return resultGeom;
540}
541
542std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate2D( double angle, const QgsPoint &center ) const
543{
544 QString errorMsg;
545 sfcgal::errorHandler()->clearText( &errorMsg );
546
547 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
548#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
549 if ( mIsPrimitive )
550 {
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 );
555 return resultGeom;
556 }
557 else
558#endif
559 {
560 sfcgal::shared_geom result = QgsSfcgalEngine::rotate2D( mSfcgalGeom.get(), angle, center, &errorMsg );
561 THROW_ON_ERROR( &errorMsg );
562
563 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
564 }
565
566 THROW_ON_ERROR( &errorMsg );
567 return resultGeom;
568}
569
570std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::transform( const QgsMatrix4x4 &mat ) const
571{
572 QString errorMsg;
573 sfcgal::errorHandler()->clearText( &errorMsg );
574
575#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
576 sfcgal::shared_geom geom = workingGeom();
577
578 sfcgal::shared_geom result = QgsSfcgalEngine::transform( geom.get(), mat );
579 THROW_ON_ERROR( &errorMsg );
580
581 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
582 THROW_ON_ERROR( &errorMsg );
583 return resultGeom;
584#else
585 ( void ) mat;
586 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
587#endif
588}
589
590std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::rotate3D( double angle, const QgsVector3D &axisVector, const QgsPoint &center ) const
591{
592 QString errorMsg;
593 sfcgal::errorHandler()->clearText( &errorMsg );
594
595 std::unique_ptr<QgsSfcgalGeometry> resultGeom;
596#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
597 if ( mIsPrimitive )
598 {
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 );
602 }
603 else
604#endif
605 {
606 sfcgal::shared_geom result = QgsSfcgalEngine::rotate3D( mSfcgalGeom.get(), angle, axisVector, center, &errorMsg );
607 THROW_ON_ERROR( &errorMsg );
608
609 resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
610 }
611
612 THROW_ON_ERROR( &errorMsg );
613 return resultGeom;
614}
615
616double QgsSfcgalGeometry::area( bool withDiscretization ) const
617{
618 QString errorMsg;
619 sfcgal::errorHandler()->clearText( &errorMsg );
620
621 double result;
622#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
623 if ( mIsPrimitive )
624 {
625 result = QgsSfcgalEngine::primitiveArea( mSfcgalPrim.get(), withDiscretization, &errorMsg );
626 }
627 else
628#endif
629 {
630 ( void ) withDiscretization;
631 result = QgsSfcgalEngine::area( mSfcgalGeom.get(), &errorMsg );
632 }
633
634 THROW_ON_ERROR( &errorMsg );
635 return result;
636}
637
638double QgsSfcgalGeometry::length() const
639{
640 QString errorMsg;
641 sfcgal::errorHandler()->clearText( &errorMsg );
642
643 if ( mIsPrimitive )
644 throw QgsNotSupportedException( QObject::tr( "Operation '%1' does not apply to primitive." ).arg( "length" ) );
645
646 double result = QgsSfcgalEngine::length( mSfcgalGeom.get(), &errorMsg );
647 THROW_ON_ERROR( &errorMsg );
648
649 return result;
650}
651
652double QgsSfcgalGeometry::volume( bool withDiscretization ) const
653{
654 QString errorMsg;
655 sfcgal::errorHandler()->clearText( &errorMsg );
656
657 if ( !mIsPrimitive )
658 throw QgsNotSupportedException( QObject::tr( "Operation '%1' does not apply to geometry." ).arg( "volume" ) );
659
660 double result;
661#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
662 result = QgsSfcgalEngine::primitiveVolume( mSfcgalPrim.get(), withDiscretization, &errorMsg );
663#else
664 ( void ) withDiscretization;
665 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
666#endif
667
668 THROW_ON_ERROR( &errorMsg );
669 return result;
670}
671
672bool QgsSfcgalGeometry::intersects( const QgsAbstractGeometry *otherGeom ) const
673{
674 QString errorMsg;
675 sfcgal::errorHandler()->clearText( &errorMsg );
676 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
677 THROW_ON_ERROR( &errorMsg );
678
679 sfcgal::shared_geom geom = workingGeom();
680 bool out = QgsSfcgalEngine::intersects( geom.get(), otherShared.get(), &errorMsg );
681 THROW_ON_ERROR( &errorMsg );
682 return out;
683}
684
685bool QgsSfcgalGeometry::intersects( const QgsSfcgalGeometry &otherGeom ) const
686{
687 QString errorMsg;
688 sfcgal::errorHandler()->clearText( &errorMsg );
689
690 sfcgal::shared_geom geom = workingGeom();
691 bool out = QgsSfcgalEngine::intersects( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
692 THROW_ON_ERROR( &errorMsg );
693 return out;
694}
695
696std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection( const QgsAbstractGeometry *otherGeom ) const
697{
698 QString errorMsg;
699 sfcgal::errorHandler()->clearText( &errorMsg );
700 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
701 THROW_ON_ERROR( &errorMsg );
702
703 sfcgal::shared_geom geom = workingGeom();
704 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherShared.get(), &errorMsg );
705 THROW_ON_ERROR( &errorMsg );
706
707 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
708 THROW_ON_ERROR( &errorMsg );
709 return resultGeom;
710}
711
712std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::intersection( const QgsSfcgalGeometry &otherGeom ) const
713{
714 QString errorMsg;
715 sfcgal::errorHandler()->clearText( &errorMsg );
716
717 sfcgal::shared_geom geom = workingGeom();
718 sfcgal::shared_geom result = QgsSfcgalEngine::intersection( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
719 THROW_ON_ERROR( &errorMsg );
720
721 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
722 THROW_ON_ERROR( &errorMsg );
723 return resultGeom;
724}
725
726std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::combine( const QVector<QgsAbstractGeometry *> &geomList ) const
727{
728 QString errorMsg;
729 sfcgal::errorHandler()->clearText( &errorMsg );
730 QVector<sfcgal::shared_geom> sfcgalGeomList;
731
732 sfcgal::shared_geom geom = workingGeom();
733 sfcgalGeomList.append( geom );
734 for ( QVector<QgsAbstractGeometry *>::const_iterator ite = geomList.constBegin(); ite != geomList.constEnd(); ++ite )
735 {
736 sfcgal::shared_geom otherShared = QgsSfcgalEngine::fromAbstractGeometry( *ite, &errorMsg );
737 THROW_ON_ERROR( &errorMsg );
738 sfcgalGeomList.append( otherShared );
739 }
740
741 sfcgal::shared_geom result = QgsSfcgalEngine::combine( sfcgalGeomList, &errorMsg );
742 THROW_ON_ERROR( &errorMsg );
743
744 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
745 THROW_ON_ERROR( &errorMsg );
746 return resultGeom;
747}
748
749std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference( const QgsAbstractGeometry *otherGeom ) const
750{
751 QString errorMsg;
752 sfcgal::errorHandler()->clearText( &errorMsg );
753 sfcgal::shared_geom otherSharedr = QgsSfcgalEngine::fromAbstractGeometry( otherGeom, &errorMsg );
754 THROW_ON_ERROR( &errorMsg );
755
756 sfcgal::shared_geom geom = workingGeom();
757 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherSharedr.get(), &errorMsg );
758 THROW_ON_ERROR( &errorMsg );
759
760 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
761 THROW_ON_ERROR( &errorMsg );
762 return resultGeom;
763}
764
765std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::difference( const QgsSfcgalGeometry &otherGeom ) const
766{
767 QString errorMsg;
768 sfcgal::errorHandler()->clearText( &errorMsg );
769
770 sfcgal::shared_geom geom = workingGeom();
771 sfcgal::shared_geom result = QgsSfcgalEngine::difference( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
772 THROW_ON_ERROR( &errorMsg );
773
774 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
775 THROW_ON_ERROR( &errorMsg );
776 return resultGeom;
777}
778
779std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::triangulate() const
780{
781 QString errorMsg;
782 sfcgal::errorHandler()->clearText( &errorMsg );
783
784 sfcgal::shared_geom geom = workingGeom();
785 sfcgal::shared_geom result = QgsSfcgalEngine::triangulate( geom.get(), &errorMsg );
786 THROW_ON_ERROR( &errorMsg );
787
788 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
789 THROW_ON_ERROR( &errorMsg );
790 return resultGeom;
791}
792
793std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::convexHull() const
794{
795 QString errorMsg;
796 sfcgal::errorHandler()->clearText( &errorMsg );
797
798 sfcgal::shared_geom geom = workingGeom();
799 sfcgal::shared_geom result = QgsSfcgalEngine::convexHull( geom.get(), &errorMsg );
800 THROW_ON_ERROR( &errorMsg );
801
802 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
803 THROW_ON_ERROR( &errorMsg );
804 return resultGeom;
805}
806
807std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::envelope() const
808{
809 QString errorMsg;
810 sfcgal::errorHandler()->clearText( &errorMsg );
811
812 sfcgal::shared_geom geom = workingGeom();
813 sfcgal::shared_geom result = QgsSfcgalEngine::envelope( geom.get(), &errorMsg );
814 THROW_ON_ERROR( &errorMsg );
815
816 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
817 THROW_ON_ERROR( &errorMsg );
818 return resultGeom;
819}
820
821bool QgsSfcgalGeometry::covers( const QgsSfcgalGeometry &otherGeom ) const
822{
823 QString errorMsg;
824 sfcgal::errorHandler()->clearText( &errorMsg );
825
826 sfcgal::shared_geom geom = workingGeom();
827 bool out = QgsSfcgalEngine::covers( geom.get(), otherGeom.workingGeom().get(), &errorMsg );
828 THROW_ON_ERROR( &errorMsg );
829 return out;
830}
831
832std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer3D( double radius, int segments, Qgis::JoinStyle3D joinStyle3D ) const
833{
834 QString errorMsg;
835 sfcgal::errorHandler()->clearText( &errorMsg );
836
837 sfcgal::shared_geom geom = workingGeom();
838 sfcgal::shared_geom result = QgsSfcgalEngine::buffer3D( geom.get(), radius, segments, joinStyle3D, &errorMsg );
839 THROW_ON_ERROR( &errorMsg );
840
841 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
842 THROW_ON_ERROR( &errorMsg );
843 return resultGeom;
844}
845
846std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::buffer2D( double radius, int segments, Qgis::JoinStyle joinStyle ) const
847{
848 QString errorMsg;
849 sfcgal::errorHandler()->clearText( &errorMsg );
850
851 sfcgal::shared_geom geom = workingGeom();
852 sfcgal::shared_geom result = QgsSfcgalEngine::buffer2D( geom.get(), radius, segments, joinStyle, &errorMsg );
853 THROW_ON_ERROR( &errorMsg );
854
855 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
856 THROW_ON_ERROR( &errorMsg );
857 return resultGeom;
858}
859
860std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::simplify( double tolerance, bool preserveTopology ) const
861{
862 QString errorMsg;
863 sfcgal::errorHandler()->clearText( &errorMsg );
864
865 sfcgal::shared_geom geom = workingGeom();
866 sfcgal::shared_geom result = QgsSfcgalEngine::simplify( geom.get(), tolerance, preserveTopology, &errorMsg );
867 THROW_ON_ERROR( &errorMsg );
868
869 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
870 THROW_ON_ERROR( &errorMsg );
871 return resultGeom;
872}
873
874std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::extrude( const QgsVector3D &extrusion ) const
875{
876 QString errorMsg;
877 sfcgal::errorHandler()->clearText( &errorMsg );
878
879 sfcgal::shared_geom geom = workingGeom();
880 sfcgal::shared_geom result = QgsSfcgalEngine::extrude( geom.get(), extrusion, &errorMsg );
881 THROW_ON_ERROR( &errorMsg );
882
883 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
884 THROW_ON_ERROR( &errorMsg );
885 return resultGeom;
886}
887
888std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::approximateMedialAxis( bool extendToEdges ) const
889{
890 QString errorMsg;
891 sfcgal::errorHandler()->clearText( &errorMsg );
892
893 sfcgal::shared_geom geom = workingGeom();
894 sfcgal::shared_geom result = QgsSfcgalEngine::approximateMedialAxis( geom.get(), extendToEdges, &errorMsg );
895 THROW_ON_ERROR( &errorMsg );
896
897 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
898 THROW_ON_ERROR( &errorMsg );
899 return resultGeom;
900}
901
902std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::toSolid() const
903{
904 QString errorMsg;
905 sfcgal::errorHandler()->clearText( &errorMsg );
906
907 sfcgal::shared_geom geom = workingGeom();
908 sfcgal::shared_geom solid = QgsSfcgalEngine::toSolid( geom.get(), &errorMsg );
909 THROW_ON_ERROR( &errorMsg );
910
911 std::unique_ptr<QgsSfcgalGeometry> solidGeom = QgsSfcgalEngine::toSfcgalGeometry( solid, &errorMsg );
912 THROW_ON_ERROR( &errorMsg );
913 return solidGeom;
914}
915
916std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::split3D( const QgsPoint &planePoint, const QgsVector3D &planeNormal, bool closeGeometries ) const
917{
918 QString errorMsg;
919 sfcgal::errorHandler()->clearText( &errorMsg );
920
921#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
922 sfcgal::shared_geom geom = workingGeom();
923
924 sfcgal::shared_geom result = QgsSfcgalEngine::split3D( geom.get(), planePoint, planeNormal, closeGeometries );
925 THROW_ON_ERROR( &errorMsg );
926
927 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
928 THROW_ON_ERROR( &errorMsg );
929 return resultGeom;
930#else
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" ) );
935#endif
936}
937
938std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::toPolyhedralSurface() const
939{
940 QString errorMsg;
941 sfcgal::errorHandler()->clearText( &errorMsg );
942
943 sfcgal::shared_geom geom = workingGeom();
944 sfcgal::shared_geom phs = QgsSfcgalEngine::toPolyhedralSurface( geom.get(), &errorMsg );
945 THROW_ON_ERROR( &errorMsg );
946
947 std::unique_ptr<QgsSfcgalGeometry> phsGeom = QgsSfcgalEngine::toSfcgalGeometry( phs, &errorMsg );
948 THROW_ON_ERROR( &errorMsg );
949 return phsGeom;
950}
951
952std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createBox( double sizeX, double sizeY, double sizeZ )
953{
954#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
955 QString errorMsg;
956 sfcgal::errorHandler()->clearText( &errorMsg );
957 sfcgal::shared_prim result = QgsSfcgalEngine::createBox( sizeX, sizeY, sizeZ, &errorMsg );
958 THROW_ON_ERROR( &errorMsg );
959
960 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_BOX, &errorMsg );
961 THROW_ON_ERROR( &errorMsg );
962 return resultGeom;
963#else
964 ( void ) sizeX;
965 ( void ) sizeY;
966 ( void ) sizeZ;
967 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
968#endif
969}
970
971std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCone( double bottomRadius, double height, double topRadius, unsigned int radial )
972{
973#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
974 QString errorMsg;
975 sfcgal::errorHandler()->clearText( &errorMsg );
976 sfcgal::shared_prim result = QgsSfcgalEngine::createCone( bottomRadius, height, topRadius, radial, &errorMsg );
977 THROW_ON_ERROR( &errorMsg );
978
979 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CONE, &errorMsg );
980 THROW_ON_ERROR( &errorMsg );
981 return resultGeom;
982#else
983 ( void ) bottomRadius;
984 ( void ) height;
985 ( void ) topRadius;
986 ( void ) radial;
987 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
988#endif
989}
990
991std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCube( double size )
992{
993#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
994 QString errorMsg;
995 sfcgal::errorHandler()->clearText( &errorMsg );
996 sfcgal::shared_prim result = QgsSfcgalEngine::createCube( size, &errorMsg );
997 THROW_ON_ERROR( &errorMsg );
998
999 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CUBE, &errorMsg );
1000 THROW_ON_ERROR( &errorMsg );
1001 return resultGeom;
1002#else
1003 ( void ) size;
1004 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1005#endif
1006}
1007
1008std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createCylinder( double radius, double height, unsigned int radial )
1009{
1010#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1011 QString errorMsg;
1012 sfcgal::errorHandler()->clearText( &errorMsg );
1013 sfcgal::shared_prim result = QgsSfcgalEngine::createCylinder( radius, height, radial, &errorMsg );
1014 THROW_ON_ERROR( &errorMsg );
1015
1016 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_CYLINDER, &errorMsg );
1017 THROW_ON_ERROR( &errorMsg );
1018 return resultGeom;
1019#else
1020 ( void ) radius;
1021 ( void ) height;
1022 ( void ) radial;
1023 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1024#endif
1025}
1026
1027std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createSphere( double radius, unsigned int subdivisions )
1028{
1029#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1030 QString errorMsg;
1031 sfcgal::errorHandler()->clearText( &errorMsg );
1032 sfcgal::shared_prim result = QgsSfcgalEngine::createSphere( radius, subdivisions, &errorMsg );
1033 THROW_ON_ERROR( &errorMsg );
1034
1035 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_SPHERE, &errorMsg );
1036 THROW_ON_ERROR( &errorMsg );
1037 return resultGeom;
1038#else
1039 ( void ) radius;
1040 ( void ) subdivisions;
1041 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1042#endif
1043}
1044
1045std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::createTorus( double mainRadius, double tubeRadius, unsigned int mainRadial, unsigned int tubeRadial )
1046{
1047#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1048 QString errorMsg;
1049 sfcgal::errorHandler()->clearText( &errorMsg );
1050 sfcgal::shared_prim result = QgsSfcgalEngine::createTorus( mainRadius, tubeRadius, mainRadial, tubeRadial, &errorMsg );
1051 THROW_ON_ERROR( &errorMsg );
1052
1053 auto resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, sfcgal::primitiveType::SFCGAL_TYPE_TORUS, &errorMsg );
1054 THROW_ON_ERROR( &errorMsg );
1055 return resultGeom;
1056#else
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" ) );
1062#endif
1063}
1064
1065std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::primitiveAsPolyhedralSurface() const
1066{
1067#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1068 if ( !mIsPrimitive )
1069 throw QgsSfcgalException( "Need primitive geometry to operate." );
1070
1071 QString errorMsg;
1072 sfcgal::errorHandler()->clearText( &errorMsg );
1073 sfcgal::shared_geom result = QgsSfcgalEngine::primitiveAsPolyhedral( mSfcgalPrim.get(), &errorMsg );
1074 THROW_ON_ERROR( &errorMsg );
1075
1076 std::unique_ptr<QgsSfcgalGeometry> resultGeom = QgsSfcgalEngine::toSfcgalGeometry( result, &errorMsg );
1077 THROW_ON_ERROR( &errorMsg );
1078 return resultGeom;
1079#else
1080 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1081#endif
1082}
1083
1084QgsMatrix4x4 QgsSfcgalGeometry::primitiveTransform() const
1085{
1086#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1087 if ( !mIsPrimitive )
1088 {
1089 throw QgsSfcgalException( "Need primitive geometry to operate." );
1090 }
1091
1092 QString errorMsg;
1093 sfcgal::errorHandler()->clearText( &errorMsg );
1094 double *data = sfcgal_primitive_transformation( mSfcgalPrim.get() );
1095 THROW_ON_ERROR( &errorMsg );
1096
1097 // sfcgal_primitive_transformation returns data in column-major order
1098 // QgsMatrix4x4 constructor expects data in row-major order
1099 // clang-format off
1100 QgsMatrix4x4 transformMatrix(
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]
1105 );
1106 // clang-format on
1107 sfcgal_free_buffer( data );
1108 return transformMatrix;
1109#else
1110 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1111#endif
1112}
1113
1114QList<std::pair<QString, QString>> QgsSfcgalGeometry::primitiveParameters() const
1115{
1116#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1117 if ( !mIsPrimitive )
1118 throw QgsSfcgalException( "Need primitive geometry to operate." );
1119
1120 QString errorMsg;
1121 sfcgal::errorHandler()->clearText( &errorMsg );
1122 QVector<sfcgal::PrimitiveParameterDesc> result = QgsSfcgalEngine::primitiveParameters( mSfcgalPrim.get(), &errorMsg );
1123 THROW_ON_ERROR( &errorMsg );
1124
1125 QList<QPair<QString, QString>> out;
1126 for ( const auto &param : result )
1127 {
1128 out.append( std::pair<QString, QString>( QString::fromStdString( param.name ), QString::fromStdString( param.type ) ) );
1129 }
1130
1131 return out;
1132#else
1133 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1134#endif
1135}
1136
1137QVariant QgsSfcgalGeometry::primitiveParameter( const QString &name ) const
1138{
1139#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1140 if ( !mIsPrimitive )
1141 throw QgsSfcgalException( "Need primitive geometry to operate." );
1142
1143 QString errorMsg;
1144 sfcgal::errorHandler()->clearText( &errorMsg );
1145 QVariant result = QgsSfcgalEngine::primitiveParameter( mSfcgalPrim.get(), name, &errorMsg );
1146 THROW_ON_ERROR( &errorMsg );
1147
1148 return result;
1149#else
1150 ( void ) name;
1151 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1152#endif
1153}
1154
1155void QgsSfcgalGeometry::primitiveSetParameter( const QString &name, const QVariant &value )
1156{
1157#if SFCGAL_VERSION_NUM >= SFCGAL_COMPUTE_VERSION( 2, 3, 0 )
1158 if ( !mIsPrimitive )
1159 throw QgsSfcgalException( "Need primitive geometry to operate." );
1160
1161 QString errorMsg;
1162 sfcgal::errorHandler()->clearText( &errorMsg );
1163 QgsSfcgalEngine::primitiveSetParameter( mSfcgalPrim.get(), name, value, &errorMsg );
1164 THROW_ON_ERROR( &errorMsg );
1165
1166#else
1167 ( void ) name;
1168 ( void ) value;
1169 throw QgsNotSupportedException( QObject::tr( "This operation requires a QGIS build based on SFCGAL 2.3 or later" ) );
1170#endif
1171}
1172
1173#endif
JoinStyle3D
Join styles for 3D buffers.
Definition qgis.h:2307
JoinStyle
Join styles for buffers.
Definition qgis.h:2294
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:314
@ PolyhedralSurfaceZ
PolyhedralSurfaceZ.
Definition qgis.h:346
Abstract base class for all geometries.
QFlags< WkbFlag > WkbFlags
A const WKB pointer.
Definition qgswkbptr.h:211
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.
Definition qgspoint.h:53
Custom exception class for SfCGAL related operations.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33