patch_for_3609.diff

Steven Mizuno, 2011-08-12 04:59 AM

Download (4.63 KB)

View differences:

python/core/qgsrasterlayer.sip
381 381
    /** \brief Returns the number of raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */
382 382
    double rasterUnitsPerPixel();
383 383

  
384
    /** \brief Returns the number of horizontal raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */
385
    double rasterUnitsPerPixelX();
386

  
387
    /** \brief Returns the number of vertical raster units per each raster pixel. In a world file, this is normally the fourth row (without the sign) */
388
    double rasterUnitsPerPixelY();
389

  
384 390
    /** \brief Read color table from GDAL raster band */
385 391
//bool readColorTable( int theBandNumber, QList<QgsColorRampShader::ColorRampItem>* theList );
386 392

  
src/app/legend/qgslegend.cpp
2008 2008
      QgsCoordinateTransform ct( r->destinationCrs(), layer->crs() );
2009 2009
      p1 = ct.transform( p1 );
2010 2010
      p2 = ct.transform( p2 );
2011
      double width = sqrt( p1.sqrDist( p2 ) ); // width of reprojected pixel
2012
      // This is not perfect of course, we use the resolution in just one direction
2013
      mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / width ) );
2011
      double width = sqrt( p1.sqrDist( p2 ) ); // diagonal distance of reprojected pixel
2012
      // use raster layer X and Y rasterUnitsPerPixel
2013
      mMapCanvas->zoomByFactor(
2014
            qSqrt( ( layer->rasterUnitsPerPixelX() * layer->rasterUnitsPerPixelX() ) + // calculate diagonal of raster pixel...
2015
                   ( layer->rasterUnitsPerPixelY() * layer->rasterUnitsPerPixelY() )
2016
                 ) / width ); // ...and divide to get ratio
2014 2017
    }
2015 2018
    else
2016 2019
    {
src/core/raster/qgsrasterlayer.cpp
2018 2018
// horisontal one.
2019 2019

  
2020 2020
  //return qAbs( mGeoTransform[1] );
2021
  return rasterUnitsPerPixelX();  // call on the X units per pixel
2022
#if 0
2021 2023
  if ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactResolution && mDataProvider->xSize() > 0 )
2022 2024
  {
2023 2025
    return mDataProvider->extent().width() / mDataProvider->xSize();
2024 2026
  }
2025 2027
  return 1;
2028
#endif
2029
}
2030

  
2031
/**
2032
 * @return the horizontal units per pixel as reported in the  GDAL geotramsform[1]
2033
 * This is the same as rasterUnitsPerPixel()
2034
 */
2035
double QgsRasterLayer::rasterUnitsPerPixelX()
2036
{
2037
// We return one raster pixel per map unit pixel
2038
// One raster pixel can have several raster units...
2039

  
2040
  if ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactResolution && mDataProvider->xSize() > 0 )
2041
  {
2042
    return mDataProvider->extent().width() / mDataProvider->xSize();
2043
  }
2044
  return 1;
2045
}
2046

  
2047
/**
2048
 * @return the vertical units per pixel as reported in the  GDAL geotramsform[5]
2049
 */
2050
double QgsRasterLayer::rasterUnitsPerPixelY()
2051
{
2052
// We return one raster pixel per map unit pixel
2053
// One raster pixel can have several raster units...
2054

  
2055
  if ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactResolution && mDataProvider->ySize() > 0 )
2056
  {
2057
    return mDataProvider->extent().height() / mDataProvider->ySize();
2058
  }
2059
  return 1;
2026 2060
}
2027 2061

  
2028 2062

  
src/core/raster/qgsrasterlayer.h
552 552
    /** \brief Returns the number of raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */
553 553
    double rasterUnitsPerPixel();
554 554

  
555
    /** \brief Returns the number of horizontal raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */
556
    double rasterUnitsPerPixelX();
557

  
558
    /** \brief Returns the number of vertical raster units per each raster pixel. In a world file, this is normally the fourth row (without the sign) */
559
    double rasterUnitsPerPixelY();
560

  
555 561
    /** \brief Read color table from GDAL raster band */
556 562
    // Keep this for QgsRasterLayerProperties
557 563
    bool readColorTable( int theBandNumber, QList<QgsColorRampShader::ColorRampItem>* theList );