Skip to content
Permalink
Browse files

Rename QgsGeometry::isEmpty to isNull

Differentiates missing geometries from empty geometries (eg
empty geometry collections)
  • Loading branch information
nyalldawson committed Jan 30, 2017
1 parent 61d3147 commit 49aae6e908cb040bef51f332ebbb6355e74962d0
Showing with 257 additions and 260 deletions.
  1. +3 −1 doc/api_break.dox
  2. +1 −6 python/core/geometry/qgsgeometry.sip
  3. +1 −1 python/plugins/processing/algs/qgis/CheckValidity.py
  4. +1 −1 python/plugins/processing/algs/qgis/Delaunay.py
  5. +1 −1 python/plugins/processing/algs/qgis/Dissolve.py
  6. +1 −1 python/plugins/processing/algs/qgis/PolygonCentroids.py
  7. +1 −1 python/plugins/processing/algs/qgis/ReverseLineDirection.py
  8. +1 −1 python/plugins/processing/algs/qgis/SplitWithLines.py
  9. +1 −1 src/analysis/interpolation/qgsinterpolator.cpp
  10. +1 −1 src/analysis/interpolation/qgstininterpolator.cpp
  11. +1 −1 src/analysis/openstreetmap/qgsosmdatabase.cpp
  12. +1 −1 src/analysis/raster/qgskde.cpp
  13. +10 −10 src/analysis/vector/qgsgeometryanalyzer.cpp
  14. +1 −1 src/analysis/vector/qgsgeometrysnapper.cpp
  15. +9 −9 src/analysis/vector/qgstransectsample.cpp
  16. +2 −2 src/analysis/vector/qgszonalstatistics.cpp
  17. +2 −2 src/app/dwg/qgsdwgimporter.cpp
  18. +1 −1 src/app/nodetool/qgsmaptoolnodetool.cpp
  19. +5 −5 src/app/qgisapp.cpp
  20. +1 −1 src/app/qgsclipboard.cpp
  21. +1 −1 src/app/qgsmaptooladdpart.cpp
  22. +1 −1 src/app/qgsmaptooldeletepart.cpp
  23. +1 −1 src/app/qgsmaptooldeletering.cpp
  24. +1 −1 src/app/qgsmaptoollabel.cpp
  25. +1 −1 src/app/qgsmaptoolmovefeature.cpp
  26. +6 −6 src/app/qgsmaptooloffsetcurve.cpp
  27. +1 −1 src/app/qgsmaptoolreshape.cpp
  28. +1 −1 src/app/qgsmaptoolrotatefeature.cpp
  29. +2 −2 src/app/qgsmaptoolsimplify.cpp
  30. +1 −1 src/app/qgsselectbyformdialog.cpp
  31. +1 −1 src/core/composer/qgscomposermapgrid.cpp
  32. +17 −17 src/core/geometry/qgsgeometry.cpp
  33. +4 −4 src/core/geometry/qgsgeometry.h
  34. +2 −2 src/core/geometry/qgsgeos.cpp
  35. +1 −1 src/core/layertree/qgslayertreemodel.cpp
  36. +3 −3 src/core/qgsdistancearea.cpp
  37. +56 −56 src/core/qgsexpression.cpp
  38. +1 −1 src/core/qgsfeature.cpp
  39. +1 −1 src/core/qgsgml.cpp
  40. +1 −1 src/core/qgsjsonutils.cpp
  41. +1 −1 src/core/qgslabelfeature.cpp
  42. +4 −4 src/core/qgsmaphittest.cpp
  43. +1 −1 src/core/qgsmaptopixelgeometrysimplifier.cpp
  44. +1 −1 src/core/qgsogcutils.cpp
  45. +7 −7 src/core/qgspallabeling.cpp
  46. +1 −1 src/core/qgsvectordataprovider.cpp
  47. +1 −1 src/core/qgsvectorlayer.cpp
  48. +1 −1 src/core/qgsvectorlayerdiagramprovider.cpp
  49. +2 −2 src/core/qgsvectorlayereditutils.cpp
  50. +1 −1 src/core/qgsvectorlayerundocommand.cpp
  51. +1 −1 src/core/symbology-ng/qgsellipsesymbollayer.cpp
  52. +1 −1 src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
  53. +1 −1 src/core/symbology-ng/qgssymbol.cpp
  54. +4 −4 src/core/symbology-ng/qgssymbollayerutils.cpp
  55. +1 −1 src/gui/qgsexpressionselectiondialog.cpp
  56. +2 −2 src/gui/qgshighlight.cpp
  57. +1 −1 src/gui/qgsmapcanvas.cpp
  58. +1 −1 src/gui/qgsmapcanvassnapper.cpp
  59. +2 −2 src/gui/qgsrubberband.cpp
  60. +1 −1 src/plugins/spatialquery/qgsspatialquery.cpp
  61. +3 −3 src/plugins/topology/checkDock.cpp
  62. +2 −2 src/plugins/topology/topolError.cpp
  63. +14 −14 src/plugins/topology/topolTest.cpp
  64. +3 −3 src/providers/delimitedtext/qgsdelimitedtextfeatureiterator.cpp
  65. +1 −1 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  66. +1 −1 src/providers/grass/qgis.v.in.cpp
  67. +1 −1 src/providers/mssql/qgsmssqlprovider.cpp
  68. +1 −1 src/providers/postgres/qgspostgresprovider.cpp
  69. +1 −1 src/providers/virtual/qgsvirtuallayersqlitemodule.cpp
  70. +3 −3 src/providers/wfs/qgswfsfeatureiterator.cpp
  71. +2 −2 src/providers/wfs/qgswfsprovider.cpp
  72. +2 −2 src/providers/wfs/qgswfsshareddata.cpp
  73. +1 −1 src/providers/wfs/qgswfsutils.cpp
  74. +1 −1 src/server/services/wfs/qgswfsgetfeature.cpp
  75. +3 −3 src/server/services/wms/qgswmsrenderer.cpp
  76. +3 −3 tests/src/app/testqgisappclipboard.cpp
  77. +1 −1 tests/src/core/testqgsfeature.cpp
  78. +11 −11 tests/src/core/testqgsgeometry.cpp
  79. +1 −1 tests/src/core/testqgsmaptopixelgeometrysimplifier.cpp
  80. +5 −5 tests/src/core/testqgsogrutils.cpp
  81. +1 −1 tests/src/python/test_qgsdelimitedtextprovider.py
  82. +9 −9 tests/src/python/test_qgsgeometry.py
  83. +3 −3 tests/src/python/test_qgsjsonutils.py
  84. +1 −1 tests/src/python/test_qgssymbol.py
@@ -1044,8 +1044,10 @@ QgsGeometry {#qgis_api_break_3_0_QgsGeometry}

- All QgsGeometry methods now accept geometry references instead of pointers, and return a QgsGeometry
value instead of a pointer. The biggest impact with this change is that PyQGIS code should not compare a geometry
result to None, but instead either use a boolean test (`if g.buffer(10):`) or explicitly use the isEmpty()
result to None, but instead either use a boolean test (`if g.buffer(10):`) or explicitly use the isNull()
method to determine if a geometry is valid.
- isEmpty() was renamed to isNull() to differentiate a missing geometry from a geometry which is empty (eg an
empty geometry collection)
- wkbSize() and asWkb() has been replaced by exportToWkb(). WKB representation is no longer cached within QgsGeometry
- asGeos() has been replaced by exportToGeos(). GEOS representation is no longer cached within QgsGeometry
- int addPart( const QList<QgsPoint> &points, QgsWkbTypes::GeometryType geomType ) has been renamed to addPoints
@@ -57,12 +57,7 @@ class QgsGeometry
*/
void setGeometry( QgsAbstractGeometry* geometry /Transfer/ );

/** Returns true if the geometry is empty (ie, contains no underlying geometry
* accessible via @link geometry @endlink).
* @see geometry
* @note added in QGIS 2.10
*/
bool isEmpty() const;
bool isNull() const;

/** Creates a new geometry from a WKT string */
static QgsGeometry fromWkt( const QString& wkt );
@@ -137,7 +137,7 @@ def doCheck(self, feedback):
attrs = inFeat.attributes()

valid = True
if not geom.isEmpty() and not geom.isGeosEmpty():
if not geom.isNull() and not geom.isGeosEmpty():
errors = list(geom.validateGeometry())
if errors:
# QGIS method return a summary at the end
@@ -82,7 +82,7 @@ def processAlgorithm(self, feedback):
total = 100.0 / len(features)
for current, inFeat in enumerate(features):
geom = QgsGeometry(inFeat.geometry())
if geom.isEmpty():
if geom.isNull():
continue
if geom.isMultipart():
points = geom.asMultiPoint()
@@ -93,7 +93,7 @@ def processAlgorithm(self, feedback):
first = False

tmpInGeom = inFeat.geometry()
if tmpInGeom.isEmpty() or tmpInGeom.isGeosEmpty():
if tmpInGeom.isNull() or tmpInGeom.isGeosEmpty():
continue

errors = tmpInGeom.validateGeometry()
@@ -80,7 +80,7 @@ def processAlgorithm(self, feedback):
inGeom = feat.geometry()
attrs = feat.attributes()

if inGeom.isEmpty():
if inGeom.isNull():
outGeom = QgsGeometry(None)
else:
outGeom = QgsGeometry(inGeom.centroid())
@@ -65,7 +65,7 @@ def processAlgorithm(self, feedback):
attrs = inFeat.attributes()

outGeom = None
if not inGeom.isEmpty():
if not inGeom.isNull():
reversedLine = inGeom.geometry().reversed()
if not reversedLine:
raise GeoAlgorithmExecutionException(
@@ -127,7 +127,7 @@ def processAlgorithm(self, feedback):
while len(inGeoms) > 0:
inGeom = inGeoms.pop()

if inGeom.isEmpty(): # this has been encountered and created a run-time error
if inGeom.isNull(): # this has been encountered and created a run-time error
continue

if split_geom_engine.intersects(inGeom.geometry()):
@@ -105,7 +105,7 @@ int QgsInterpolator::cacheBaseData()

int QgsInterpolator::addVerticesToCache( const QgsGeometry& geom, bool zCoord, double attributeValue )
{
if ( geom.isEmpty() )
if ( geom.isNull() )
return 1;

bool hasZValue = false;
@@ -175,7 +175,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT

QgsGeometry g = f->geometry();
{
if ( g.isEmpty() )
if ( g.isNull() )
{
return 2;
}
@@ -504,7 +504,7 @@ void QgsOSMDatabase::exportSpatiaLiteWays( bool closed, const QString& tableName
sqlite3_bind_null( stmtInsert, ++col );
}

if ( !geom.isEmpty() )
if ( !geom.isNull() )
{
QByteArray wkb( geom.exportToWkb() );
sqlite3_bind_blob( stmtInsert, ++col, wkb.constData(), wkb.length(), SQLITE_STATIC );
@@ -110,7 +110,7 @@ QgsKernelDensityEstimation::Result QgsKernelDensityEstimation::prepare()
QgsKernelDensityEstimation::Result QgsKernelDensityEstimation::addFeature( const QgsFeature& feature )
{
QgsGeometry featureGeometry = feature.geometry();
if ( featureGeometry.isEmpty() )
if ( featureGeometry.isNull() )
{
return Success;
}
@@ -475,7 +475,7 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
++jt;
}
QList<double> values;
if ( dissolveGeometry.isEmpty() )
if ( dissolveGeometry.isNull() )
{
QgsDebugMsg( "no dissolved geometry - should not happen" );
return false;
@@ -520,7 +520,7 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap
++jt;
}
QList<double> values;
if ( dissolveGeometry.isEmpty() )
if ( dissolveGeometry.isNull() )
{
QgsDebugMsg( "no dissolved geometry - should not happen" );
return false;
@@ -705,7 +705,7 @@ QgsGeometry QgsGeometryAnalyzer::dissolveFeature( const QgsFeature& f, const Qgs

QgsGeometry featureGeometry = f.geometry();

if ( dissolveInto.isEmpty() )
if ( dissolveInto.isNull() )
{
return featureGeometry;
}
@@ -810,7 +810,7 @@ bool QgsGeometryAnalyzer::buffer( QgsVectorLayer* layer, const QString& shapefil
if ( dissolve )
{
QgsFeature dissolveFeature;
if ( dissolveGeometry.isEmpty() )
if ( dissolveGeometry.isNull() )
{
QgsDebugMsg( "no dissolved geometry - should not happen" );
return false;
@@ -967,7 +967,7 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
lrsGeom = locateBetweenMeasures( measure1, measure2, featureIdIt->geometry() );
}

if ( !lrsGeom.isEmpty() )
if ( !lrsGeom.isNull() )
{
++nOutputFeatures;
addEventLayerFeature( fet, lrsGeom, featureIdIt->geometry(), fileWriter, memoryProviderFeatures, offsetField, offsetScale, forceSingleGeometry );
@@ -995,7 +995,7 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, const QgsGeometry& geom, const QgsGeometry& lineGeom, QgsVectorFileWriter* fileWriter, QgsFeatureList& memoryFeatures,
int offsetField, double offsetScale, bool forceSingleType )
{
if ( geom.isEmpty() )
if ( geom.isNull() )
{
return;
}
@@ -1020,7 +1020,7 @@ void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, const QgsGe
double offsetVal = feature.attribute( offsetField ).toDouble();
offsetVal *= offsetScale;
newGeom = createOffsetGeometry( *geomIt, lineGeom, offsetVal );
if ( newGeom.isEmpty() )
if ( newGeom.isNull() )
{
continue;
}
@@ -1040,7 +1040,7 @@ void QgsGeometryAnalyzer::addEventLayerFeature( QgsFeature& feature, const QgsGe

QgsGeometry QgsGeometryAnalyzer::createOffsetGeometry( const QgsGeometry& geom, const QgsGeometry& lineGeom, double offset )
{
if ( !geom || lineGeom.isEmpty() )
if ( !geom || lineGeom.isNull() )
{
return QgsGeometry();
}
@@ -1147,7 +1147,7 @@ QgsPoint QgsGeometryAnalyzer::createPointOffset( double x, double y, double dist

QgsGeometry QgsGeometryAnalyzer::locateBetweenMeasures( double fromMeasure, double toMeasure, const QgsGeometry& lineGeom )
{
if ( lineGeom.isEmpty() )
if ( lineGeom.isNull() )
{
return QgsGeometry();
}
@@ -1189,7 +1189,7 @@ QgsGeometry QgsGeometryAnalyzer::locateBetweenMeasures( double fromMeasure, doub

QgsGeometry QgsGeometryAnalyzer::locateAlongMeasure( double measure, const QgsGeometry& lineGeom )
{
if ( lineGeom.isEmpty() )
if ( lineGeom.isNull() )
{
return QgsGeometry();
}
@@ -475,7 +475,7 @@ QgsFeatureList QgsGeometrySnapper::snapFeatures( const QgsFeatureList& features,

void QgsGeometrySnapper::processFeature( QgsFeature& feature, double snapTolerance, SnapMode mode )
{
if ( !feature.geometry().isEmpty() )
if ( !feature.geometry().isNull() )
feature.setGeometry( snapGeometry( feature.geometry(), snapTolerance, mode ) );
}

@@ -172,7 +172,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
//find baseline for strata
QVariant strataId = fet.attribute( mStrataIdAttribute );
QgsGeometry baselineGeom = findBaselineGeometry( strataId.isValid() ? strataId : -1 );
if ( baselineGeom.isEmpty() )
if ( baselineGeom.isNull() )
{
continue;
}
@@ -218,7 +218,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
double randomPosition = (( double )mt_rand() / MD_RAND_MAX ) * clippedBaseline.length();
QgsGeometry samplePoint = clippedBaseline.interpolate( randomPosition );
++nIterations;
if ( samplePoint.isEmpty() )
if ( samplePoint.isNull() )
{
continue;
}
@@ -252,7 +252,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
lineFarAway << sampleQgsPoint << ptFarAway;
QgsGeometry lineFarAwayGeom = QgsGeometry::fromPolyline( lineFarAway );
QgsGeometry lineClipStratum = lineFarAwayGeom.intersection( strataGeom );
if ( lineClipStratum.isEmpty() )
if ( lineClipStratum.isNull() )
{
continue;
}
@@ -268,7 +268,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
|| lineClipStratum.wkbType() == QgsWkbTypes::MultiLineString25D )
{
QgsGeometry singleLine = closestMultilineElement( sampleQgsPoint, lineClipStratum );
if ( !singleLine.isEmpty() )
if ( !singleLine.isNull() )
{
lineClipStratum = singleLine;
}
@@ -351,13 +351,13 @@ QgsGeometry QgsTransectSample::findBaselineGeometry( const QVariant& strataId )
bool QgsTransectSample::otherTransectWithinDistance( const QgsGeometry& geom, double minDistLayerUnit, double minDistance, QgsSpatialIndex& sIndex,
const QMap< QgsFeatureId, QgsGeometry >& lineFeatureMap, QgsDistanceArea& da )
{
if ( geom.isEmpty() )
if ( geom.isNull() )
{
return false;
}

QgsGeometry buffer = geom.buffer( minDistLayerUnit, 8 );
if ( buffer.isEmpty() )
if ( buffer.isNull() )
{
return false;
}
@@ -557,7 +557,7 @@ QgsGeometry* QgsTransectSample::clipBufferLine( const QgsGeometry& stratumGeom,
{
//int verticesBefore = usedBaseline->asMultiPolyline().count();
usedBaseline = clippedBaseline->simplify( mBaselineSimplificationTolerance );
if ( usedBaseline.isEmpty() )
if ( usedBaseline.isNull() )
{
return nullptr;
}
@@ -576,7 +576,7 @@ QgsGeometry* QgsTransectSample::clipBufferLine( const QgsGeometry& stratumGeom,
{
//loop with tolerance: create buffer, convert buffer to line, clip line by stratum, test if result is (single) line
QgsGeometry clipBaselineBuffer = usedBaseline.buffer( currentBufferDist, 8 );
if ( clipBaselineBuffer.isEmpty() )
if ( clipBaselineBuffer.isNull() )
{
continue;
}
@@ -621,7 +621,7 @@ QgsGeometry* QgsTransectSample::clipBufferLine( const QgsGeometry& stratumGeom,
}
bufferLineClipped = bufferLine.intersection( stratumGeom );

if ( bufferLineClipped.isEmpty() && bufferLineClipped.type() == QgsWkbTypes::LineGeometry )
if ( bufferLineClipped.isNull() && bufferLineClipped.type() == QgsWkbTypes::LineGeometry )
{
//if stratumGeom is a multipolygon, bufferLineClipped must intersect each part
bool bufferLineClippedIntersectsStratum = true;
@@ -490,11 +490,11 @@ void QgsZonalStatistics::statisticsFromPreciseIntersection( void* band, const Qg
continue;

pixelRectGeometry = QgsGeometry::fromRect( QgsRectangle( currentX - hCellSizeX, currentY - hCellSizeY, currentX + hCellSizeX, currentY + hCellSizeY ) );
if ( !pixelRectGeometry.isEmpty() )
if ( !pixelRectGeometry.isNull() )
{
//intersection
QgsGeometry intersectGeometry = pixelRectGeometry.intersection( poly );
if ( !intersectGeometry.isEmpty() )
if ( !intersectGeometry.isNull() )
{
double intersectionArea = intersectGeometry.area();
if ( intersectionArea >= 0.0 )
@@ -2577,7 +2577,7 @@ bool QgsDwgImporter::expandInserts( QString &error )
}

QgsGeometry g( QgsOgrUtils::ogrGeometryToQgsGeometry( ogrG ) );
if ( g.isEmpty() )
if ( g.isNull() )
{
QgsDebugMsg( QString( "%1: could not copy geometry" ).arg( OGR_F_GetFID( insert ) ) );
continue;
@@ -2668,7 +2668,7 @@ bool QgsDwgImporter::expandInserts( QString &error )
}

QgsGeometry g( QgsOgrUtils::ogrGeometryToQgsGeometry( ogrG ) );
if ( g.isEmpty() )
if ( g.isNull() )
{
QgsDebugMsg( QString( "%1: could not copy geometry" ).arg( fid ) );
continue;
@@ -660,7 +660,7 @@ void QgsMapToolNodeTool::deleteNodeSelection()

mSelectedFeature->deleteSelectedVertexes();

if ( mSelectedFeature->geometry()->isEmpty() )
if ( mSelectedFeature->geometry()->isNull() )
{
emit messageEmitted( tr( "Geometry has been cleared. Use the add part tool to set geometry for this feature." ) );
}
@@ -6661,10 +6661,10 @@ QgsGeometry QgisApp::unionGeometries( const QgsVectorLayer* vl, QgsFeatureList&
}
progress.setValue( i );
QgsGeometry currentGeom = featureList.at( i ).geometry();
if ( !currentGeom.isEmpty() )
if ( !currentGeom.isNull() )
{
unionGeom = unionGeom.combine( currentGeom );
if ( unionGeom.isEmpty() )
if ( unionGeom.isNull() )
{
QApplication::restoreOverrideCursor();
return QgsGeometry();
@@ -7193,7 +7193,7 @@ void QgisApp::mergeSelectedFeatures()
QgsFeatureList featureList = vl->selectedFeatures(); //get QList<QgsFeature>
bool canceled;
QgsGeometry unionGeom = unionGeometries( vl, featureList, canceled );
if ( unionGeom.isEmpty() )
if ( unionGeom.isNull() )
{
if ( !canceled )
{
@@ -7229,7 +7229,7 @@ void QgisApp::mergeSelectedFeatures()
bool canceled;
QgsFeatureList featureListAfter = vl->selectedFeatures();
unionGeom = unionGeometries( vl, featureListAfter, canceled );
if ( unionGeom.isEmpty() )
if ( unionGeom.isNull() )
{
if ( !canceled )
{
@@ -7585,7 +7585,7 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
if ( destType != QgsWkbTypes::UnknownGeometry )
{
QgsGeometry newGeometry = geom.convertToType( destType, destIsMulti );
if ( newGeometry.isEmpty() )
if ( newGeometry.isNull() )
{
continue;
}
@@ -189,7 +189,7 @@ QgsFeatureList QgsClipboard::stringToFeatureList( const QString& string, const Q
{
// Assume that it's just WKT for now.
QgsGeometry geometry = QgsGeometry::fromWkt( row );
if ( geometry.isEmpty() )
if ( geometry.isNull() )
continue;

QgsFeature feature;
@@ -66,7 +66,7 @@ void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
}

bool isGeometryEmpty = false;
if ( vlayer->selectedFeatures()[0].geometry().isEmpty() )
if ( vlayer->selectedFeatures()[0].geometry().isNull() )
isGeometryEmpty = true;

if ( !checkSelection() )

0 comments on commit 49aae6e

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