Skip to content
Permalink
Browse files

Fix displayed extent for US National Atlas CRS (and others) on projec…

…tion map (#5738)
  • Loading branch information
nirvn committed Dec 2, 2017
1 parent 389435e commit bec099ea33af9b578256abfeae223e69d0fe7fce
@@ -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 );
}
}

@@ -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 );
}
@@ -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()

0 comments on commit bec099e

Please sign in to comment.
You can’t perform that action at this time.