QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
geometry
qgswkbptr.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgswkbptr.cpp
3
---------------------
4
begin : May 2015
5
copyright : (C) 2015 by Marco Hugentobler
6
email : marco dot hugentobler at sourcepole dot ch
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
#include "
qgswkbptr.h
"
16
17
#include "
qgsapplication.h
"
18
#include "
qgswkbtypes.h
"
19
20
#include <QString>
21
22
using namespace
Qt::StringLiterals;
23
24
QgsWkbPtr::QgsWkbPtr
( QByteArray &wkb )
25
{
26
mP =
reinterpret_cast<
unsigned
char
*
>
( wkb.data() );
27
mStart = mP;
28
mEnd = mP + wkb.length();
29
}
30
31
QgsWkbPtr::QgsWkbPtr
(
unsigned
char
*p,
int
size
)
32
{
33
mP = p;
34
mStart = mP;
35
mEnd = mP +
size
;
36
}
37
38
void
QgsWkbPtr::verifyBound(
int
size )
const
39
{
40
if
( !mP || mP +
size
> mEnd )
41
throw
QgsWkbException
( u
"wkb access out of bounds"
_s );
42
}
43
44
QgsConstWkbPtr::QgsConstWkbPtr
(
const
QByteArray &wkb )
45
{
46
mP
=
reinterpret_cast<
unsigned
char
*
>
(
const_cast<
char
*
>
( wkb.constData() ) );
47
mEnd
=
mP
+ wkb.length();
48
mEndianSwap
=
false
;
49
mWkbType
=
Qgis::WkbType::Unknown
;
50
}
51
52
QgsConstWkbPtr::QgsConstWkbPtr
(
const
unsigned
char
*p,
int
size )
53
{
54
mP
=
const_cast<
unsigned
char
*
>
( p );
55
mEnd
=
mP
+ size;
56
mEndianSwap
=
false
;
57
mWkbType
=
Qgis::WkbType::Unknown
;
58
}
59
60
Qgis::WkbType
QgsConstWkbPtr::readHeader
()
const
61
{
62
if
( !
mP
)
63
return
Qgis::WkbType::Unknown
;
64
65
char
wkbEndian;
66
*
this
>> wkbEndian;
67
mEndianSwap
= wkbEndian !=
QgsApplication::endian
();
68
69
int
wkbType;
70
*
this
>> wkbType;
71
mWkbType
=
static_cast<
Qgis::WkbType
>
( wkbType );
72
73
return
mWkbType
;
74
}
75
76
void
QgsConstWkbPtr::verifyBound
(
int
size )
const
77
{
78
if
( !
mP
||
mP
+ size >
mEnd
)
79
throw
QgsWkbException
( u
"wkb access out of bounds"
_s );
80
}
81
82
const
QgsConstWkbPtr
&
QgsConstWkbPtr::operator>>
( QPointF &point )
const
83
{
84
read
( point.rx() );
85
read
( point.ry() );
86
return
*
this
;
87
}
88
89
const
QgsConstWkbPtr
&
QgsConstWkbPtr::operator>>
( QPolygonF &points )
const
90
{
91
const
int
skipZM = (
QgsWkbTypes::coordDimensions
(
mWkbType
) - 2 ) *
sizeof
(
double
);
92
Q_ASSERT( skipZM >= 0 );
93
94
unsigned
int
nPoints;
95
read
( nPoints );
96
97
points.resize( nPoints );
98
QPointF *ptr = points.data();
99
100
for
(
unsigned
int
i = 0; i < nPoints; ++i, ++ptr )
101
{
102
read
( ptr->rx() );
103
read
( ptr->ry() );
104
mP
+= skipZM;
105
}
106
return
*
this
;
107
}
Qgis::WkbType
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition
qgis.h:314
Qgis::WkbType::Unknown
@ Unknown
Unknown.
Definition
qgis.h:315
QgsApplication::endian
static endian_t endian()
Returns whether this machine uses big or little endian.
Definition
qgsapplication.cpp:1621
QgsConstWkbPtr::QgsConstWkbPtr
QgsConstWkbPtr(const QByteArray &wkb)
Construct WKB pointer from QByteArray.
Definition
qgswkbptr.cpp:44
QgsConstWkbPtr::read
void read(T &v) const
Read a value.
Definition
qgswkbptr.h:228
QgsConstWkbPtr::verifyBound
void verifyBound(int size) const
Verify bounds.
Definition
qgswkbptr.cpp:76
QgsConstWkbPtr::readHeader
Qgis::WkbType readHeader() const
readHeader
Definition
qgswkbptr.cpp:60
QgsConstWkbPtr::operator>>
const QgsConstWkbPtr & operator>>(double &v) const
Definition
qgswkbptr.h:248
QgsConstWkbPtr::mEndianSwap
bool mEndianSwap
Definition
qgswkbptr.h:215
QgsConstWkbPtr::mP
unsigned char * mP
Definition
qgswkbptr.h:213
QgsConstWkbPtr::mWkbType
Qgis::WkbType mWkbType
Definition
qgswkbptr.h:216
QgsConstWkbPtr::mEnd
unsigned char * mEnd
Definition
qgswkbptr.h:214
QgsWkbException
Custom exception class for Wkb related exceptions.
Definition
qgswkbptr.h:32
QgsWkbPtr::size
int size() const
size
Definition
qgswkbptr.h:189
QgsWkbPtr::QgsWkbPtr
QgsWkbPtr(QByteArray &wkb)
Construct WKB pointer from QByteArray.
Definition
qgswkbptr.cpp:24
QgsWkbTypes::coordDimensions
static Q_INVOKABLE int coordDimensions(Qgis::WkbType type)
Returns the coordinate dimension of the geometry type as an integer.
Definition
qgswkbtypes.h:954
qgsapplication.h
qgswkbptr.h
qgswkbtypes.h
Generated on
for QGIS API Documentation by
1.17.0