Navigation Menu

Skip to content

Commit

Permalink
Fix rendering of CurvePolygons without curved segments (fix #14028)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 21, 2016
1 parent 1a7dede commit c38ee41
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 5 deletions.
5 changes: 5 additions & 0 deletions python/core/geometry/qgswkbtypes.sip
Expand Up @@ -113,6 +113,11 @@ class QgsWKBTypes
*/
static bool isMultiType( Type type );

/** Returns true if the WKB type is a curved type or can contain curved geometries.
* @note added in QGIS 2.14
*/
static bool isCurvedType( Type type );

/** Returns the inherent dimension of the geometry type as an integer. Returned value will
* always be less than or equal to the coordinate dimension.
* @returns 0 for point geometries, 1 for line geometries, 2 for polygon geometries
Expand Down
18 changes: 18 additions & 0 deletions src/core/geometry/qgswkbtypes.cpp
Expand Up @@ -94,6 +94,24 @@ bool QgsWKBTypes::isMultiType( Type type )
return it->mIsMultiType;
}

bool QgsWKBTypes::isCurvedType( QgsWKBTypes::Type type )
{
switch ( flatType( type ) )
{
case CircularString:
case CompoundCurve:
case CurvePolygon:
case MultiCurve:
case MultiSurface:
return true;

default:
return false;
}

return false;
}

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests.
Expand Down
5 changes: 5 additions & 0 deletions src/core/geometry/qgswkbtypes.h
Expand Up @@ -144,6 +144,11 @@ class CORE_EXPORT QgsWKBTypes
*/
static bool isMultiType( Type type );

/** Returns true if the WKB type is a curved type or can contain curved geometries.
* @note added in QGIS 2.14
*/
static bool isCurvedType( Type type );

/** Returns the inherent dimension of the geometry type as an integer. Returned value will
* always be less than or equal to the coordinate dimension.
* @returns 0 for point geometries, 1 for line geometries, 2 for polygon geometries
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -702,7 +702,7 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
bool tileMapRendering = context.testFlag( QgsRenderContext::RenderMapTile );

//convert curve types to normal point/line/polygon ones
if ( geom->geometry()->hasCurvedSegments() )
if ( QgsWKBTypes::isCurvedType( geom->geometry()->wkbType() ) )
{
QgsAbstractGeometryV2* g = geom->geometry()->segmentize();
if ( !g )
Expand Down
58 changes: 58 additions & 0 deletions tests/src/python/test_qgsgeometry.py
Expand Up @@ -2324,6 +2324,64 @@ def testWkbTypes(self):
assert QgsWKBTypes.isMultiType(QgsWKBTypes.MultiLineString25D)
assert QgsWKBTypes.isMultiType(QgsWKBTypes.MultiPolygon25D)

# test isCurvedType methods
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.Unknown)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.Point)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.LineString)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.Polygon)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiPoint)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiLineString)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiPolygon)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.GeometryCollection)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CircularString)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CompoundCurve)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CurvePolygon)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiCurve)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiSurface)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.NoGeometry)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.PointZ)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.LineStringZ)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.PolygonZ)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiPointZ)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiLineStringZ)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiPolygonZ)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.GeometryCollectionZ)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CircularStringZ)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CompoundCurveZ)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CurvePolygonZ)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiCurveZ)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiSurfaceZ)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.PointM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.LineStringM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.PolygonM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiPointM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiLineStringM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiPolygonM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.GeometryCollectionM)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CircularStringM)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CompoundCurveM)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CurvePolygonM)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiCurveM)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiSurfaceM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.PointZM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.LineStringZM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.PolygonZM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiPointZM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiLineStringZM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiPolygonZM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.GeometryCollectionZM)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CircularStringZM)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CompoundCurveZM)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.CurvePolygonZM)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiCurveZM)
assert QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiSurfaceZM)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.Point25D)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.LineString25D)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.Polygon25D)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiPoint25D)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiLineString25D)
assert not QgsWKBTypes.isCurvedType(QgsWKBTypes.MultiPolygon25D)

# test hasZ methods
assert not QgsWKBTypes.hasZ(QgsWKBTypes.Unknown)
assert not QgsWKBTypes.hasZ(QgsWKBTypes.Point)
Expand Down
14 changes: 10 additions & 4 deletions tests/src/python/test_qgssymbolv2.py
Expand Up @@ -95,7 +95,13 @@ def testGeometryRendering(self):
'reference_image': 'compound_curve'},
{'name': 'CurvePolygon',
'wkt': 'CURVEPOLYGON(CIRCULARSTRING(1 3, 3 5, 4 7, 7 3, 1 3))',
'reference_image': 'curve_polygon'}]
'reference_image': 'curve_polygon'},
{'name': 'MultiCurve',
'wkt': 'MultiCurve((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0, 2 1,2 2))',
'reference_image': 'multicurve'},
{'name': 'CurvePolygon_no_arc', # refs #14028
'wkt': 'CURVEPOLYGON(LINESTRING(1 3, 3 5, 4 7, 7 3, 1 3))',
'reference_image': 'curve_polygon_no_arc'}]

for test in tests:
geom = QgsGeometry.fromWkt(test['wkt'])
Expand All @@ -110,18 +116,18 @@ def testGeometryRendering(self):
geom_z = QgsGeometry.fromWkt(test['wkt'])
geom_z.geometry().addZValue(5)
rendered_image = self.renderGeometry(geom_z)
assert self.imageCheck(test['name'] + ' z', test['reference_image'], rendered_image)
assert self.imageCheck(test['name'] + 'Z', test['reference_image'], rendered_image)

#test with ZM
geom_z.geometry().addMValue(15)
rendered_image = self.renderGeometry(geom_z)
assert self.imageCheck(test['name'] + ' zm', test['reference_image'], rendered_image)
assert self.imageCheck(test['name'] + 'ZM', test['reference_image'], rendered_image)

#test with ZM
geom_m = QgsGeometry.fromWkt(test['wkt'])
geom_m.geometry().addMValue(15)
rendered_image = self.renderGeometry(geom_m)
assert self.imageCheck(test['name'] + ' m', test['reference_image'], rendered_image)
assert self.imageCheck(test['name'] + 'M', test['reference_image'], rendered_image)

def renderGeometry(self, geom):
f = QgsFeature()
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c38ee41

Please sign in to comment.