Skip to content
Permalink
Browse files

port more WKB parsing to Qgs(Const)WkbPtr including bounds checking

  • Loading branch information
jef-n committed Jan 31, 2016
1 parent ded1ebb commit 2ea3d7744dbaaa3e189cb1f7be24691a0ecf4f17
Showing with 639 additions and 895 deletions.
  1. +1 −0 python/core/core.sip
  2. +1 −12 python/core/geometry/qgsabstractgeometryv2.sip
  3. +1 −1 python/core/geometry/qgscircularstringv2.sip
  4. +1 −1 python/core/geometry/qgscompoundcurvev2.sip
  5. +1 −1 python/core/geometry/qgscurvepolygonv2.sip
  6. +1 −1 python/core/geometry/qgsgeometrycollectionv2.sip
  7. +2 −1 python/core/geometry/qgslinestringv2.sip
  8. +1 −1 python/core/geometry/qgspointv2.sip
  9. +1 −1 python/core/geometry/qgspolygonv2.sip
  10. +21 −0 python/core/geometry/qgswkbptr.sip
  11. +1 −1 python/core/qgsclipper.sip
  12. +3 −3 python/core/symbology-ng/qgsrendererv2.sip
  13. +2 −2 python/core/symbology-ng/qgssymbolv2.sip
  14. +2 −1 src/analysis/interpolation/qgsinterpolator.cpp
  15. +4 −3 src/analysis/interpolation/qgstininterpolator.cpp
  16. +53 −69 src/analysis/vector/qgsgeometryanalyzer.cpp
  17. +2 −2 src/analysis/vector/qgsgeometryanalyzer.h
  18. +23 −55 src/app/gps/qgsgpsinformationwidget.cpp
  19. +1 −23 src/core/geometry/qgsabstractgeometryv2.cpp
  20. +4 −15 src/core/geometry/qgsabstractgeometryv2.h
  21. +3 −6 src/core/geometry/qgscircularstringv2.cpp
  22. +2 −1 src/core/geometry/qgscircularstringv2.h
  23. +5 −8 src/core/geometry/qgscompoundcurvev2.cpp
  24. +1 −1 src/core/geometry/qgscompoundcurvev2.h
  25. +16 −17 src/core/geometry/qgscurvepolygonv2.cpp
  26. +1 −1 src/core/geometry/qgscurvepolygonv2.h
  27. +1 −1 src/core/geometry/qgsgeometry.cpp
  28. +2 −1 src/core/geometry/qgsgeometry.h
  29. +6 −6 src/core/geometry/qgsgeometrycollectionv2.cpp
  30. +1 −1 src/core/geometry/qgsgeometrycollectionv2.h
  31. +8 −10 src/core/geometry/qgsgeometryfactory.cpp
  32. +3 −1 src/core/geometry/qgsgeometryfactory.h
  33. +5 −4 src/core/geometry/qgslinestringv2.cpp
  34. +1 −1 src/core/geometry/qgslinestringv2.h
  35. +2 −3 src/core/geometry/qgspointv2.cpp
  36. +1 −1 src/core/geometry/qgspointv2.h
  37. +5 −5 src/core/geometry/qgspolygonv2.cpp
  38. +1 −1 src/core/geometry/qgspolygonv2.h
  39. +15 −9 src/core/geometry/qgswkbptr.cpp
  40. +66 −37 src/core/geometry/qgswkbptr.h
  41. +3 −3 src/core/qgis.h
  42. +8 −18 src/core/qgsclipper.cpp
  43. +2 −1 src/core/qgsclipper.h
  44. +5 −5 src/core/qgsdistancearea.cpp
  45. +2 −1 src/core/qgsdistancearea.h
  46. +88 −182 src/core/qgsgml.cpp
  47. +6 −7 src/core/qgsgml.h
  48. +103 −195 src/core/qgsmaptopixelgeometrysimplifier.cpp
  49. +1 −1 src/core/qgsmaptopixelgeometrysimplifier.h
  50. +7 −4 src/core/qgsogcutils.cpp
  51. +8 −6 src/core/qgspointlocator.cpp
  52. +5 −5 src/core/qgsspatialindex.cpp
  53. +1 −1 src/core/symbology-ng/qgs25drenderer.cpp
  54. +2 −1 src/core/symbology-ng/qgspointdisplacementrenderer.cpp
  55. +25 −41 src/core/symbology-ng/qgsrendererv2.cpp
  56. +3 −3 src/core/symbology-ng/qgsrendererv2.h
  57. +41 −50 src/core/symbology-ng/qgssymbolv2.cpp
  58. +2 −2 src/core/symbology-ng/qgssymbolv2.h
  59. +3 −3 src/gui/qgsmapcanvas.h
  60. +32 −37 src/providers/gpx/qgsgpxfeatureiterator.cpp
  61. +1 −1 src/providers/grass/qgsgrassfeatureiterator.cpp
  62. +2 −2 src/server/qgshttprequesthandler.cpp
  63. +1 −1 src/server/qgsserverprojectparser.cpp
  64. +15 −15 tests/src/core/testqgsgeometry.cpp
  65. +2 −2 tests/src/core/testqgsgeometryimport.cpp
@@ -324,3 +324,4 @@
%Include geometry/qgspolygonv2.sip
%Include geometry/qgssurfacev2.sip
%Include geometry/qgswkbtypes.sip
%Include geometry/qgswkbptr.sip
@@ -127,7 +127,7 @@ class QgsAbstractGeometryV2
/** Sets the geometry from a WKB string.
* @see fromWkt
*/
virtual bool fromWkb( const unsigned char * wkb ) = 0;
virtual bool fromWkb( QgsConstWkbPtr wkb ) = 0;

/** Sets the geometry from a WKT string.
* @see fromWkb
@@ -368,15 +368,4 @@ class QgsAbstractGeometryV2
/** Updates the geometry type based on whether sub geometries contain z or m values.
*/
void setZMTypeFromSubGeometry( const QgsAbstractGeometryV2* subggeom, QgsWKBTypes::Type baseGeomType );

/** Reads a WKB header and tests its validity.
* @param wkbPtr
* @param wkbType destination for WKB type from header
* @param endianSwap will be set to true if endian from WKB must be swapped to match QGIS platform endianness
* @param expectedType expected WKB type
* @returns true if header is valid and matches expected type
* @note not available in Python bindings
*/
//static bool readWkbHeader( QgsConstWkbPtr& wkbPtr, QgsWKBTypes::Type& wkbType, bool& endianSwap, QgsWKBTypes::Type expectedType );

};
@@ -18,7 +18,7 @@ class QgsCircularStringV2: public QgsCurveV2

virtual QgsRectangle calculateBoundingBox() const;

virtual bool fromWkb( const unsigned char * wkb );
virtual bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );

int wkbSize() const;
@@ -20,7 +20,7 @@ class QgsCompoundCurveV2: public QgsCurveV2

virtual QgsRectangle calculateBoundingBox() const;

virtual bool fromWkb( const unsigned char* wkb );
virtual bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );

int wkbSize() const;
@@ -17,7 +17,7 @@ class QgsCurvePolygonV2: public QgsSurfaceV2


virtual QgsRectangle calculateBoundingBox() const;
virtual bool fromWkb( const unsigned char* wkb );
virtual bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );

int wkbSize() const;
@@ -57,7 +57,7 @@ class QgsGeometryCollectionV2: public QgsAbstractGeometryV2

virtual void draw( QPainter& p ) const;

bool fromWkb( const unsigned char * wkb );
bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );
int wkbSize() const;
unsigned char* asWkb( int& binarySize ) const;
@@ -112,7 +112,8 @@ class QgsLineStringV2: public QgsCurveV2
virtual int dimension() const;
virtual QgsLineStringV2* clone() const /Factory/;

virtual bool fromWkb( const unsigned char* wkb );

virtual bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );

int wkbSize() const;
@@ -143,7 +143,7 @@ class QgsPointV2: public QgsAbstractGeometryV2
virtual int dimension() const;
virtual QgsPointV2* clone() const /Factory/;
void clear();
virtual bool fromWkb( const unsigned char* wkb );
virtual bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );
int wkbSize() const;
unsigned char* asWkb( int& binarySize ) const;
@@ -13,7 +13,7 @@ class QgsPolygonV2: public QgsCurvePolygonV2
virtual QString geometryType() const;
virtual QgsPolygonV2* clone() const;

virtual bool fromWkb( const unsigned char* wkb );
virtual bool fromWkb( QgsConstWkbPtr wkb );

// inherited: bool fromWkt( const QString &wkt );

@@ -0,0 +1,21 @@
class QgsWkbPtr
{
%TypeHeaderCode
#include <qgswkbptr.h>
%End

public:
QgsWkbPtr( unsigned char *wkb /Array/, int size /ArraySize/ );

};

class QgsConstWkbPtr
{
%TypeHeaderCode
#include <qgswkbptr.h>
%End

public:
QgsConstWkbPtr( unsigned char *wkb /Array/, int size /ArraySize/ );

};
@@ -56,5 +56,5 @@ class QgsClipper
@param wkb pointer to the start of the line wkb
@param clipExtent clipping bounds
@param line out: clipped line coordinates*/
static const unsigned char* clippedLineWKB( const unsigned char* wkb, const QgsRectangle& clipExtent, QPolygonF& line );
static QgsConstWkbPtr clippedLineWKB( QgsConstWkbPtr wkb, const QgsRectangle& clipExtent, QPolygonF& line );
};
@@ -374,9 +374,9 @@ class QgsFeatureRendererV2
//! render editing vertex marker for a polygon
void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );

static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr wkb );
static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr wkb, bool clipToExtent = true );
static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr wkb, bool clipToExtent = true );

void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );

@@ -226,13 +226,13 @@ class QgsSymbolV2
* Creates a line string in screen coordinates from a wkb string in map
* coordinates
*/
static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr wkb, bool clipToExtent = true );

/**
* Creates a polygon in screen coordinates from a wkb string in map
* coordinates
*/
static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr wkb, bool clipToExtent = true );

/**
* Retrieve a cloned list of all layers that make up this symbol.
@@ -108,7 +108,8 @@ int QgsInterpolator::addVerticesToCache( const QgsGeometry *geom, bool zCoord, d
return 1;

bool hasZValue = false;
QgsConstWkbPtr currentWkbPtr( geom->asWkb() + 1 + sizeof( int ) );
QgsConstWkbPtr currentWkbPtr( geom->asWkb(), geom->wkbSize() );
currentWkbPtr.readHeader();
vertexData theVertex; //the current vertex

QGis::WkbType wkbType = geom->wkbType();
@@ -199,7 +199,8 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
//parse WKB. It is ugly, but we cannot use the methods with QgsPoint because they don't contain z-values for 25D types
bool hasZValue = false;
double x, y, z;
QgsConstWkbPtr currentWkbPtr( g->asWkb() + 1 + sizeof( int ) );
QgsConstWkbPtr currentWkbPtr( g->asWkb(), g->wkbSize() );
currentWkbPtr.readHeader();
//maybe a structure or break line
Line3D* line = nullptr;

@@ -236,7 +237,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
currentWkbPtr >> nPoints;
for ( int index = 0; index < nPoints; ++index )
{
currentWkbPtr += 1 + sizeof( int );
currentWkbPtr.readHeader();
currentWkbPtr >> x >> y;
if ( hasZValue ) //skip z-coordinate for 25D geometries
{
@@ -388,7 +389,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
currentWkbPtr >> nPolys;
for ( int index = 0; index < nPolys; ++index )
{
currentWkbPtr += 1 + sizeof( int );
currentWkbPtr.readHeader();
int nRings;
currentWkbPtr >> nRings;
for ( int index2 = 0; index2 < nRings; ++index2 )

0 comments on commit 2ea3d77

Please sign in to comment.
You can’t perform that action at this time.