mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Merge pull request #2667 from SebDieBln/ZoomToFeatureIds
allow zooming to multiple features by their ID
This commit is contained in:
commit
21cdefa7e8
@ -168,10 +168,10 @@ class QgsMapCanvas : QGraphicsView
|
||||
@param layer optionally specify different than current layer */
|
||||
void zoomToSelected( QgsVectorLayer* layer = NULL );
|
||||
|
||||
/** Set canvas extent to the bounding box of a feature
|
||||
/** Set canvas extent to the bounding box of a set of features
|
||||
@param layer the vector layer
|
||||
@param id the feature id*/
|
||||
void zoomToFeatureId( QgsVectorLayer* layer, QgsFeatureId id );
|
||||
@param ids the feature ids*/
|
||||
void zoomToFeatureIds( QgsVectorLayer* layer, const QgsFeatureIds& ids );
|
||||
|
||||
/** Pan to the selected features of current (vector) layer keeping same extent. */
|
||||
void panToSelected( QgsVectorLayer* layer = NULL );
|
||||
|
@ -409,11 +409,12 @@ void QgsDualView::zoomToCurrentFeature()
|
||||
return;
|
||||
}
|
||||
|
||||
QgsFeatureId id = mFilterModel->rowToId( currentIndex );
|
||||
QgsFeatureIds ids;
|
||||
ids.insert( mFilterModel->rowToId( currentIndex ) );
|
||||
QgsMapCanvas* canvas = mFilterModel->mapCanvas();
|
||||
if ( canvas )
|
||||
{
|
||||
canvas->zoomToFeatureId( mLayerCache->layer(), id );
|
||||
canvas->zoomToFeatureIds( mLayerCache->layer(), ids );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1071,38 +1071,45 @@ void QgsMapCanvas::zoomToFeatureExtent( QgsRectangle& rect )
|
||||
refresh();
|
||||
}
|
||||
|
||||
void QgsMapCanvas::zoomToFeatureId( QgsVectorLayer* layer, QgsFeatureId id )
|
||||
void QgsMapCanvas::zoomToFeatureIds( QgsVectorLayer* layer, const QgsFeatureIds& ids )
|
||||
{
|
||||
if ( !layer )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsFeatureIterator it = layer->getFeatures( QgsFeatureRequest().setFilterFid( id ).setSubsetOfAttributes( QgsAttributeList() ) );
|
||||
QgsFeatureIterator it = layer->getFeatures( QgsFeatureRequest().setFilterFids( ids ).setSubsetOfAttributes( QgsAttributeList() ) );
|
||||
QgsRectangle rect;
|
||||
rect.setMinimal();
|
||||
QgsFeature fet;
|
||||
if ( !it.nextFeature( fet ) )
|
||||
int featureCount = 0;
|
||||
while ( it.nextFeature( fet ) )
|
||||
{
|
||||
QgsGeometry* geom = fet.geometry();
|
||||
QString errorMessage;
|
||||
if ( !geom || !geom->geometry() )
|
||||
{
|
||||
errorMessage = tr( "Feature does not have a geometry" );
|
||||
}
|
||||
else if ( geom->geometry()->isEmpty() )
|
||||
{
|
||||
errorMessage = tr( "Feature geometry is empty" );
|
||||
}
|
||||
if ( !errorMessage.isEmpty() )
|
||||
{
|
||||
emit messageEmitted( tr( "Zoom to feature id failed" ), errorMessage, QgsMessageBar::WARNING );
|
||||
return;
|
||||
}
|
||||
QgsRectangle r = mapSettings().layerExtentToOutputExtent( layer, geom->boundingBox() );
|
||||
rect.combineExtentWith( &r );
|
||||
featureCount++;
|
||||
}
|
||||
|
||||
if ( featureCount != ids.count() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsGeometry* geom = fet.geometry();
|
||||
|
||||
QString errorMessage;
|
||||
if ( !geom || !geom->geometry() )
|
||||
{
|
||||
errorMessage = tr( "Feature does not have a geometry" );
|
||||
}
|
||||
else if ( geom->geometry()->isEmpty() )
|
||||
{
|
||||
errorMessage = tr( "Feature geometry is empty" );
|
||||
}
|
||||
if ( !errorMessage.isEmpty() )
|
||||
{
|
||||
emit messageEmitted( tr( "Zoom to feature id failed" ), errorMessage, QgsMessageBar::WARNING );
|
||||
return;
|
||||
}
|
||||
|
||||
QgsRectangle rect = mapSettings().layerExtentToOutputExtent( layer, geom->boundingBox() );
|
||||
zoomToFeatureExtent( rect );
|
||||
}
|
||||
|
||||
|
@ -238,10 +238,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
||||
@param layer optionally specify different than current layer */
|
||||
void zoomToSelected( QgsVectorLayer* layer = nullptr );
|
||||
|
||||
/** Set canvas extent to the bounding box of a feature
|
||||
/** Set canvas extent to the bounding box of a set of features
|
||||
@param layer the vector layer
|
||||
@param id the feature id*/
|
||||
void zoomToFeatureId( QgsVectorLayer* layer, QgsFeatureId id );
|
||||
@param ids the feature ids*/
|
||||
void zoomToFeatureIds( QgsVectorLayer* layer, const QgsFeatureIds& ids );
|
||||
|
||||
/** Pan to the selected features of current (vector) layer keeping same extent. */
|
||||
void panToSelected( QgsVectorLayer* layer = nullptr );
|
||||
|
Loading…
x
Reference in New Issue
Block a user