Skip to content

Commit

Permalink
Fix displayed extent for US National Atlas CRS (and others) on projec…
Browse files Browse the repository at this point in the history
…tion map (#5738)
  • Loading branch information
nirvn authored Dec 2, 2017
1 parent 389435e commit bec099e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/core/qgscoordinatereferencesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,11 @@ QgsRectangle QgsCoordinateReferenceSystem::bounds() const
double north = statement.columnAsDouble( 1 );
double east = statement.columnAsDouble( 2 );
double south = statement.columnAsDouble( 3 );
rect = QgsRectangle( west, north, east, south );

rect.setXMinimum( west );
rect.setYMinimum( south );
rect.setXMaximum( east );
rect.setYMaximum( north );
}
}

Expand Down
28 changes: 23 additions & 5 deletions src/gui/qgsprojectionselectiontreewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,14 +1028,32 @@ void QgsProjectionSelectionTreeWidget::updateBoundsPreview()
return;

QgsRectangle rect = currentCrs.bounds();
if ( !rect.isEmpty() )
if ( !qgsDoubleNear( rect.area(), 0.0 ) )
{
mPreviewBand->setToGeometry( QgsGeometry::fromRect( rect ), nullptr );
QgsGeometry geom;
if ( rect.xMinimum() > rect.xMaximum() )
{
QgsRectangle rect1 = QgsRectangle( -180, rect.yMinimum(), rect.xMaximum(), rect.yMaximum() );
QgsRectangle rect2 = QgsRectangle( rect.xMinimum(), rect.yMinimum(), 180, rect.yMaximum() );
geom = QgsGeometry::fromRect( rect1 );
geom.addPart( QgsGeometry::fromRect( rect2 ) );
}
else
{
geom = QgsGeometry::fromRect( rect );
}
mPreviewBand->setToGeometry( geom, nullptr );
mPreviewBand->setColor( QColor( 255, 0, 0, 65 ) );
mAreaCanvas->setExtent( rect );
QgsRectangle extent = geom.boundingBox();
extent.scale( 1.1 );
mAreaCanvas->setExtent( extent );
mAreaCanvas->refresh();
mPreviewBand->show();
mAreaCanvas->zoomOut();
QString extentString = tr( "Extent: %1" ).arg( rect.toString( 2 ) );
QString extentString = tr( "Extent: %1, %2, %3, %4" )
.arg( rect.xMinimum(), 0, 'f', 2 )
.arg( rect.yMinimum(), 0, 'f', 2 )
.arg( rect.xMaximum(), 0, 'f', 2 )
.arg( rect.yMaximum(), 0, 'f', 2 );
QString proj4String = tr( "Proj4: %1" ).arg( selectedProj4String() );
teProjection->setText( extentString + "\n" + proj4String );
}
Expand Down
7 changes: 7 additions & 0 deletions tests/src/core/testqgscoordinatereferencesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,13 @@ void TestQgsCoordinateReferenceSystem::bounds()
QGSCOMPARENEAR( bounds.xMaximum(), 180.000000, 0.0001 );
QGSCOMPARENEAR( bounds.yMinimum(), -90.00000, 0.0001 );
QGSCOMPARENEAR( bounds.yMaximum(), 90.00000, 0.0001 );

QgsCoordinateReferenceSystem crs2163( "EPSG:2163" );
bounds = crs2163.bounds();
QGSCOMPARENEAR( bounds.xMinimum(), 167.65000, 0.0001 );
QGSCOMPARENEAR( bounds.xMaximum(), -65.69000, 0.0001 );
QGSCOMPARENEAR( bounds.yMinimum(), 15.56000, 0.0001 );
QGSCOMPARENEAR( bounds.yMaximum(), 74.71000, 0.0001 );
}

void TestQgsCoordinateReferenceSystem::saveAsUserCrs()
Expand Down

0 comments on commit bec099e

Please sign in to comment.