QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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
20QgsWkbPtr::QgsWkbPtr( QByteArray &wkb )
21{
22 mP = reinterpret_cast<unsigned char *>( wkb.data() );
23 mStart = mP;
24 mEnd = mP + wkb.length();
25}
26
27QgsWkbPtr::QgsWkbPtr( unsigned char *p, int size )
28{
29 mP = p;
30 mStart = mP;
31 mEnd = mP + size;
32}
33
34void QgsWkbPtr::verifyBound( int size ) const
35{
36 if ( !mP || mP + size > mEnd )
37 throw QgsWkbException( QStringLiteral( "wkb access out of bounds" ) );
38}
39
40QgsConstWkbPtr::QgsConstWkbPtr( const QByteArray &wkb )
41{
42 mP = reinterpret_cast< unsigned char * >( const_cast<char *>( wkb.constData() ) );
43 mEnd = mP + wkb.length();
44 mEndianSwap = false;
46}
47
48QgsConstWkbPtr::QgsConstWkbPtr( const unsigned char *p, int size )
49{
50 mP = const_cast< unsigned char * >( p );
51 mEnd = mP + size;
52 mEndianSwap = false;
54}
55
57{
58 if ( !mP )
60
61 char wkbEndian;
62 *this >> wkbEndian;
63 mEndianSwap = wkbEndian != QgsApplication::endian();
64
65 int wkbType;
66 *this >> wkbType;
67 mWkbType = static_cast<Qgis::WkbType>( wkbType );
68
69 return mWkbType;
70}
71
72void QgsConstWkbPtr::verifyBound( int size ) const
73{
74 if ( !mP || mP + size > mEnd )
75 throw QgsWkbException( QStringLiteral( "wkb access out of bounds" ) );
76}
77
78const QgsConstWkbPtr &QgsConstWkbPtr::operator>>( QPointF &point ) const
79{
80 read( point.rx() );
81 read( point.ry() );
82 return *this;
83}
84
85const QgsConstWkbPtr &QgsConstWkbPtr::operator>>( QPolygonF &points ) const
86{
87 const int skipZM = ( QgsWkbTypes::coordDimensions( mWkbType ) - 2 ) * sizeof( double );
88 Q_ASSERT( skipZM >= 0 );
89
90 unsigned int nPoints;
91 read( nPoints );
92
93 points.resize( nPoints );
94 QPointF *ptr = points.data();
95
96 for ( unsigned int i = 0; i < nPoints; ++i, ++ptr )
97 {
98 read( ptr->rx() );
99 read( ptr->ry() );
100 mP += skipZM;
101 }
102 return *this;
103}
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ Unknown
Unknown.
Definition qgis.h:278
static endian_t endian()
Returns whether this machine uses big or little endian.
QgsConstWkbPtr(const QByteArray &wkb)
Construct WKB pointer from QByteArray.
Definition qgswkbptr.cpp:40
void read(T &v) const
Read a value.
Definition qgswkbptr.h:156
void verifyBound(int size) const
Verify bounds.
Definition qgswkbptr.cpp:72
Qgis::WkbType readHeader() const
readHeader
Definition qgswkbptr.cpp:56
const QgsConstWkbPtr & operator>>(double &v) const
Definition qgswkbptr.h:176
unsigned char * mP
Definition qgswkbptr.h:141
Qgis::WkbType mWkbType
Definition qgswkbptr.h:144
unsigned char * mEnd
Definition qgswkbptr.h:142
Custom exception class for Wkb related exceptions.
Definition qgswkbptr.h:32
int size() const
size
Definition qgswkbptr.h:117
QgsWkbPtr(QByteArray &wkb)
Construct WKB pointer from QByteArray.
Definition qgswkbptr.cpp:20
static Q_INVOKABLE int coordDimensions(Qgis::WkbType type)
Returns the coordinate dimension of the geometry type as an integer.