void QgsWFSData::calculateExtentFromFeatures() const { if ( mFeatures.size() < 1 ) { return; } QgsRectangle bbox; QgsFeature* currentFeature = 0; QgsGeometry* currentGeometry = 0; bool bboxInitialised = false; //gets true once bbox has been set to the first geometry for ( int i = 0; i < mFeatures.size(); ++i ) { currentFeature = mFeatures[i]; if ( !currentFeature ) { continue; } currentGeometry = currentFeature->geometry(); if ( currentGeometry ) { if ( !bboxInitialised ) { bbox = currentGeometry->boundingBox(); bboxInitialised = true; } else { bbox.unionRect( currentGeometry->boundingBox() ); } } } ( *mExtent ) = bbox; }
void QgsGeometryCheckerResultTab::highlightErrors( bool current ) { qDeleteAll( mCurrentRubberBands ); mCurrentRubberBands.clear(); QList<QTableWidgetItem*> items; QList<QgsPoint> errorPositions; QgsRectangle totextent; if ( current ) { items.append( ui.tableWidgetErrors->currentItem() ); } else { items.append( ui.tableWidgetErrors->selectedItems() ); } foreach ( QTableWidgetItem* item, items ) { QgsGeometryCheckError* error = ui.tableWidgetErrors->item( item->row(), 0 )->data( Qt::UserRole ).value<QgsGeometryCheckError*>(); QgsAbstractGeometryV2* geometry = error->geometry(); if ( ui.checkBoxHighlight->isChecked() && geometry ) { QgsRubberBand* featureRubberBand = new QgsRubberBand( mIface->mapCanvas() ); QgsGeometry geom( geometry ); featureRubberBand->addGeometry( &geom, mFeaturePool->getLayer() ); featureRubberBand->setWidth( 5 ); featureRubberBand->setColor( Qt::yellow ); mCurrentRubberBands.append( featureRubberBand ); } else { // QgsGeometry above takes ownership of geometry and deletes it when it goes out of scope delete geometry; geometry = 0; } if ( ui.radioButtonError->isChecked() || current || error->status() == QgsGeometryCheckError::StatusFixed ) { QgsRubberBand* pointRubberBand = new QgsRubberBand( mIface->mapCanvas(), QGis::Point ); QgsPoint pos = mIface->mapCanvas()->mapSettings().layerToMapCoordinates( mFeaturePool->getLayer(), QgsPoint( error->location().x(), error->location().y() ) ); pointRubberBand->addPoint( pos ); pointRubberBand->setWidth( 20 ); pointRubberBand->setColor( Qt::red ); mCurrentRubberBands.append( pointRubberBand ); errorPositions.append( pos ); } else if ( ui.radioButtonFeature->isChecked() && geometry ) { QgsRectangle geomextent = mIface->mapCanvas()->mapSettings().layerExtentToOutputExtent( mFeaturePool->getLayer(), geometry->boundingBox() ); if ( totextent.isEmpty() ) { totextent = geomextent; } else { totextent.unionRect( geomextent ); } } }
QgsRectangle QgsMapSettings::fullExtent() const { QgsDebugMsg( "called." ); QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance(); // reset the map canvas extent since the extent may now be smaller // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction QgsRectangle fullExtent; fullExtent.setMinimal(); // iterate through the map layers and test each layers extent // against the current min and max values QStringList::const_iterator it = mLayers.begin(); QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayers.count() ) ); while ( it != mLayers.end() ) { QgsMapLayer * lyr = registry->mapLayer( *it ); if ( !lyr ) { QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) ); } else { QgsDebugMsg( "Updating extent using " + lyr->name() ); QgsDebugMsg( "Input extent: " + lyr->extent().toString() ); if ( lyr->extent().isNull() ) { ++it; continue; } // Layer extents are stored in the coordinate system (CS) of the // layer. The extent must be projected to the canvas CS QgsRectangle extent = layerExtentToOutputExtent( lyr, lyr->extent() ); QgsDebugMsg( "Output extent: " + extent.toString() ); fullExtent.unionRect( extent ); } ++it; } if ( fullExtent.width() == 0.0 || fullExtent.height() == 0.0 ) { // If all of the features are at the one point, buffer the // rectangle a bit. If they are all at zero, do something a bit // more crude. if ( fullExtent.xMinimum() == 0.0 && fullExtent.xMaximum() == 0.0 && fullExtent.yMinimum() == 0.0 && fullExtent.yMaximum() == 0.0 ) { fullExtent.set( -1.0, -1.0, 1.0, 1.0 ); } else { const double padFactor = 1e-8; double widthPad = fullExtent.xMinimum() * padFactor; double heightPad = fullExtent.yMinimum() * padFactor; double xmin = fullExtent.xMinimum() - widthPad; double xmax = fullExtent.xMaximum() + widthPad; double ymin = fullExtent.yMinimum() - heightPad; double ymax = fullExtent.yMaximum() + heightPad; fullExtent.set( xmin, ymin, xmax, ymax ); } } QgsDebugMsg( "Full extent: " + fullExtent.toString() ); return fullExtent; }