Skip to content

Commit

Permalink
Rename QgsGeometry::isEmpty to isNull
Browse files Browse the repository at this point in the history
Differentiates missing geometries from empty geometries (eg
empty geometry collections)
  • Loading branch information
nyalldawson committed Jan 30, 2017
1 parent 61d3147 commit 49aae6e
Show file tree
Hide file tree
Showing 84 changed files with 257 additions and 260 deletions.
4 changes: 3 additions & 1 deletion doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions python/core/geometry/qgsgeometry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/CheckValidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/Delaunay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/Dissolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/PolygonCentroids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/SplitWithLines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()):
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/interpolation/qgsinterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/interpolation/qgstininterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/openstreetmap/qgsosmdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgskde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
20 changes: 10 additions & 10 deletions src/analysis/vector/qgsgeometryanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -705,7 +705,7 @@ QgsGeometry QgsGeometryAnalyzer::dissolveFeature( const QgsFeature& f, const Qgs

QgsGeometry featureGeometry = f.geometry();

if ( dissolveInto.isEmpty() )
if ( dissolveInto.isNull() )
{
return featureGeometry;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/vector/qgsgeometrysnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}

Expand Down
18 changes: 9 additions & 9 deletions src/analysis/vector/qgstransectsample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/qgszonalstatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions src/app/dwg/qgsdwgimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/nodetool/qgsmaptoolnodetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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." ) );
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsclipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooladdpart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand Down
Loading

0 comments on commit 49aae6e

Please sign in to comment.