Skip to content

Commit

Permalink
Fix point distance renderer handling of crs transform
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 29, 2016
1 parent c671bad commit 3dcc69a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/core/symbology-ng/qgspointdistancerenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,27 @@ bool QgsPointDistanceRenderer::renderFeature( QgsFeature& feature, QgsRenderCont
label = getLabel( feature );
}

QgsCoordinateTransform xform = context.coordinateTransform();
QgsFeature transformedFeature = feature;
if ( xform.isValid() )
{
geom.transform( xform );
transformedFeature.setGeometry( geom );
}

double searchDistance = mTolerance * QgsSymbolLayerUtils::mapUnitScaleFactor( context, mToleranceUnit, mToleranceMapUnitScale );
QgsPoint point = feature.geometry().asPoint();
QgsPoint point = transformedFeature.geometry().asPoint();
QList<QgsFeatureId> intersectList = mSpatialIndex->intersects( searchRect( point, searchDistance ) );
if ( intersectList.empty() )
{
mSpatialIndex->insertFeature( feature );
mSpatialIndex->insertFeature( transformedFeature );
// create new group
ClusteredGroup newGroup;
newGroup << GroupedFeature( feature, symbol, selected, label );
newGroup << GroupedFeature( transformedFeature, symbol, selected, label );
mClusteredGroups.push_back( newGroup );
// add to group index
mGroupIndex.insert( feature.id(), mClusteredGroups.count() - 1 );
mGroupLocations.insert( feature.id(), point );
mGroupIndex.insert( transformedFeature.id(), mClusteredGroups.count() - 1 );
mGroupLocations.insert( transformedFeature.id(), point );
}
else
{
Expand All @@ -120,9 +128,9 @@ bool QgsPointDistanceRenderer::renderFeature( QgsFeature& feature, QgsRenderCont
( oldCenter.y() * group.size() + point.y() ) / ( group.size() + 1.0 ) );

// add to a group
group << GroupedFeature( feature, symbol, selected, label );
group << GroupedFeature( transformedFeature, symbol, selected, label );
// add to group index
mGroupIndex.insert( feature.id(), groupIdx );
mGroupIndex.insert( transformedFeature.id(), groupIdx );
}

return true;
Expand All @@ -138,7 +146,8 @@ void QgsPointDistanceRenderer::drawGroup( const ClusteredGroup& group, QgsRender
}
QgsGeometry groupGeom( groupMultiPoint );
QgsGeometry centroid = groupGeom.centroid();
QPointF pt = _getPoint( context, *static_cast<QgsPointV2*>( centroid.geometry() ) );
QPointF pt = centroid.asQPointF();
context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );

context.expressionContext().appendScope( createGroupScope( group ) );
drawGroup( pt, context, group );
Expand Down

0 comments on commit 3dcc69a

Please sign in to comment.