forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathogr_geometry.h
4048 lines (3499 loc) · 130 KB
/
ogr_geometry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
* $Id$
*
* Project: OpenGIS Simple Features Reference Implementation
* Purpose: Classes for manipulating simple features that is not specific
* to a particular interface technology.
* Author: Frank Warmerdam, [email protected]
*
******************************************************************************
* Copyright (c) 1999, Frank Warmerdam
* Copyright (c) 2008-2014, Even Rouault <even dot rouault at spatialys.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
#ifndef OGR_GEOMETRY_H_INCLUDED
#define OGR_GEOMETRY_H_INCLUDED
#include "cpl_conv.h"
#include "cpl_json.h"
#include "ogr_core.h"
#include "ogr_spatialref.h"
#include <cmath>
#include <memory>
/**
* \file ogr_geometry.h
*
* Simple feature geometry classes.
*/
/*! @cond Doxygen_Suppress */
#ifndef DEFINEH_OGRGeometryH
#define DEFINEH_OGRGeometryH
#ifdef DEBUG
typedef struct OGRGeometryHS *OGRGeometryH;
#else
typedef void *OGRGeometryH;
#endif
#endif /* DEFINEH_OGRGeometryH */
/*! @endcond */
/// WKT Output formatting options.
enum class OGRWktFormat
{
F, ///< F-type formatting.
G, ///< G-type formatting.
Default ///< Format as F when abs(value) < 1, otherwise as G.
};
/// Options for formatting WKT output
struct CPL_DLL OGRWktOptions
{
public:
/// Type of WKT output to produce.
OGRwkbVariant variant;
/// Precision of output. Interpretation depends on \c format.
int precision;
/// Whether GDAL-special rounding should be applied.
bool round;
/// Formatting type.
OGRWktFormat format;
/// Constructor.
OGRWktOptions()
: variant(wkbVariantOldOgc), precision(15), round(true),
format(OGRWktFormat::Default)
{
static int defPrecision = getDefaultPrecision();
static bool defRound = getDefaultRound();
precision = defPrecision;
round = defRound;
}
/// Copy constructor
OGRWktOptions(const OGRWktOptions &) = default;
private:
static int getDefaultPrecision();
static bool getDefaultRound();
};
/**
* Simple container for a position.
*/
class OGRRawPoint
{
public:
/** Constructor */
OGRRawPoint() : x(0.0), y(0.0)
{
}
/** Constructor */
OGRRawPoint(double xIn, double yIn) : x(xIn), y(yIn)
{
}
/** x */
double x;
/** y */
double y;
};
/** GEOS geometry type */
typedef struct GEOSGeom_t *GEOSGeom;
/** GEOS context handle type */
typedef struct GEOSContextHandle_HS *GEOSContextHandle_t;
/** SFCGAL geometry type */
typedef void sfcgal_geometry_t;
class OGRPoint;
class OGRCurve;
class OGRCompoundCurve;
class OGRSimpleCurve;
class OGRLinearRing;
class OGRLineString;
class OGRCircularString;
class OGRSurface;
class OGRCurvePolygon;
class OGRPolygon;
class OGRMultiPoint;
class OGRMultiSurface;
class OGRMultiPolygon;
class OGRMultiCurve;
class OGRMultiLineString;
class OGRGeometryCollection;
class OGRTriangle;
class OGRPolyhedralSurface;
class OGRTriangulatedSurface;
//! @cond Doxygen_Suppress
typedef OGRLineString *(*OGRCurveCasterToLineString)(OGRCurve *);
typedef OGRLinearRing *(*OGRCurveCasterToLinearRing)(OGRCurve *);
typedef OGRPolygon *(*OGRSurfaceCasterToPolygon)(OGRSurface *);
typedef OGRCurvePolygon *(*OGRSurfaceCasterToCurvePolygon)(OGRSurface *);
typedef OGRMultiPolygon *(*OGRPolyhedralSurfaceCastToMultiPolygon)(
OGRPolyhedralSurface *);
//! @endcond
/** OGRGeometry visitor interface.
* @since GDAL 2.3
*/
class CPL_DLL IOGRGeometryVisitor
{
public:
/** Destructor/ */
virtual ~IOGRGeometryVisitor() = default;
/** Visit OGRPoint. */
virtual void visit(OGRPoint *) = 0;
/** Visit OGRLineString. */
virtual void visit(OGRLineString *) = 0;
/** Visit OGRLinearRing. */
virtual void visit(OGRLinearRing *) = 0;
/** Visit OGRPolygon. */
virtual void visit(OGRPolygon *) = 0;
/** Visit OGRMultiPoint. */
virtual void visit(OGRMultiPoint *) = 0;
/** Visit OGRMultiLineString. */
virtual void visit(OGRMultiLineString *) = 0;
/** Visit OGRMultiPolygon. */
virtual void visit(OGRMultiPolygon *) = 0;
/** Visit OGRGeometryCollection. */
virtual void visit(OGRGeometryCollection *) = 0;
/** Visit OGRCircularString. */
virtual void visit(OGRCircularString *) = 0;
/** Visit OGRCompoundCurve. */
virtual void visit(OGRCompoundCurve *) = 0;
/** Visit OGRCurvePolygon. */
virtual void visit(OGRCurvePolygon *) = 0;
/** Visit OGRMultiCurve. */
virtual void visit(OGRMultiCurve *) = 0;
/** Visit OGRMultiSurface. */
virtual void visit(OGRMultiSurface *) = 0;
/** Visit OGRTriangle. */
virtual void visit(OGRTriangle *) = 0;
/** Visit OGRPolyhedralSurface. */
virtual void visit(OGRPolyhedralSurface *) = 0;
/** Visit OGRTriangulatedSurface. */
virtual void visit(OGRTriangulatedSurface *) = 0;
};
/** OGRGeometry visitor default implementation.
*
* This default implementation will recurse down to calling
* visit(OGRPoint*) on each point.
*
* @since GDAL 2.3
*/
class CPL_DLL OGRDefaultGeometryVisitor : public IOGRGeometryVisitor
{
void _visit(OGRSimpleCurve *poGeom);
public:
void visit(OGRPoint *) override
{
}
void visit(OGRLineString *) override;
void visit(OGRLinearRing *) override;
void visit(OGRPolygon *) override;
void visit(OGRMultiPoint *) override;
void visit(OGRMultiLineString *) override;
void visit(OGRMultiPolygon *) override;
void visit(OGRGeometryCollection *) override;
void visit(OGRCircularString *) override;
void visit(OGRCompoundCurve *) override;
void visit(OGRCurvePolygon *) override;
void visit(OGRMultiCurve *) override;
void visit(OGRMultiSurface *) override;
void visit(OGRTriangle *) override;
void visit(OGRPolyhedralSurface *) override;
void visit(OGRTriangulatedSurface *) override;
};
/** OGRGeometry visitor interface.
* @since GDAL 2.3
*/
class CPL_DLL IOGRConstGeometryVisitor
{
public:
/** Destructor/ */
virtual ~IOGRConstGeometryVisitor() = default;
/** Visit OGRPoint. */
virtual void visit(const OGRPoint *) = 0;
/** Visit OGRLineString. */
virtual void visit(const OGRLineString *) = 0;
/** Visit OGRLinearRing. */
virtual void visit(const OGRLinearRing *) = 0;
/** Visit OGRPolygon. */
virtual void visit(const OGRPolygon *) = 0;
/** Visit OGRMultiPoint. */
virtual void visit(const OGRMultiPoint *) = 0;
/** Visit OGRMultiLineString. */
virtual void visit(const OGRMultiLineString *) = 0;
/** Visit OGRMultiPolygon. */
virtual void visit(const OGRMultiPolygon *) = 0;
/** Visit OGRGeometryCollection. */
virtual void visit(const OGRGeometryCollection *) = 0;
/** Visit OGRCircularString. */
virtual void visit(const OGRCircularString *) = 0;
/** Visit OGRCompoundCurve. */
virtual void visit(const OGRCompoundCurve *) = 0;
/** Visit OGRCurvePolygon. */
virtual void visit(const OGRCurvePolygon *) = 0;
/** Visit OGRMultiCurve. */
virtual void visit(const OGRMultiCurve *) = 0;
/** Visit OGRMultiSurface. */
virtual void visit(const OGRMultiSurface *) = 0;
/** Visit OGRTriangle. */
virtual void visit(const OGRTriangle *) = 0;
/** Visit OGRPolyhedralSurface. */
virtual void visit(const OGRPolyhedralSurface *) = 0;
/** Visit OGRTriangulatedSurface. */
virtual void visit(const OGRTriangulatedSurface *) = 0;
};
/** OGRGeometry visitor default implementation.
*
* This default implementation will recurse down to calling
* visit(const OGRPoint*) on each point.
*
* @since GDAL 2.3
*/
class CPL_DLL OGRDefaultConstGeometryVisitor : public IOGRConstGeometryVisitor
{
void _visit(const OGRSimpleCurve *poGeom);
public:
void visit(const OGRPoint *) override
{
}
void visit(const OGRLineString *) override;
void visit(const OGRLinearRing *) override;
void visit(const OGRPolygon *) override;
void visit(const OGRMultiPoint *) override;
void visit(const OGRMultiLineString *) override;
void visit(const OGRMultiPolygon *) override;
void visit(const OGRGeometryCollection *) override;
void visit(const OGRCircularString *) override;
void visit(const OGRCompoundCurve *) override;
void visit(const OGRCurvePolygon *) override;
void visit(const OGRMultiCurve *) override;
void visit(const OGRMultiSurface *) override;
void visit(const OGRTriangle *) override;
void visit(const OGRPolyhedralSurface *) override;
void visit(const OGRTriangulatedSurface *) override;
};
/************************************************************************/
/* OGRGeometry */
/************************************************************************/
/**
* Abstract base class for all geometry classes.
*
* Some spatial analysis methods require that OGR is built on the GEOS library
* to work properly. The precise meaning of methods that describe spatial
* relationships between geometries is described in the SFCOM, or other simple
* features interface specifications, like "OpenGIS® Implementation
* Specification for Geographic information - Simple feature access - Part 1:
* Common architecture":
* <a href="http://www.opengeospatial.org/standards/sfa">OGC 06-103r4</a>
*
* In GDAL 2.0, the hierarchy of classes has been extended with
* <a href="https://portal.opengeospatial.org/files/?artifact_id=32024">
* (working draft) ISO SQL/MM Part 3 (ISO/IEC 13249-3)</a> curve geometries :
* CIRCULARSTRING (OGRCircularString), COMPOUNDCURVE (OGRCompoundCurve),
* CURVEPOLYGON (OGRCurvePolygon), MULTICURVE (OGRMultiCurve) and
* MULTISURFACE (OGRMultiSurface).
*
*/
class CPL_DLL OGRGeometry
{
private:
OGRSpatialReference *poSRS = nullptr; // may be NULL
protected:
//! @cond Doxygen_Suppress
friend class OGRCurveCollection;
unsigned int flags = 0;
OGRErr importPreambleFromWkt(const char **ppszInput, int *pbHasZ,
int *pbHasM, bool *pbIsEmpty);
OGRErr importCurveCollectionFromWkt(
const char **ppszInput, int bAllowEmptyComponent, int bAllowLineString,
int bAllowCurve, int bAllowCompoundCurve,
OGRErr (*pfnAddCurveDirectly)(OGRGeometry *poSelf, OGRCurve *poCurve));
OGRErr importPreambleFromWkb(const unsigned char *pabyData, size_t nSize,
OGRwkbByteOrder &eByteOrder,
OGRwkbVariant eWkbVariant);
OGRErr importPreambleOfCollectionFromWkb(const unsigned char *pabyData,
size_t &nSize, size_t &nDataOffset,
OGRwkbByteOrder &eByteOrder,
size_t nMinSubGeomSize,
int &nGeomCount,
OGRwkbVariant eWkbVariant);
OGRErr PointOnSurfaceInternal(OGRPoint *poPoint) const;
OGRBoolean IsSFCGALCompatible() const;
void HomogenizeDimensionalityWith(OGRGeometry *poOtherGeom);
std::string wktTypeString(OGRwkbVariant variant) const;
//! @endcond
public:
/************************************************************************/
/* Bit flags for OGRGeometry */
/* The OGR_G_NOT_EMPTY_POINT is used *only* for points. */
/* Do not use these outside of the core. */
/* Use Is3D, IsMeasured, set3D, and setMeasured instead */
/************************************************************************/
//! @cond Doxygen_Suppress
static const unsigned int OGR_G_NOT_EMPTY_POINT = 0x1;
static const unsigned int OGR_G_3D = 0x2;
static const unsigned int OGR_G_MEASURED = 0x4;
//! @endcond
OGRGeometry();
OGRGeometry(const OGRGeometry &other);
virtual ~OGRGeometry();
OGRGeometry &operator=(const OGRGeometry &other);
/** Returns if two geometries are equal. */
bool operator==(const OGRGeometry &other) const
{
return CPL_TO_BOOL(Equals(&other));
}
/** Returns if two geometries are different. */
bool operator!=(const OGRGeometry &other) const
{
return !CPL_TO_BOOL(Equals(&other));
}
// Standard IGeometry.
virtual int getDimension() const = 0;
virtual int getCoordinateDimension() const;
int CoordinateDimension() const;
virtual OGRBoolean IsEmpty() const = 0;
virtual OGRBoolean IsValid() const;
virtual OGRGeometry *MakeValid(CSLConstList papszOptions = nullptr) const;
virtual OGRGeometry *Normalize() const;
virtual OGRBoolean IsSimple() const;
/*! Returns whether the geometry has a Z component. */
OGRBoolean Is3D() const
{
return (flags & OGR_G_3D) != 0;
}
/*! Returns whether the geometry has a M component. */
OGRBoolean IsMeasured() const
{
return (flags & OGR_G_MEASURED) != 0;
}
virtual OGRBoolean IsRing() const;
virtual void empty() = 0;
virtual OGRGeometry *clone() const CPL_WARN_UNUSED_RESULT = 0;
virtual void getEnvelope(OGREnvelope *psEnvelope) const = 0;
virtual void getEnvelope(OGREnvelope3D *psEnvelope) const = 0;
// IWks Interface.
virtual size_t WkbSize() const = 0;
OGRErr importFromWkb(const GByte *, size_t = static_cast<size_t>(-1),
OGRwkbVariant = wkbVariantOldOgc);
virtual OGRErr importFromWkb(const unsigned char *, size_t, OGRwkbVariant,
size_t &nBytesConsumedOut) = 0;
virtual OGRErr exportToWkb(OGRwkbByteOrder, unsigned char *,
OGRwkbVariant = wkbVariantOldOgc) const = 0;
virtual OGRErr importFromWkt(const char **ppszInput) = 0;
#ifndef DOXYGEN_XML
/** Deprecated.
* @deprecated in GDAL 2.3
*/
OGRErr importFromWkt(char **ppszInput)
/*! @cond Doxygen_Suppress */
CPL_WARN_DEPRECATED("Use importFromWkt(const char**) instead")
/*! @endcond */
{
return importFromWkt(const_cast<const char **>(ppszInput));
}
#endif
OGRErr exportToWkt(char **ppszDstText,
OGRwkbVariant = wkbVariantOldOgc) const;
/// Export a WKT geometry.
/// \param opts Output options.
/// \param err Pointer to error code, if desired.
/// \return WKT string representing this geometry.
virtual std::string exportToWkt(const OGRWktOptions &opts = OGRWktOptions(),
OGRErr *err = nullptr) const = 0;
// Non-standard.
virtual OGRwkbGeometryType getGeometryType() const = 0;
OGRwkbGeometryType getIsoGeometryType() const;
virtual const char *getGeometryName() const = 0;
void dumpReadable(FILE *, const char * = nullptr,
CSLConstList papszOptions = nullptr) const;
std::string dumpReadable(const char * = nullptr,
CSLConstList papszOptions = nullptr) const;
virtual void flattenTo2D() = 0;
virtual char *exportToGML(const char *const *papszOptions = nullptr) const;
virtual char *exportToKML() const;
virtual char *exportToJson() const;
/** Accept a visitor. */
virtual void accept(IOGRGeometryVisitor *visitor) = 0;
/** Accept a visitor. */
virtual void accept(IOGRConstGeometryVisitor *visitor) const = 0;
static GEOSContextHandle_t createGEOSContext();
static void freeGEOSContext(GEOSContextHandle_t hGEOSCtxt);
virtual GEOSGeom
exportToGEOS(GEOSContextHandle_t hGEOSCtxt) const CPL_WARN_UNUSED_RESULT;
virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
virtual OGRGeometry *getCurveGeometry(
const char *const *papszOptions = nullptr) const CPL_WARN_UNUSED_RESULT;
virtual OGRGeometry *getLinearGeometry(
double dfMaxAngleStepSizeDegrees = 0,
const char *const *papszOptions = nullptr) const CPL_WARN_UNUSED_RESULT;
// SFCGAL interfacing methods.
//! @cond Doxygen_Suppress
static sfcgal_geometry_t *OGRexportToSFCGAL(const OGRGeometry *poGeom);
static OGRGeometry *SFCGALexportToOGR(const sfcgal_geometry_t *_geometry);
//! @endcond
virtual void closeRings();
virtual void setCoordinateDimension(int nDimension);
virtual void set3D(OGRBoolean bIs3D);
virtual void setMeasured(OGRBoolean bIsMeasured);
virtual void assignSpatialReference(OGRSpatialReference *poSR);
OGRSpatialReference *getSpatialReference(void) const
{
return poSRS;
}
virtual OGRErr transform(OGRCoordinateTransformation *poCT) = 0;
OGRErr transformTo(OGRSpatialReference *poSR);
virtual void segmentize(double dfMaxLength);
// ISpatialRelation
virtual OGRBoolean Intersects(const OGRGeometry *) const;
virtual OGRBoolean Equals(const OGRGeometry *) const = 0;
virtual OGRBoolean Disjoint(const OGRGeometry *) const;
virtual OGRBoolean Touches(const OGRGeometry *) const;
virtual OGRBoolean Crosses(const OGRGeometry *) const;
virtual OGRBoolean Within(const OGRGeometry *) const;
virtual OGRBoolean Contains(const OGRGeometry *) const;
virtual OGRBoolean Overlaps(const OGRGeometry *) const;
// virtual OGRBoolean Relate( const OGRGeometry *, const char * ) const;
// virtual OGRGeometry *LocateAlong( double mValue ) const;
// virtual OGRGeometry *LocateBetween( double mStart, double mEnd )
// const;
virtual OGRGeometry *Boundary() const CPL_WARN_UNUSED_RESULT;
virtual double Distance(const OGRGeometry *) const;
virtual OGRGeometry *ConvexHull() const CPL_WARN_UNUSED_RESULT;
virtual OGRGeometry *
ConcaveHull(double dfRatio, bool bAllowHoles) const CPL_WARN_UNUSED_RESULT;
virtual OGRGeometry *
Buffer(double dfDist, int nQuadSegs = 30) const CPL_WARN_UNUSED_RESULT;
virtual OGRGeometry *
Intersection(const OGRGeometry *) const CPL_WARN_UNUSED_RESULT;
virtual OGRGeometry *
Union(const OGRGeometry *) const CPL_WARN_UNUSED_RESULT;
virtual OGRGeometry *UnionCascaded() const CPL_WARN_UNUSED_RESULT;
virtual OGRGeometry *
Difference(const OGRGeometry *) const CPL_WARN_UNUSED_RESULT;
virtual OGRGeometry *
SymDifference(const OGRGeometry *) const CPL_WARN_UNUSED_RESULT;
virtual OGRErr Centroid(OGRPoint *poPoint) const;
virtual OGRGeometry *
Simplify(double dTolerance) const CPL_WARN_UNUSED_RESULT;
OGRGeometry *
SimplifyPreserveTopology(double dTolerance) const CPL_WARN_UNUSED_RESULT;
virtual OGRGeometry *
DelaunayTriangulation(double dfTolerance,
int bOnlyEdges) const CPL_WARN_UNUSED_RESULT;
virtual OGRGeometry *Polygonize() const CPL_WARN_UNUSED_RESULT;
virtual double Distance3D(const OGRGeometry *poOtherGeom) const;
//! @cond Doxygen_Suppress
// backward compatibility to non-standard method names.
OGRBoolean Intersect(OGRGeometry *) const
CPL_WARN_DEPRECATED("Non standard method. "
"Use Intersects() instead");
OGRBoolean Equal(OGRGeometry *) const
CPL_WARN_DEPRECATED("Non standard method. "
"Use Equals() instead");
OGRGeometry *SymmetricDifference(const OGRGeometry *) const
CPL_WARN_DEPRECATED("Non standard method. "
"Use SymDifference() instead");
OGRGeometry *getBoundary() const
CPL_WARN_DEPRECATED("Non standard method. "
"Use Boundary() instead");
//! @endcond
//! @cond Doxygen_Suppress
// Special HACK for DB2 7.2 support
static int bGenerate_DB2_V72_BYTE_ORDER;
//! @endcond
virtual void swapXY();
//! @cond Doxygen_Suppress
static OGRGeometry *CastToIdentity(OGRGeometry *poGeom)
{
return poGeom;
}
static OGRGeometry *CastToError(OGRGeometry *poGeom);
//! @endcond
/** Convert a OGRGeometry* to a OGRGeometryH.
* @since GDAL 2.3
*/
static inline OGRGeometryH ToHandle(OGRGeometry *poGeom)
{
return reinterpret_cast<OGRGeometryH>(poGeom);
}
/** Convert a OGRGeometryH to a OGRGeometry*.
* @since GDAL 2.3
*/
static inline OGRGeometry *FromHandle(OGRGeometryH hGeom)
{
return reinterpret_cast<OGRGeometry *>(hGeom);
}
/** Down-cast to OGRPoint*.
* Implies prior checking that wkbFlatten(getGeometryType()) == wkbPoint.
* @since GDAL 2.3
*/
inline OGRPoint *toPoint()
{
return cpl::down_cast<OGRPoint *>(this);
}
/** Down-cast to OGRPoint*.
* Implies prior checking that wkbFlatten(getGeometryType()) == wkbPoint.
* @since GDAL 2.3
*/
inline const OGRPoint *toPoint() const
{
return cpl::down_cast<const OGRPoint *>(this);
}
/** Down-cast to OGRCurve*.
* Implies prior checking that OGR_GT_IsSubClass(getGeometryType(),
* wkbCurve).
* @since GDAL 2.3
*/
inline OGRCurve *toCurve()
{
return cpl::down_cast<OGRCurve *>(this);
}
/** Down-cast to OGRCurve*.
* Implies prior checking that OGR_GT_IsSubClass(getGeometryType(),
* wkbCurve).
* @since GDAL 2.3
*/
inline const OGRCurve *toCurve() const
{
return cpl::down_cast<const OGRCurve *>(this);
}
/** Down-cast to OGRSimpleCurve*.
* Implies prior checking that getGeometryType() is wkbLineString,
* wkbCircularString or a derived type.
* @since GDAL 2.3
*/
inline OGRSimpleCurve *toSimpleCurve()
{
return cpl::down_cast<OGRSimpleCurve *>(this);
}
/** Down-cast to OGRSimpleCurve*.
* Implies prior checking that getGeometryType() is wkbLineString,
* wkbCircularString or a derived type.
* @since GDAL 2.3
*/
inline const OGRSimpleCurve *toSimpleCurve() const
{
return cpl::down_cast<const OGRSimpleCurve *>(this);
}
/** Down-cast to OGRLineString*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbLineString.
* @since GDAL 2.3
*/
inline OGRLineString *toLineString()
{
return cpl::down_cast<OGRLineString *>(this);
}
/** Down-cast to OGRLineString*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbLineString.
* @since GDAL 2.3
*/
inline const OGRLineString *toLineString() const
{
return cpl::down_cast<const OGRLineString *>(this);
}
/** Down-cast to OGRLinearRing*.
* Implies prior checking that EQUAL(getGeometryName(), "LINEARRING").
* @since GDAL 2.3
*/
inline OGRLinearRing *toLinearRing()
{
return cpl::down_cast<OGRLinearRing *>(this);
}
/** Down-cast to OGRLinearRing*.
* Implies prior checking that EQUAL(getGeometryName(), "LINEARRING").
* @since GDAL 2.3
*/
inline const OGRLinearRing *toLinearRing() const
{
return cpl::down_cast<const OGRLinearRing *>(this);
}
/** Down-cast to OGRCircularString*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbCircularString.
* @since GDAL 2.3
*/
inline OGRCircularString *toCircularString()
{
return cpl::down_cast<OGRCircularString *>(this);
}
/** Down-cast to OGRCircularString*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbCircularString.
* @since GDAL 2.3
*/
inline const OGRCircularString *toCircularString() const
{
return cpl::down_cast<const OGRCircularString *>(this);
}
/** Down-cast to OGRCompoundCurve*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbCompoundCurve.
* @since GDAL 2.3
*/
inline OGRCompoundCurve *toCompoundCurve()
{
return cpl::down_cast<OGRCompoundCurve *>(this);
}
/** Down-cast to OGRCompoundCurve*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbCompoundCurve.
* @since GDAL 2.3
*/
inline const OGRCompoundCurve *toCompoundCurve() const
{
return cpl::down_cast<const OGRCompoundCurve *>(this);
}
/** Down-cast to OGRSurface*.
* Implies prior checking that OGR_GT_IsSubClass(getGeometryType(),
* wkbSurface).
* @since GDAL 2.3
*/
inline OGRSurface *toSurface()
{
return cpl::down_cast<OGRSurface *>(this);
}
/** Down-cast to OGRSurface*.
* Implies prior checking that OGR_GT_IsSubClass(getGeometryType(),
* wkbSurface).
* @since GDAL 2.3
*/
inline const OGRSurface *toSurface() const
{
return cpl::down_cast<const OGRSurface *>(this);
}
/** Down-cast to OGRPolygon*.
* Implies prior checking that wkbFlatten(getGeometryType()) == wkbPolygon
* or wkbTriangle.
* @since GDAL 2.3
*/
inline OGRPolygon *toPolygon()
{
return cpl::down_cast<OGRPolygon *>(this);
}
/** Down-cast to OGRPolygon*.
* Implies prior checking that wkbFlatten(getGeometryType()) == wkbPolygon
* or wkbTriangle.
* @since GDAL 2.3
*/
inline const OGRPolygon *toPolygon() const
{
return cpl::down_cast<const OGRPolygon *>(this);
}
/** Down-cast to OGRTriangle*.
* Implies prior checking that wkbFlatten(getGeometryType()) == wkbTriangle.
* @since GDAL 2.3
*/
inline OGRTriangle *toTriangle()
{
return cpl::down_cast<OGRTriangle *>(this);
}
/** Down-cast to OGRTriangle*.
* Implies prior checking that wkbFlatten(getGeometryType()) == wkbTriangle.
* @since GDAL 2.3
*/
inline const OGRTriangle *toTriangle() const
{
return cpl::down_cast<const OGRTriangle *>(this);
}
/** Down-cast to OGRCurvePolygon*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbCurvePolygon or wkbPolygon or wkbTriangle.
* @since GDAL 2.3
*/
inline OGRCurvePolygon *toCurvePolygon()
{
return cpl::down_cast<OGRCurvePolygon *>(this);
}
/** Down-cast to OGRCurvePolygon*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbCurvePolygon or wkbPolygon or wkbTriangle.
* @since GDAL 2.3
*/
inline const OGRCurvePolygon *toCurvePolygon() const
{
return cpl::down_cast<const OGRCurvePolygon *>(this);
}
/** Down-cast to OGRGeometryCollection*.
* Implies prior checking that OGR_GT_IsSubClass(getGeometryType(),
* wkbGeometryCollection).
* @since GDAL 2.3
*/
inline OGRGeometryCollection *toGeometryCollection()
{
return cpl::down_cast<OGRGeometryCollection *>(this);
}
/** Down-cast to OGRGeometryCollection*.
* Implies prior checking that OGR_GT_IsSubClass(getGeometryType(),
* wkbGeometryCollection).
* @since GDAL 2.3
*/
inline const OGRGeometryCollection *toGeometryCollection() const
{
return cpl::down_cast<const OGRGeometryCollection *>(this);
}
/** Down-cast to OGRMultiPoint*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbMultiPoint.
* @since GDAL 2.3
*/
inline OGRMultiPoint *toMultiPoint()
{
return cpl::down_cast<OGRMultiPoint *>(this);
}
/** Down-cast to OGRMultiPoint*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbMultiPoint.
* @since GDAL 2.3
*/
inline const OGRMultiPoint *toMultiPoint() const
{
return cpl::down_cast<const OGRMultiPoint *>(this);
}
/** Down-cast to OGRMultiLineString*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbMultiLineString.
* @since GDAL 2.3
*/
inline OGRMultiLineString *toMultiLineString()
{
return cpl::down_cast<OGRMultiLineString *>(this);
}
/** Down-cast to OGRMultiLineString*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbMultiLineString.
* @since GDAL 2.3
*/
inline const OGRMultiLineString *toMultiLineString() const
{
return cpl::down_cast<const OGRMultiLineString *>(this);
}
/** Down-cast to OGRMultiPolygon*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbMultiPolygon.
* @since GDAL 2.3
*/
inline OGRMultiPolygon *toMultiPolygon()
{
return cpl::down_cast<OGRMultiPolygon *>(this);
}
/** Down-cast to OGRMultiPolygon*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbMultiPolygon.
* @since GDAL 2.3
*/
inline const OGRMultiPolygon *toMultiPolygon() const
{
return cpl::down_cast<const OGRMultiPolygon *>(this);
}
/** Down-cast to OGRMultiCurve*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbMultiCurve and derived types.
* @since GDAL 2.3
*/
inline OGRMultiCurve *toMultiCurve()
{
return cpl::down_cast<OGRMultiCurve *>(this);
}
/** Down-cast to OGRMultiCurve*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbMultiCurve and derived types.
* @since GDAL 2.3
*/
inline const OGRMultiCurve *toMultiCurve() const
{
return cpl::down_cast<const OGRMultiCurve *>(this);
}
/** Down-cast to OGRMultiSurface*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbMultiSurface and derived types.
* @since GDAL 2.3
*/
inline OGRMultiSurface *toMultiSurface()
{
return cpl::down_cast<OGRMultiSurface *>(this);
}
/** Down-cast to OGRMultiSurface*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbMultiSurface and derived types.
* @since GDAL 2.3
*/
inline const OGRMultiSurface *toMultiSurface() const
{
return cpl::down_cast<const OGRMultiSurface *>(this);
}
/** Down-cast to OGRPolyhedralSurface*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbPolyhedralSurface or wkbTIN.
* @since GDAL 2.3
*/
inline OGRPolyhedralSurface *toPolyhedralSurface()
{
return cpl::down_cast<OGRPolyhedralSurface *>(this);
}
/** Down-cast to OGRPolyhedralSurface*.
* Implies prior checking that wkbFlatten(getGeometryType()) ==
* wkbPolyhedralSurface or wkbTIN.
* @since GDAL 2.3
*/
inline const OGRPolyhedralSurface *toPolyhedralSurface() const
{
return cpl::down_cast<const OGRPolyhedralSurface *>(this);
}
/** Down-cast to OGRTriangulatedSurface*.
* Implies prior checking that wkbFlatten(getGeometryType()) == wkbTIN.
* @since GDAL 2.3
*/
inline OGRTriangulatedSurface *toTriangulatedSurface()
{
return cpl::down_cast<OGRTriangulatedSurface *>(this);
}
/** Down-cast to OGRTriangulatedSurface*.
* Implies prior checking that wkbFlatten(getGeometryType()) == wkbTIN.
* @since GDAL 2.3
*/
inline const OGRTriangulatedSurface *toTriangulatedSurface() const
{
return cpl::down_cast<const OGRTriangulatedSurface *>(this);
}
};
//! @cond Doxygen_Suppress
struct CPL_DLL OGRGeometryUniquePtrDeleter
{
void operator()(OGRGeometry *) const;
};
//! @endcond
/** Unique pointer type for OGRGeometry.
* @since GDAL 2.3
*/
typedef std::unique_ptr<OGRGeometry, OGRGeometryUniquePtrDeleter>
OGRGeometryUniquePtr;
//! @cond Doxygen_Suppress
#define OGR_FORBID_DOWNCAST_TO(name) \
inline OGR##name *to##name() = delete; \
inline const OGR##name *to##name() const = delete;
#define OGR_FORBID_DOWNCAST_TO_POINT OGR_FORBID_DOWNCAST_TO(Point)
#define OGR_FORBID_DOWNCAST_TO_CURVE OGR_FORBID_DOWNCAST_TO(Curve)
#define OGR_FORBID_DOWNCAST_TO_SIMPLE_CURVE OGR_FORBID_DOWNCAST_TO(SimpleCurve)
#define OGR_FORBID_DOWNCAST_TO_LINESTRING OGR_FORBID_DOWNCAST_TO(LineString)
#define OGR_FORBID_DOWNCAST_TO_LINEARRING OGR_FORBID_DOWNCAST_TO(LinearRing)
#define OGR_FORBID_DOWNCAST_TO_CIRCULARSTRING \
OGR_FORBID_DOWNCAST_TO(CircularString)
#define OGR_FORBID_DOWNCAST_TO_COMPOUNDCURVE \
OGR_FORBID_DOWNCAST_TO(CompoundCurve)
#define OGR_FORBID_DOWNCAST_TO_SURFACE OGR_FORBID_DOWNCAST_TO(Surface)
#define OGR_FORBID_DOWNCAST_TO_CURVEPOLYGON OGR_FORBID_DOWNCAST_TO(CurvePolygon)