27 #include <QDomElement> 34 , mLabelAttributeName( labelAttributeName )
52 Q_UNUSED( drawVertexMarker )
83 label = getLabel( feature );
97 if ( intersectList.empty() )
112 double minDist =
mGroupLocations.value( minDistFeatureId ).distance( point );
113 for (
int i = 1; i < intersectList.count(); ++i )
116 double newDist =
mGroupLocations.value( candidateId ).distance( point );
117 if ( newDist < minDist )
120 minDistFeatureId = candidateId;
130 ( oldCenter.
y() * group.size() + point.
y() ) / ( group.size() + 1.0 ) );
145 const auto constGroup = group;
148 groupMultiPoint->
addGeometry( f.feature.geometry().constGet()->clone() );
156 drawGroup( pt, context, group );
174 mRenderer->setLegendSymbolItem( key, symbol );
182 return mRenderer->legendSymbolItemsCheckable();
190 return mRenderer->legendSymbolItemChecked( key );
198 mRenderer->checkLegendSymbolItem( key, state );
220 QSet<QString> attributeList;
227 attributeList +=
mRenderer->usedAttributes( context );
229 return attributeList;
261 return mRenderer->symbolForFeature( feature, context );
268 return mRenderer->originalSymbolForFeature( feature, context );
277 return mRenderer->symbolsForFeature( feature, context );
284 return mRenderer->originalSymbolsForFeature( feature, context );
290 return QSet< QString >() << QString();
291 return mRenderer->legendKeysForFeature( feature, context );
300 return mRenderer->willRenderFeature( feature, context );
308 mRenderer->startRender( context, fields );
345 drawGroup( group, context );
369 return QgsRectangle( p.
x() - distance, p.
y() - distance, p.
x() + distance, p.
y() + distance );
372 void QgsPointDistanceRenderer::printGroupInfo()
const 376 QgsDebugMsg(
"number of displacement groups:" + QString::number( nGroups ) );
377 for (
int i = 0; i < nGroups; ++i )
379 QgsDebugMsg(
"***************displacement group " + QString::number( i ) );
389 QString QgsPointDistanceRenderer::getLabel(
const QgsFeature &feature )
const 409 p->setPen( labelPen );
415 pixelSizeFont.setPixelSize( static_cast< int >( std::round( fontSizeInPixels ) ) );
416 QFont scaledFont = pixelSizeFont;
417 scaledFont.setPixelSize( pixelSizeFont.pixelSize() );
418 p->setFont( scaledFont );
420 QFontMetricsF fontMetrics( pixelSizeFont );
421 QPointF currentLabelShift;
423 QList<QPointF>::const_iterator labelPosIt = labelShifts.constBegin();
424 ClusteredGroup::const_iterator groupIt = group.constBegin();
426 for ( ; labelPosIt != labelShifts.constEnd() && groupIt != group.constEnd(); ++labelPosIt, ++groupIt )
428 currentLabelShift = *labelPosIt;
429 if ( currentLabelShift.x() < 0 )
431 currentLabelShift.setX( currentLabelShift.x() - fontMetrics.width( groupIt->label ) );
433 if ( currentLabelShift.y() > 0 )
435 currentLabelShift.setY( currentLabelShift.y() + fontMetrics.ascent() );
438 QPointF drawingPoint( centerPoint + currentLabelShift );
440 p->translate( drawingPoint.x(), drawingPoint.y() );
441 p->drawText( QPointF( 0, 0 ), groupIt->label );
449 if ( group.size() > 1 )
453 ClusteredGroup::const_iterator groupIt = group.constBegin();
454 for ( ; groupIt != group.constEnd(); ++groupIt )
456 if ( !groupIt->symbol() )
459 if ( !groupColor.isValid() )
461 groupColor = groupIt->symbol()->color();
465 if ( groupColor != groupIt->symbol()->color() )
467 groupColor = QColor();
473 if ( groupColor.isValid() )
485 if ( !group.empty() )
488 clusterScope->
setFeature( group.at( 0 ).feature );
501 if ( symbolList.isEmpty() )
int lookupField(const QString &fieldName) const
Looks 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.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsUnitTypes::RenderUnit mToleranceUnit
Unit for distance tolerance.
QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns list of symbols used for rendering the feature.
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Abstract base class for all rendered symbols.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
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.
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...
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
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.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
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.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
An interface for classes which can visit style entity (e.g.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QMap< QString, QString > QgsStringMap
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
A marker symbol type, for rendering Point and MultiPoint geometries.
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.
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...
QMap< QgsFeatureId, QgsPointXY > mGroupLocations
Mapping of feature ID to approximate group location.
bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns whether the renderer will render a feature or not.
QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
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.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QgsMapUnitScale mToleranceMapUnitScale
Map unit scale for distance tolerance.
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
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.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
A spatial index for QgsFeature objects.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
#define FID_TO_STRING(fid)
Points (e.g., for font sizes)
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
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 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 renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override SIP_THROW(QgsCsException)
Render a feature using this renderer in the given context.
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()...
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=nullptr) override
Adds a feature to the index.
void setEmbeddedRenderer(QgsFeatureRenderer *r) override
Sets an embedded renderer (subrenderer) for this feature renderer.
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
static Type flatType(Type type)
Returns the flat type for a WKB type.
RAII class to pop scope from an expression context on destruction.
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
Returns 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
Returns a list of attributes required by this renderer.
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.