Skip to content

Commit

Permalink
Add a const geometry getter to QgsFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 11, 2015
1 parent e509fc5 commit 2863f20
Show file tree
Hide file tree
Showing 106 changed files with 368 additions and 351 deletions.
4 changes: 2 additions & 2 deletions python/analysis/vector/qgsgeometryanalyzer.sip
Expand Up @@ -95,9 +95,9 @@ class QgsGeometryAnalyzer
bool forceSingleGeometry = false, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );

/**Returns linear reference geometry as a multiline (or 0 if no match). Currently, the z-coordinates are considered to be the measures (no support for m-values in QGIS)*/
QgsGeometry* locateBetweenMeasures( double fromMeasure, double toMeasure, QgsGeometry* lineGeom );
QgsGeometry* locateBetweenMeasures( double fromMeasure, double toMeasure, const QgsGeometry* lineGeom );
/**Returns linear reference geometry. Unlike the PostGIS function, this method always returns multipoint or 0 if no match (not geometry collection).
Currently, the z-coordinates are considered to be the measures (no support for m-values in QGIS)*/
QgsGeometry* locateAlongMeasure( double measure, QgsGeometry* lineGeom );
QgsGeometry* locateAlongMeasure( double measure, const QgsGeometry* lineGeom );

};
4 changes: 2 additions & 2 deletions python/core/qgsdistancearea.sip
Expand Up @@ -56,10 +56,10 @@ class QgsDistanceArea
double ellipsoidInverseFlattening() const;

//! general measurement (line distance or polygon area)
double measure( QgsGeometry* geometry );
double measure( const QgsGeometry* geometry );

//! measures perimeter of polygon
double measurePerimeter( QgsGeometry* geometry );
double measurePerimeter( const QgsGeometry* geometry );

//! measures line
double measureLine( const QList<QgsPoint>& points );
Expand Down
7 changes: 6 additions & 1 deletion python/core/qgsfeature.sip
Expand Up @@ -313,7 +313,12 @@ class QgsFeature
/**
* Get the geometry object associated with this feature
*/
QgsGeometry *geometry() const;
QgsGeometry* geometry() const;

/** Gets a const pointer to the geometry object associated with this feature
* @note added in QGIS 2.9
*/
const QgsGeometry* constGeometry() const;

/**
* Get the geometry object associated with this feature
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsgeometry.sip
Expand Up @@ -282,7 +282,7 @@ class QgsGeometry
/**Changes this geometry such that it does not intersect the other geometry
@param other geometry that should not be intersect
@return 0 in case of success*/
int makeDifference( QgsGeometry* other );
int makeDifference( const QgsGeometry* other );

/**Returns the bounding box of this feature*/
QgsRectangle boundingBox() const;
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgsogcutils.sip
Expand Up @@ -28,12 +28,12 @@ class QgsOgcUtils
/** Exports the geometry to GML2 or GML3
@return QDomElement
*/
static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc, QString format, const int &precision = 17 );
static QDomElement geometryToGML( const QgsGeometry* geometry, QDomDocument& doc, QString format, const int &precision = 17 );

/** Exports the geometry to GML2
@return QDomElement
*/
static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc, const int &precision = 17 );
static QDomElement geometryToGML( const QgsGeometry* geometry, QDomDocument& doc, const int &precision = 17 );

/** Exports the rectangle to GML2 Box
@return QDomElement
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgspallabeling.sip
Expand Up @@ -752,7 +752,7 @@ class QgsPalLabeling : QgsLabelingEngineInterface
* @returns prepared geometry
* @note added in QGIS 2.9
*/
static QgsGeometry* prepareGeometry( QgsGeometry *geometry, const QgsRenderContext &context, const QgsCoordinateTransform *ct, double minSize = 0, QgsGeometry *clipGeometry = 0 ) /Factory/;
static QgsGeometry* prepareGeometry( const QgsGeometry *geometry, const QgsRenderContext &context, const QgsCoordinateTransform *ct, double minSize = 0, QgsGeometry *clipGeometry = 0 ) /Factory/;

/** Checks whether a geometry requires preparation before registration with PAL
* @param geometry geometry to prepare
Expand All @@ -762,7 +762,7 @@ class QgsPalLabeling : QgsLabelingEngineInterface
* @returns true if geometry requires preparation
* @note added in QGIS 2.9
*/
static bool geometryRequiresPreparation( QgsGeometry *geometry, const QgsRenderContext &context, const QgsCoordinateTransform *ct, QgsGeometry *clipGeometry = 0 );
static bool geometryRequiresPreparation( const QgsGeometry *geometry, const QgsRenderContext &context, const QgsCoordinateTransform *ct, QgsGeometry *clipGeometry = 0 );


protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayer.sip
Expand Up @@ -694,7 +694,7 @@ class QgsVectorLayer : QgsMapLayer
* @note geom is not going to be modified by the function
* @return 0 in case of success
*/
int addTopologicalPoints( QgsGeometry* geom );
int addTopologicalPoints( const QgsGeometry* geom );

/** Adds a vertex to segments which intersect point p but don't
* already have a vertex there. If a feature already has a vertex at position p,
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayereditutils.sip
Expand Up @@ -76,7 +76,7 @@ class QgsVectorLayerEditUtils
* @note geom is not going to be modified by the function
* @return 0 in case of success
*/
int addTopologicalPoints( QgsGeometry* geom );
int addTopologicalPoints( const QgsGeometry* geom );

/** Adds a vertex to segments which intersect point p but don't
* already have a vertex there. If a feature already has a vertex at position p,
Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgshighlight.sip
Expand Up @@ -4,7 +4,7 @@ class QgsHighlight : QgsMapCanvasItem
#include <qgshighlight.h>
%End
public:
QgsHighlight( QgsMapCanvas *mapCanvas, QgsGeometry *geom, QgsVectorLayer *layer );
QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry *geom, QgsVectorLayer *layer );
~QgsHighlight();

/** Set line/outline to color, polygon fill to color with alpha = 63.
Expand Down
4 changes: 2 additions & 2 deletions python/gui/qgsrubberband.sip
Expand Up @@ -161,7 +161,7 @@ class QgsRubberBand: QgsMapCanvasItem
* @param layer the layer containing the feature, used for coord transformation to map
* crs. In case of 0 pointer, the coordinates are not going to be transformed.
*/
void setToGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
void setToGeometry( const QgsGeometry* geom, QgsVectorLayer* layer );

/**
* Sets this rubber band to a map canvas rectangle
Expand All @@ -180,7 +180,7 @@ class QgsRubberBand: QgsMapCanvasItem
* @param layer the layer containing the feature, used for coord transformation to map
* crs. In case of 0 pointer, the coordinates are not going to be transformed.
*/
void addGeometry( QgsGeometry* geom, QgsVectorLayer* layer );
void addGeometry( const QgsGeometry* geom, QgsVectorLayer* layer );

/**
* Adds translation to original coordinates (all in map coordinates)
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/interpolation/qgsinterpolator.cpp
Expand Up @@ -93,7 +93,7 @@ int QgsInterpolator::cacheBaseData()
}
}

if ( addVerticesToCache( theFeature.geometry(), v_it->zCoordInterpolation, attributeValue ) != 0 )
if ( addVerticesToCache( theFeature.constGeometry(), v_it->zCoordInterpolation, attributeValue ) != 0 )
{
return 3;
}
Expand All @@ -103,7 +103,7 @@ int QgsInterpolator::cacheBaseData()
return 0;
}

int QgsInterpolator::addVerticesToCache( QgsGeometry* geom, bool zCoord, double attributeValue )
int QgsInterpolator::addVerticesToCache( const QgsGeometry *geom, bool zCoord, double attributeValue )
{
if ( !geom )
return 1;
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/interpolation/qgsinterpolator.h
Expand Up @@ -88,7 +88,7 @@ class ANALYSIS_EXPORT QgsInterpolator
@param zCoord true if the z-coordinate of the geometry is to be interpolated
@param attributeValue the attribute value for interpolation (if not interpolated from z-coordinate)
@return 0 in case of success*/
int addVerticesToCache( QgsGeometry* geom, bool zCoord, double attributeValue );
int addVerticesToCache( const QgsGeometry* geom, bool zCoord, double attributeValue );
};

#endif
2 changes: 1 addition & 1 deletion src/analysis/interpolation/qgstininterpolator.cpp
Expand Up @@ -172,7 +172,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
return 1;
}

QgsGeometry* g = f->geometry();
const QgsGeometry* g = f->constGeometry();
{
if ( !g )
{
Expand Down
16 changes: 8 additions & 8 deletions src/analysis/network/qgslinevectorlayerdirector.cpp
Expand Up @@ -166,10 +166,10 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
while ( fit.nextFeature( feature ) )
{
QgsMultiPolyline mpl;
if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString )
mpl = feature.geometry()->asMultiPolyline();
else if ( feature.geometry()->wkbType() == QGis::WKBLineString )
mpl.push_back( feature.geometry()->asPolyline() );
if ( feature.constGeometry()->wkbType() == QGis::WKBMultiLineString )
mpl = feature.constGeometry()->asMultiPolyline();
else if ( feature.constGeometry()->wkbType() == QGis::WKBLineString )
mpl.push_back( feature.constGeometry()->asPolyline() );

QgsMultiPolyline::iterator mplIt;
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
Expand Down Expand Up @@ -300,10 +300,10 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c

// begin features segments and add arc to the Graph;
QgsMultiPolyline mpl;
if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString )
mpl = feature.geometry()->asMultiPolyline();
else if ( feature.geometry()->wkbType() == QGis::WKBLineString )
mpl.push_back( feature.geometry()->asPolyline() );
if ( feature.constGeometry()->wkbType() == QGis::WKBMultiLineString )
mpl = feature.constGeometry()->asMultiPolyline();
else if ( feature.constGeometry()->wkbType() == QGis::WKBLineString )
mpl.push_back( feature.constGeometry()->asPolyline() );

QgsMultiPolyline::iterator mplIt;
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
Expand Down
57 changes: 29 additions & 28 deletions src/analysis/vector/qgsgeometryanalyzer.cpp
Expand Up @@ -122,13 +122,14 @@ bool QgsGeometryAnalyzer::simplify( QgsVectorLayer* layer,

void QgsGeometryAnalyzer::simplifyFeature( QgsFeature& f, QgsVectorFileWriter* vfw, double tolerance )
{
QgsGeometry* featureGeometry = f.geometry();
QgsGeometry* tmpGeometry = 0;

if ( !featureGeometry )
if ( !f.constGeometry() )
{
return;
}

const QgsGeometry* featureGeometry = f.constGeometry();
QgsGeometry* tmpGeometry = 0;

// simplify feature
tmpGeometry = featureGeometry->simplify( tolerance );

Expand Down Expand Up @@ -238,14 +239,14 @@ bool QgsGeometryAnalyzer::centroids( QgsVectorLayer* layer, const QString& shape

void QgsGeometryAnalyzer::centroidFeature( QgsFeature& f, QgsVectorFileWriter* vfw )
{
QgsGeometry* featureGeometry = f.geometry();
QgsGeometry* tmpGeometry = 0;

if ( !featureGeometry )
if ( !f.constGeometry() )
{
return;
}

const QgsGeometry* featureGeometry = f.constGeometry();
QgsGeometry* tmpGeometry = 0;

tmpGeometry = featureGeometry->centroid();

QgsFeature newFeature;
Expand Down Expand Up @@ -572,15 +573,15 @@ bool QgsGeometryAnalyzer::convexHull( QgsVectorLayer* layer, const QString& shap

void QgsGeometryAnalyzer::convexFeature( QgsFeature& f, int nProcessedFeatures, QgsGeometry** dissolveGeometry )
{
QgsGeometry* featureGeometry = f.geometry();
QgsGeometry* tmpGeometry = 0;
QgsGeometry* convexGeometry = 0;

if ( !featureGeometry )
if ( !f.constGeometry() )
{
return;
}

const QgsGeometry* featureGeometry = f.constGeometry();
QgsGeometry* tmpGeometry = 0;
QgsGeometry* convexGeometry = 0;

convexGeometry = featureGeometry->convexHull();

if ( nProcessedFeatures == 0 )
Expand Down Expand Up @@ -732,13 +733,13 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef

void QgsGeometryAnalyzer::dissolveFeature( QgsFeature& f, int nProcessedFeatures, QgsGeometry** dissolveGeometry )
{
QgsGeometry* featureGeometry = f.geometry();

if ( !featureGeometry )
if ( !f.constGeometry() )
{
return;
}

const QgsGeometry* featureGeometry = f.constGeometry();

if ( nProcessedFeatures == 0 )
{
size_t geomSize = featureGeometry->wkbSize();
Expand Down Expand Up @@ -862,16 +863,16 @@ bool QgsGeometryAnalyzer::buffer( QgsVectorLayer* layer, const QString& shapefil
void QgsGeometryAnalyzer::bufferFeature( QgsFeature& f, int nProcessedFeatures, QgsVectorFileWriter* vfw, bool dissolve,
QgsGeometry** dissolveGeometry, double bufferDistance, int bufferDistanceField )
{
double currentBufferDistance;
QgsGeometry* featureGeometry = f.geometry();
QgsGeometry* tmpGeometry = 0;
QgsGeometry* bufferGeometry = 0;

if ( !featureGeometry )
if ( !f.constGeometry() )
{
return;
}

double currentBufferDistance;
const QgsGeometry* featureGeometry = f.constGeometry();
QgsGeometry* tmpGeometry = 0;
QgsGeometry* bufferGeometry = 0;

//create buffer
if ( bufferDistanceField == -1 )
{
Expand Down Expand Up @@ -997,16 +998,16 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
}

QList<QgsFeature> featureIdList = lineLayerIdMap.values( fet.attribute( eventField ).toString() );
QList<QgsFeature>::const_iterator featureIdIt = featureIdList.constBegin();
for ( ; featureIdIt != featureIdList.constEnd(); ++featureIdIt )
QList<QgsFeature>::iterator featureIdIt = featureIdList.begin();
for ( ; featureIdIt != featureIdList.end(); ++featureIdIt )
{
if ( locationField2 == -1 )
{
lrsGeom = locateAlongMeasure( measure1, featureIdIt->geometry() );
lrsGeom = locateAlongMeasure( measure1, featureIdIt->constGeometry() );
}
else
{
lrsGeom = locateBetweenMeasures( measure1, measure2, featureIdIt->geometry() );
lrsGeom = locateBetweenMeasures( measure1, measure2, featureIdIt->constGeometry() );
}

if ( lrsGeom )
Expand Down Expand Up @@ -1194,7 +1195,7 @@ QgsPoint QgsGeometryAnalyzer::createPointOffset( double x, double y, double dist
return QgsPoint( x - normalX, y - normalY ); //negative values -> left side, positive values -> right side
}

QgsGeometry* QgsGeometryAnalyzer::locateBetweenMeasures( double fromMeasure, double toMeasure, QgsGeometry* lineGeom )
QgsGeometry* QgsGeometryAnalyzer::locateBetweenMeasures( double fromMeasure, double toMeasure, const QgsGeometry* lineGeom )
{
if ( !lineGeom )
{
Expand Down Expand Up @@ -1238,7 +1239,7 @@ QgsGeometry* QgsGeometryAnalyzer::locateBetweenMeasures( double fromMeasure, dou
return QgsGeometry::fromMultiPolyline( resultGeom );
}

QgsGeometry* QgsGeometryAnalyzer::locateAlongMeasure( double measure, QgsGeometry* lineGeom )
QgsGeometry* QgsGeometryAnalyzer::locateAlongMeasure( double measure, const QgsGeometry *lineGeom )
{
if ( !lineGeom )
{
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/qgsgeometryanalyzer.h
Expand Up @@ -121,10 +121,10 @@ class ANALYSIS_EXPORT QgsGeometryAnalyzer
bool forceSingleGeometry = false, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );

/**Returns linear reference geometry as a multiline (or 0 if no match). Currently, the z-coordinates are considered to be the measures (no support for m-values in QGIS)*/
QgsGeometry* locateBetweenMeasures( double fromMeasure, double toMeasure, QgsGeometry* lineGeom );
QgsGeometry* locateBetweenMeasures( double fromMeasure, double toMeasure, const QgsGeometry *lineGeom );
/**Returns linear reference geometry. Unlike the PostGIS function, this method always returns multipoint or 0 if no match (not geometry collection).
Currently, the z-coordinates are considered to be the measures (no support for m-values in QGIS)*/
QgsGeometry* locateAlongMeasure( double measure, QgsGeometry* lineGeom );
QgsGeometry* locateAlongMeasure( double measure, const QgsGeometry* lineGeom );

private:

Expand Down
14 changes: 7 additions & 7 deletions src/analysis/vector/qgsoverlayanalyzer.cpp
Expand Up @@ -142,15 +142,15 @@ bool QgsOverlayAnalyzer::intersection( QgsVectorLayer* layerA, QgsVectorLayer* l
void QgsOverlayAnalyzer::intersectFeature( QgsFeature& f, QgsVectorFileWriter* vfw,
QgsVectorLayer* vl, QgsSpatialIndex* index )
{
QgsGeometry* featureGeometry = f.geometry();
QgsGeometry* intersectGeometry = 0;
QgsFeature overlayFeature;

if ( !featureGeometry )
if ( !f.constGeometry() )
{
return;
}

const QgsGeometry* featureGeometry = f.constGeometry();
QgsGeometry* intersectGeometry = 0;
QgsFeature overlayFeature;

QList<QgsFeatureId> intersects;
intersects = index->intersects( featureGeometry->boundingBox() );
QList<QgsFeatureId>::const_iterator it = intersects.constBegin();
Expand All @@ -162,9 +162,9 @@ void QgsOverlayAnalyzer::intersectFeature( QgsFeature& f, QgsVectorFileWriter* v
continue;
}

if ( featureGeometry->intersects( overlayFeature.geometry() ) )
if ( featureGeometry->intersects( overlayFeature.constGeometry() ) )
{
intersectGeometry = featureGeometry->intersection( overlayFeature.geometry() );
intersectGeometry = featureGeometry->intersection( overlayFeature.constGeometry() );

outFeature.setGeometry( intersectGeometry );
QgsAttributes attributesA = f.attributes();
Expand Down
6 changes: 2 additions & 4 deletions src/analysis/vector/qgspointsample.cpp
Expand Up @@ -83,12 +83,10 @@ int QgsPointSample::createRandomPoints( QProgressDialog* pd )

void QgsPointSample::addSamplePoints( QgsFeature& inputFeature, QgsVectorFileWriter& writer, int nPoints, double minDistance )
{
QgsGeometry* geom = inputFeature.geometry();
if ( !geom )
{
if ( !inputFeature.constGeometry() )
return;
}

const QgsGeometry* geom = inputFeature.constGeometry();
QgsRectangle geomRect = geom->boundingBox();
if ( geomRect.isEmpty() )
{
Expand Down

0 comments on commit 2863f20

Please sign in to comment.