|
26 | 26 | #include "qgssymbollayerv2utils.h"
|
27 | 27 | #include "qgssymbolv2.h"
|
28 | 28 | #include "qgscoordinatereferencesystem.h"
|
| 29 | +#include "qgslogger.h" |
29 | 30 |
|
30 | 31 | #include <QPainter>
|
31 | 32 | #include <QPen>
|
@@ -1525,8 +1526,16 @@ int QgsComposerMapGrid::xGridLinesCRSTransform( const QgsRectangle& bbox, const
|
1525 | 1526 | cont = false;
|
1526 | 1527 | }
|
1527 | 1528 |
|
1528 |
| - QgsPoint mapPoint = t.transform( currentX, currentLevel ); //transform back to map crs |
1529 |
| - gridLine.append( mComposerMap->mapToItemCoords( QPointF( mapPoint.x(), mapPoint.y() ) ) ); //transform back to composer coords |
| 1529 | + try |
| 1530 | + { |
| 1531 | + QgsPoint mapPoint = t.transform( currentX, currentLevel ); //transform back to map crs |
| 1532 | + gridLine.append( mComposerMap->mapToItemCoords( QPointF( mapPoint.x(), mapPoint.y() ) ) ); //transform back to composer coords |
| 1533 | + } |
| 1534 | + catch ( QgsCsException & cse ) |
| 1535 | + { |
| 1536 | + QgsDebugMsg( QString( "Caught CRS exception %1" ).arg( cse.what() ) ); |
| 1537 | + } |
| 1538 | + |
1530 | 1539 | currentX += step;
|
1531 | 1540 | if ( crosses180 && currentX > 180.0 )
|
1532 | 1541 | {
|
@@ -1583,10 +1592,18 @@ int QgsComposerMapGrid::yGridLinesCRSTransform( const QgsRectangle& bbox, const
|
1583 | 1592 | {
|
1584 | 1593 | cont = false;
|
1585 | 1594 | }
|
1586 |
| - //transform back to map crs |
1587 |
| - QgsPoint mapPoint = t.transform( currentLevel, currentY ); |
1588 |
| - //transform back to composer coords |
1589 |
| - gridLine.append( mComposerMap->mapToItemCoords( QPointF( mapPoint.x(), mapPoint.y() ) ) ); |
| 1595 | + try |
| 1596 | + { |
| 1597 | + //transform back to map crs |
| 1598 | + QgsPoint mapPoint = t.transform( currentLevel, currentY ); |
| 1599 | + //transform back to composer coords |
| 1600 | + gridLine.append( mComposerMap->mapToItemCoords( QPointF( mapPoint.x(), mapPoint.y() ) ) ); |
| 1601 | + } |
| 1602 | + catch ( QgsCsException & cse ) |
| 1603 | + { |
| 1604 | + QgsDebugMsg( QString( "Caught CRS exception %1" ).arg( cse.what() ) ); |
| 1605 | + } |
| 1606 | + |
1590 | 1607 | currentY += step;
|
1591 | 1608 | }
|
1592 | 1609 | //clip grid line to map polygon
|
@@ -2018,39 +2035,47 @@ int QgsComposerMapGrid::crsGridParams( QgsRectangle& crsRect, QgsCoordinateTrans
|
2018 | 2035 | return 1;
|
2019 | 2036 | }
|
2020 | 2037 |
|
2021 |
| - QgsCoordinateTransform tr( mComposerMap->composition()->mapSettings().destinationCrs(), mCRS ); |
2022 |
| - QPolygonF mapPolygon = mComposerMap->transformedMapPolygon(); |
2023 |
| - QRectF mbr = mapPolygon.boundingRect(); |
2024 |
| - QgsRectangle mapBoundingRect( mbr.left(), mbr.bottom(), mbr.right(), mbr.top() ); |
2025 |
| - |
2026 |
| - |
2027 |
| - if ( mCRS.geographicFlag() ) |
| 2038 | + try |
2028 | 2039 | {
|
2029 |
| - //handle crossing the 180 degree longitude line |
2030 |
| - QgsPoint lowerLeft( mapBoundingRect.xMinimum(), mapBoundingRect.yMinimum() ); |
2031 |
| - QgsPoint upperRight( mapBoundingRect.xMaximum(), mapBoundingRect.yMaximum() ); |
| 2040 | + QgsCoordinateTransform tr( mComposerMap->composition()->mapSettings().destinationCrs(), mCRS ); |
| 2041 | + QPolygonF mapPolygon = mComposerMap->transformedMapPolygon(); |
| 2042 | + QRectF mbr = mapPolygon.boundingRect(); |
| 2043 | + QgsRectangle mapBoundingRect( mbr.left(), mbr.bottom(), mbr.right(), mbr.top() ); |
2032 | 2044 |
|
2033 |
| - lowerLeft = tr.transform( lowerLeft.x(), lowerLeft.y() ); |
2034 |
| - upperRight = tr.transform( upperRight.x(), upperRight.y() ); |
2035 | 2045 |
|
2036 |
| - if ( lowerLeft.x() > upperRight.x() ) |
| 2046 | + if ( mCRS.geographicFlag() ) |
2037 | 2047 | {
|
2038 |
| - //we've crossed the line |
2039 |
| - crsRect = tr.transformBoundingBox( mapBoundingRect, QgsCoordinateTransform::ForwardTransform, true ); |
| 2048 | + //handle crossing the 180 degree longitude line |
| 2049 | + QgsPoint lowerLeft( mapBoundingRect.xMinimum(), mapBoundingRect.yMinimum() ); |
| 2050 | + QgsPoint upperRight( mapBoundingRect.xMaximum(), mapBoundingRect.yMaximum() ); |
| 2051 | + |
| 2052 | + lowerLeft = tr.transform( lowerLeft.x(), lowerLeft.y() ); |
| 2053 | + upperRight = tr.transform( upperRight.x(), upperRight.y() ); |
| 2054 | + |
| 2055 | + if ( lowerLeft.x() > upperRight.x() ) |
| 2056 | + { |
| 2057 | + //we've crossed the line |
| 2058 | + crsRect = tr.transformBoundingBox( mapBoundingRect, QgsCoordinateTransform::ForwardTransform, true ); |
| 2059 | + } |
| 2060 | + else |
| 2061 | + { |
| 2062 | + //didn't cross the line |
| 2063 | + crsRect = tr.transformBoundingBox( mapBoundingRect ); |
| 2064 | + } |
2040 | 2065 | }
|
2041 | 2066 | else
|
2042 | 2067 | {
|
2043 |
| - //didn't cross the line |
2044 | 2068 | crsRect = tr.transformBoundingBox( mapBoundingRect );
|
2045 | 2069 | }
|
| 2070 | + |
| 2071 | + inverseTransform.setSourceCrs( mCRS ); |
| 2072 | + inverseTransform.setDestCRS( mComposerMap->composition()->mapSettings().destinationCrs() ); |
2046 | 2073 | }
|
2047 |
| - else |
| 2074 | + catch ( QgsCsException & cse ) |
2048 | 2075 | {
|
2049 |
| - crsRect = tr.transformBoundingBox( mapBoundingRect ); |
| 2076 | + QgsDebugMsg( QString( "Caught CRS exception %1" ).arg( cse.what() ) ); |
| 2077 | + return 1; |
2050 | 2078 | }
|
2051 |
| - |
2052 |
| - inverseTransform.setSourceCrs( mCRS ); |
2053 |
| - inverseTransform.setDestCRS( mComposerMap->composition()->mapSettings().destinationCrs() ); |
2054 | 2079 | return 0;
|
2055 | 2080 | }
|
2056 | 2081 |
|
|
0 commit comments