25 #include <QDomElement> 32 , mLabelAttributeName( labelAttributeName )
50 Q_UNUSED( drawVertexMarker );
81 label = getLabel( feature );
95 if ( intersectList.empty() )
110 double minDist =
mGroupLocations.value( minDistFeatureId ).distance( point );
111 for (
int i = 1; i < intersectList.count(); ++i )
114 double newDist =
mGroupLocations.value( candidateId ).distance( point );
115 if ( newDist < minDist )
118 minDistFeatureId = candidateId;
128 ( oldCenter.
y() * group.size() + point.
y() ) / ( group.size() + 1.0 ) );
153 drawGroup( pt, context, group );
172 mRenderer->setLegendSymbolItem( key, symbol );
180 return mRenderer->legendSymbolItemsCheckable();
188 return mRenderer->legendSymbolItemChecked( key );
196 mRenderer->checkLegendSymbolItem( key, state );
209 QSet<QString> attributeList;
216 attributeList +=
mRenderer->usedAttributes( context );
218 return attributeList;
245 return mRenderer->symbolForFeature( feature, context );
252 return mRenderer->originalSymbolForFeature( feat, context );
261 return mRenderer->symbolsForFeature( feature, context );
268 return mRenderer->originalSymbolsForFeature( feat, context );
274 return QSet< QString >() << QString();
275 return mRenderer->legendKeysForFeature( feat, context );
284 return mRenderer->willRenderFeature( feat, context );
292 mRenderer->startRender( context, fields );
326 drawGroup( group, context );
349 return QgsRectangle( p.
x() - distance, p.
y() - distance, p.
x() + distance, p.
y() + distance );
352 void QgsPointDistanceRenderer::printGroupInfo()
const 356 QgsDebugMsg(
"number of displacement groups:" + QString::number( nGroups ) );
357 for (
int i = 0; i < nGroups; ++i )
359 QgsDebugMsg(
"***************displacement group " + QString::number( i ) );
368 QString QgsPointDistanceRenderer::getLabel(
const QgsFeature &feature )
const 388 p->setPen( labelPen );
393 QFont scaledFont = pixelSizeFont;
394 scaledFont.setPixelSize( pixelSizeFont.pixelSize() );
395 p->setFont( scaledFont );
397 QFontMetricsF fontMetrics( pixelSizeFont );
398 QPointF currentLabelShift;
400 QList<QPointF>::const_iterator labelPosIt = labelShifts.constBegin();
401 ClusteredGroup::const_iterator groupIt = group.constBegin();
403 for ( ; labelPosIt != labelShifts.constEnd() && groupIt != group.constEnd(); ++labelPosIt, ++groupIt )
405 currentLabelShift = *labelPosIt;
406 if ( currentLabelShift.x() < 0 )
408 currentLabelShift.setX( currentLabelShift.x() - fontMetrics.width( groupIt->label ) );
410 if ( currentLabelShift.y() > 0 )
412 currentLabelShift.setY( currentLabelShift.y() + fontMetrics.ascent() );
415 QPointF drawingPoint( centerPoint + currentLabelShift );
417 p->translate( drawingPoint.x(), drawingPoint.y() );
418 p->drawText( QPointF( 0, 0 ), groupIt->label );
426 if ( group.size() > 1 )
430 ClusteredGroup::const_iterator groupIt = group.constBegin();
431 for ( ; groupIt != group.constEnd(); ++groupIt )
433 if ( !groupIt->symbol() )
436 if ( !groupColor.isValid() )
438 groupColor = groupIt->symbol()->color();
442 if ( groupColor != groupIt->symbol()->color() )
444 groupColor = QColor();
450 if ( groupColor.isValid() )
462 if ( !group.empty() )
465 clusterScope->
setFeature( group.at( 0 ).feature );
478 if ( symbolList.isEmpty() )
int lookupField(const QString &fieldName) const
Look up field's index from the field name.
QgsSpatialIndex * mSpatialIndex
Spatial index for fast lookup of nearby points.
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
Single variable definition for use within a QgsExpressionContextScope.
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
A rectangle specified with double values.
QString mLabelAttributeName
Attribute name for labeling. An empty string indicates that no labels should be rendered.
double rendererScale() const
Returns the renderer map scale.
QgsSymbol * symbolForFeature(QgsFeature &feature, QgsRenderContext &context) override
To be overridden.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsUnitTypes::RenderUnit mToleranceUnit
Unit for distance tolerance.
QgsSymbol * originalSymbolForFeature(QgsFeature &feat, QgsRenderContext &context) override
Return symbol for feature.
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
QgsPointDistanceRenderer(const QString &rendererName, const QString &labelAttributeName=QString())
Constructor for QgsPointDistanceRenderer.
Multi point geometry collection.
QgsFeatureRenderer::Capabilities capabilities() override
Returns details about internals of this renderer.
QgsFeature feature
Feature.
QgsSymbolList symbols(QgsRenderContext &context) override
Returns list of symbols used by the renderer.
void checkLegendSymbolItem(const QString &key, bool state) override
item in symbology was checked
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
A class to represent a 2D point.
Helper functions for various unit types.
virtual QString filter(const QgsFields &fields=QgsFields())
If a renderer does not require all the features this method may be overridden and return an expressio...
#define FID_TO_STRING(fid)
double outputLineWidth(double width) const
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const override
used from subclasses to create SLD Rule elements following SLD v1.1 specs
Container of fields for a vector layer.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
A geometry is the spatial representation of a feature.
QMap< QgsFeatureId, int > mGroupIndex
Mapping of feature ID to the feature's group index.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
bool insertFeature(const QgsFeature &feature)
Adds a feature to the index.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
QMap< QString, QString > QgsStringMap
bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override
Render a feature using this renderer in the given context.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
QgsSymbolList symbolsForFeature(QgsFeature &feat, QgsRenderContext &context) override
Returns list of symbols used for rendering the feature.
bool mDrawLabels
Whether labels should be drawn for points. This is set internally from startRender() depending on sca...
double mMinLabelScale
Maximum scale denominator for label display. A zero value indicates no scale limitation.
void drawLabels(QPointF centerPoint, QgsSymbolRenderContext &context, const QList< QPointF > &labelShifts, const ClusteredGroup &group)
Renders the labels for a group.
static QString encodeColor(const QColor &color)
void transformInPlace(double &x, double &y) const
Transform device coordinates to map coordinates.
QgsSymbolList originalSymbolsForFeature(QgsFeature &feat, QgsRenderContext &context) override
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
Type
The WKB type describes the number of dimensions a geometry has.
QFont mLabelFont
Label font.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
QList< QgsSymbol * > QgsSymbolList
double mTolerance
Distance tolerance. Points that are closer together than this distance are considered clustered...
QSet< QString > legendKeysForFeature(QgsFeature &feature, QgsRenderContext &context) override
Return legend keys matching a specified feature.
QMap< QgsFeatureId, QgsPointXY > mGroupLocations
Mapping of feature ID to approximate group location.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context, or an invalid transform is no coordinate tr...
QColor mLabelColor
Label text color.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QgsMapUnitScale mToleranceMapUnitScale
Map unit scale for distance tolerance.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsExpressionContext & expressionContext()
Gets the expression context.
Contains properties for a feature within a clustered group.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
QString filter(const QgsFields &fields=QgsFields()) override
If a renderer does not require all the features this method may be overridden and return an expressio...
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
Contains information about the context of a rendering operation.
A spatial index for QgsFeature objects.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
QgsPointXY asPoint() const
Returns contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
std::unique_ptr< QgsFeatureRenderer > mRenderer
Embedded base renderer. This can be used for rendering individual, isolated points.
QPointF asQPointF() const
Returns contents of the geometry as a QPointF if wkbType is WKBPoint, otherwise returns a null QPoint...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
QList< QgsPointDistanceRenderer::GroupedFeature > ClusteredGroup
A group of clustered points (ie features within the distance tolerance).
bool willRenderFeature(QgsFeature &feat, QgsRenderContext &context) override
Returns whether the renderer will render a feature or not.
QList< ClusteredGroup > mClusteredGroups
Groups of features that are considered clustered together.
int mLabelIndex
Label attribute index (or -1 if none). This index is not stored, it is requested in the startRender()...
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
void setEmbeddedRenderer(QgsFeatureRenderer *r) override
Sets an embedded renderer (subrenderer) for this feature renderer.
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
return a new renderer - used by default in vector layers
static Type flatType(Type type)
Returns the flat type for a WKB type.
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.
QgsMarkerSymbol * clone() const override
Get a deep copy of this symbol.
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Return a list of attributes required by this renderer.