GDAL

ogr_wkb.h
1/******************************************************************************
2 *
3 * Project: OGR
4 * Purpose: WKB geometry related methods
5 * Author: Even Rouault <even dot rouault at spatialys.com>
6 *
7 ******************************************************************************
8 * Copyright (c) 2022, Even Rouault <even dot rouault at spatialys.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 ****************************************************************************/
28
29#ifndef OGR_WKB_H_INCLUDED
30#define OGR_WKB_H_INCLUDED
31
32#include "cpl_port.h"
33#include "ogr_core.h"
34
35bool CPL_DLL OGRWKBGetGeomType(const GByte *pabyWkb, size_t nWKBSize,
36 bool &bNeedSwap, uint32_t &nType);
37bool OGRWKBPolygonGetArea(const GByte *&pabyWkb, size_t &nWKBSize,
38 double &dfArea);
39bool OGRWKBMultiPolygonGetArea(const GByte *&pabyWkb, size_t &nWKBSize,
40 double &dfArea);
41
42bool CPL_DLL OGRWKBGetBoundingBox(const GByte *pabyWkb, size_t nWKBSize,
43 OGREnvelope3D &sEnvelope);
44
45bool CPL_DLL OGRWKBGetBoundingBox(const GByte *pabyWkb, size_t nWKBSize,
46 OGREnvelope &sEnvelope);
47
48bool CPL_DLL OGRWKBIntersectsPessimistic(const GByte *pabyWkb, size_t nWKBSize,
49 const OGREnvelope &sEnvelope);
50
51void CPL_DLL OGRWKBFixupCounterClockWiseExternalRing(GByte *pabyWkb,
52 size_t nWKBSize);
53
62const GByte CPL_DLL *WKBFromEWKB(GByte *pabyEWKB, size_t nEWKBSize,
63 size_t &nWKBSizeOut, int *pnSRIDOut);
64
65/************************************************************************/
66/* OGRAppendBuffer */
67/************************************************************************/
68
70 class CPL_DLL OGRAppendBuffer
71{
72 public:
74 OGRAppendBuffer();
75
77 virtual ~OGRAppendBuffer();
78
82 inline void *GetPtrForNewBytes(size_t nItemSize)
83 {
84 if (nItemSize > m_nCapacity - m_nSize)
85 {
86 if (!Grow(nItemSize))
87 return nullptr;
88 }
89 void *pRet = static_cast<GByte *>(m_pRawBuffer) + m_nSize;
90 m_nSize += nItemSize;
91 return pRet;
92 }
93
95 inline size_t GetSize() const
96 {
97 return m_nSize;
98 }
99
100 protected:
102 size_t m_nCapacity = 0;
103
105 size_t m_nSize = 0;
106
108 void *m_pRawBuffer = nullptr;
109
113 virtual bool Grow(size_t nItemSize) = 0;
114
115 private:
116 OGRAppendBuffer(const OGRAppendBuffer &) = delete;
117 OGRAppendBuffer &operator=(const OGRAppendBuffer &) = delete;
118};
119
120/************************************************************************/
121/* OGRWKTToWKBTranslator */
122/************************************************************************/
123
125 class CPL_DLL OGRWKTToWKBTranslator
126{
127 OGRAppendBuffer &m_oAppendBuffer;
128 bool m_bCanUseStrtod = false;
129
130 public:
132 explicit OGRWKTToWKBTranslator(OGRAppendBuffer &oAppendBuffer);
133
141 size_t TranslateWKT(void *pabyWKTStart, size_t nLength,
142 bool bCanAlterByteAfter);
143};
144
145#endif // OGR_WKB_H_INCLUDED
OGRAppendBuffer
Append buffer that can be grown dynamically.
Definition: ogr_wkb.h:71
OGRAppendBuffer::GetSize
size_t GetSize() const
Return the number of valid bytes in the buffer.
Definition: ogr_wkb.h:95
OGRAppendBuffer::GetPtrForNewBytes
void * GetPtrForNewBytes(size_t nItemSize)
Return the pointer at which nItemSize bytes can be written, or nullptr in case of error.
Definition: ogr_wkb.h:82
OGRAppendBuffer::Grow
virtual bool Grow(size_t nItemSize)=0
Extend the capacity of m_pRawBuffer to be at least m_nSize + nItemSize large.
OGRAppendBuffer::~OGRAppendBuffer
virtual ~OGRAppendBuffer()
Destructor.
OGRAppendBuffer::OGRAppendBuffer
OGRAppendBuffer()
Constructor.
OGREnvelope3D
Simple container for a bounding region in 3D.
Definition: ogr_core.h:216
OGREnvelope
Simple container for a bounding region (rectangle)
Definition: ogr_core.h:61
OGRWKTToWKBTranslator
Translate WKT geometry to WKB geometry and append it to a buffer.
Definition: ogr_wkb.h:126
cpl_port.h
Core portability definitions for CPL.
GByte
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:185
ogr_core.h
Core portability services for cross-platform OGR code.