Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
backport r15148
git-svn-id: http://svn.osgeo.org/qgis/branches/Release-1_6_0@15171 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Feb 14, 2011
1 parent ecdc73c commit 803f357
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 42 deletions.
7 changes: 6 additions & 1 deletion src/analysis/raster/qgsninecellfilter.cpp
Expand Up @@ -19,6 +19,11 @@
#include "cpl_string.h"
#include <QProgressDialog>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#endif

QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
mInputFile( inputFile ), mOutputFile( outputFile ), mOutputFormat( outputFormat ), mCellSizeX( -1 ), mCellSizeY( -1 ), mInputNodataValue( -1 ), mOutputNodataValue( -1 )
Expand Down Expand Up @@ -191,7 +196,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )

GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
{
GDALDatasetH inputDataset = GDALOpen( mInputFile.toLocal8Bit().data(), GA_ReadOnly );
GDALDatasetH inputDataset = GDALOpen( TO8( mInputFile ), GA_ReadOnly );
if ( inputDataset != NULL )
{
nCellsX = GDALGetRasterXSize( inputDataset );
Expand Down
8 changes: 7 additions & 1 deletion src/analysis/raster/qgsrastercalculator.cpp
Expand Up @@ -22,6 +22,12 @@
#include "cpl_string.h"
#include <QProgressDialog>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#endif

QgsRasterCalculator::QgsRasterCalculator( const QString& formulaString, const QString& outputFile, const QString& outputFormat,
const QgsRectangle& outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry>& rasterEntries ): mFormulaString( formulaString ), mOutputFile( outputFile ), mOutputFormat( outputFormat ),
mOutputRectangle( outputExtent ), mNumOutputColumns( nOutputColumns ), mNumOutputRows( nOutputRows ), mRasterEntries( rasterEntries )
Expand Down Expand Up @@ -57,7 +63,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
{
return 2;
}
GDALDatasetH inputDataset = GDALOpen( it->raster->source().toLocal8Bit().data(), GA_ReadOnly );
GDALDatasetH inputDataset = GDALOpen( TO8( it->raster->source() ), GA_ReadOnly );
if( inputDataset == NULL )
{
return 2;
Expand Down
18 changes: 16 additions & 2 deletions src/analysis/raster/qgsrastercalculator.h
Expand Up @@ -61,8 +61,22 @@ class ANALYSIS_EXPORT QgsRasterCalculator
GDALDatasetH openOutputFile( GDALDriverH outputDriver );

/**Reads raster pixels from a dataset/band
@param targetGeotransformation transformation parameters of the requested raster array (not necessarily the same as the transform of the source dataset */
void readRasterPart( double* targetGeotransform, int xOffset, int yOffset, int nCols, int nRows, double* sourceTransform, GDALRasterBandH sourceBand, float* rasterBuffer );
@param targetGeotransform transformation parameters of the requested raster array
(not necessarily the same as the transform of the source dataset)
@param xOffset x offset
@param yOffset y offset
@param nCols number of columns
@param nRows number of rows
@param sourceTransform source transformation
@param sourceBand source band
@param rasterBuffer raster buffer
*/
void readRasterPart( double* targetGeotransform,
int xOffset, int yOffset,
int nCols, int nRows,
double* sourceTransform,
GDALRasterBandH sourceBand,
float* rasterBuffer );

/**Compares two geotransformations (six parameter double arrays*/
bool transformationsEqual( double* t1, double* t2 ) const;
Expand Down
8 changes: 7 additions & 1 deletion src/analysis/vector/qgszonalstatistics.cpp
Expand Up @@ -23,6 +23,12 @@
#include "cpl_string.h"
#include <QProgressDialog>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#endif

QgsZonalStatistics::QgsZonalStatistics( QgsVectorLayer* polygonLayer, const QString& rasterFile, const QString& attributePrefix, int rasterBand )
: mRasterFilePath( rasterFile )
, mRasterBand( rasterBand )
Expand Down Expand Up @@ -60,7 +66,7 @@ int QgsZonalStatistics::calculateStatistics( QProgressDialog* p )

//open the raster layer and the raster band
GDALAllRegister();
GDALDatasetH inputDataset = GDALOpen( mRasterFilePath.toLocal8Bit().data(), GA_ReadOnly );
GDALDatasetH inputDataset = GDALOpen( TO8( mRasterFilePath ), GA_ReadOnly );
if ( inputDataset == NULL )
{
return 3;
Expand Down
7 changes: 6 additions & 1 deletion src/app/ogr/qgsnewogrconnection.cpp
Expand Up @@ -29,6 +29,11 @@
#include <ogr_api.h>
#include <cpl_error.h>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent, const QString& connType, const QString& connName, Qt::WFlags fl )
: QDialog( parent, fl ),
Expand Down Expand Up @@ -83,7 +88,7 @@ void QgsNewOgrConnection::testConnection()
OGRDataSourceH poDS;
OGRSFDriverH pahDriver;
CPLErrorReset();
poDS = OGROpen( QFile::encodeName( uri ).constData(), false, &pahDriver );
poDS = OGROpen( TO8F( uri ), false, &pahDriver );
if ( poDS == NULL )
{
QMessageBox::information( this, tr( "Test connection" ), tr( "Connection failed - Check settings and try again.\n\nExtended error information:\n%1" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
Expand Down
17 changes: 11 additions & 6 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -74,6 +74,11 @@ email : tim at linfiniti.com
// doubles can take for the current system. (Yes, 20 was arbitrary.)
#define TINY_VALUE std::numeric_limits<double>::epsilon() * 20

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsRasterLayer::QgsRasterLayer(
QString const & path,
Expand Down Expand Up @@ -452,7 +457,7 @@ bool QgsRasterLayer::isValidRasterFileName( QString const & theFileNameQString,
CPLErrorReset();

//open the file using gdal making sure we have handled locale properly
myDataset = GDALOpen( QFile::encodeName( theFileNameQString ).constData(), GA_ReadOnly );
myDataset = GDALOpen( TO8F( theFileNameQString ), GA_ReadOnly );
if ( myDataset == NULL )
{
if ( CPLGetLastErrorNo() != CPLE_OpenFailed )
Expand Down Expand Up @@ -1002,12 +1007,12 @@ QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyrami

//close the gdal dataset and reopen it in read / write mode
GDALClose( mGdalDataset );
mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_Update );
mGdalBaseDataset = GDALOpen( TO8F( mDataSource ), GA_Update );

// if the dataset couldn't be opened in read / write mode, tell the user
if ( !mGdalBaseDataset )
{
mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
mGdalBaseDataset = GDALOpen( TO8F( mDataSource ), GA_ReadOnly );
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
mGdalDataset = mGdalBaseDataset;
return "ERROR_WRITE_FORMAT";
Expand Down Expand Up @@ -1077,7 +1082,7 @@ QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyrami
//something bad happenend
//QString myString = QString (CPLGetLastError());
GDALClose( mGdalBaseDataset );
mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
mGdalBaseDataset = GDALOpen( TO8F( mDataSource ), GA_ReadOnly );
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
mGdalDataset = mGdalBaseDataset;

Expand All @@ -1104,7 +1109,7 @@ QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyrami
{
//close the gdal dataset and reopen it in read only mode
GDALClose( mGdalBaseDataset );
mGdalBaseDataset = GDALOpen( QFile::encodeName( mDataSource ).constData(), GA_ReadOnly );
mGdalBaseDataset = GDALOpen( TO8F( mDataSource ), GA_ReadOnly );
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
mGdalDataset = mGdalBaseDataset;
}
Expand Down Expand Up @@ -5290,7 +5295,7 @@ bool QgsRasterLayer::readFile( QString const &theFilename )
mGdalDataset = NULL;

//open the dataset making sure we handle char encoding of locale properly
mGdalBaseDataset = GDALOpen( QFile::encodeName( theFilename ).constData(), GA_ReadOnly );
mGdalBaseDataset = GDALOpen( TO8F( theFilename ), GA_ReadOnly );

if ( mGdalBaseDataset == NULL )
{
Expand Down
28 changes: 12 additions & 16 deletions src/mapserver/qgssldparser.cpp
Expand Up @@ -76,6 +76,12 @@
#include "qgsidwinterpolator.h"
#include "qgstininterpolator.h"

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#endif

QgsSLDParser::QgsSLDParser( QDomDocument* doc ): QgsConfigParser(), mXMLDoc( doc )
{
mSLDNamespace = "http://www.opengis.net/sld";
Expand Down Expand Up @@ -1279,15 +1285,6 @@ QgsVectorLayer* QgsSLDParser::contourLayerFromRaster( const QDomElement& userSty
GDALRasterBandH hBand;
GDALDatasetH hSrcDS;

QByteArray pszSrcData = rasterLayer->source().toLocal8Bit();
QByteArray pszDstData = tmpFileName.toLocal8Bit();
QByteArray pszElevData = propertyName.toLocal8Bit();

const char *pszSrcFilename = pszSrcData.data();
const char *pszDstFilename = pszDstData.data();
const char *pszElevAttrib = pszElevData.data();
const char *pszFormat = "ESRI Shapefile";

int numberOfLevels = 0;
double currentLevel = 0.0;

Expand Down Expand Up @@ -1315,7 +1312,7 @@ QgsVectorLayer* QgsSLDParser::contourLayerFromRaster( const QDomElement& userSty

int b3D = FALSE, bNoDataSet = FALSE, bIgnoreNoData = FALSE;

hSrcDS = GDALOpen( pszSrcFilename, GA_ReadOnly );
hSrcDS = GDALOpen( TO8( rasterLayer->source() ), GA_ReadOnly );
if ( hSrcDS == NULL )
exit( 2 );

Expand Down Expand Up @@ -1344,19 +1341,18 @@ QgsVectorLayer* QgsSLDParser::contourLayerFromRaster( const QDomElement& userSty
/* Create the outputfile. */
/* -------------------------------------------------------------------- */
OGRDataSourceH hDS;
OGRSFDriverH hDriver = OGRGetDriverByName( pszFormat );
OGRSFDriverH hDriver = OGRGetDriverByName( "ESRI Shapefile" );
OGRFieldDefnH hFld;
OGRLayerH hLayer;
int nElevField = -1;

if ( hDriver == NULL )
{
fprintf( FCGI_stderr, "Unable to find format driver named %s.\n",
pszFormat );
fprintf( FCGI_stderr, "Unable to find format driver named 'ESRI Shapefile'.\n" );
exit( 10 );
}

hDS = OGR_Dr_CreateDataSource( hDriver, pszDstFilename, NULL );
hDS = OGR_Dr_CreateDataSource( hDriver, TO8( tmpFileName ), NULL );
if ( hDS == NULL )
exit( 1 );

Expand All @@ -1371,9 +1367,9 @@ QgsVectorLayer* QgsSLDParser::contourLayerFromRaster( const QDomElement& userSty
OGR_L_CreateField( hLayer, hFld, FALSE );
OGR_Fld_Destroy( hFld );

if ( pszElevAttrib )
if ( !propertyName.isEmpty() )
{
hFld = OGR_Fld_Create( pszElevAttrib, OFTReal );
hFld = OGR_Fld_Create( TO8( propertyName ), OFTReal );
OGR_Fld_SetWidth( hFld, 12 );
OGR_Fld_SetPrecision( hFld, 3 );
OGR_L_CreateField( hLayer, hFld, FALSE );
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/georeferencer/qgsimagewarper.cpp
Expand Up @@ -31,6 +31,12 @@
#include "qgsimagewarper.h"
#include "qgsgeoreftransform.h"

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

bool QgsImageWarper::mWarpCanceled = false;

QgsImageWarper::QgsImageWarper( QWidget *theParent )
Expand All @@ -44,7 +50,7 @@ bool QgsImageWarper::openSrcDSAndGetWarpOpt( const QString &input, const Resampl
{
// Open input file
GDALAllRegister();
hSrcDS = GDALOpen( QFile::encodeName( input ).constData(), GA_ReadOnly );
hSrcDS = GDALOpen( TO8F( input ), GA_ReadOnly );
if ( hSrcDS == NULL ) return false;

// Setup warp options.
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/ogr_converter/dialog.cpp
Expand Up @@ -32,6 +32,12 @@

#include <ogr_api.h>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#endif

Dialog::Dialog( QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
{
Expand Down Expand Up @@ -158,7 +164,7 @@ void Dialog::populateLayers( QString const& url )
{
comboSrcLayer->clear();

OGRDataSourceH ds = OGROpen( url.toAscii().constData(), 0, 0 );
OGRDataSourceH ds = OGROpen( TO8( url ), 0, 0 );
if ( 0 != ds )
{
QString lyrName;
Expand Down Expand Up @@ -199,7 +205,7 @@ bool Dialog::testConnection( QString const& url )
{
bool success = false;

OGRDataSourceH ds = OGROpen( url.toAscii().constData(), 0, 0 );
OGRDataSourceH ds = OGROpen( TO8( url ), 0, 0 );
if ( 0 != ds )
{
success = true;
Expand Down
18 changes: 13 additions & 5 deletions src/plugins/ogr_converter/translator.cpp
Expand Up @@ -20,6 +20,14 @@

#include <ogr_api.h>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#define FROM8(x) QString::fromUtf8(x)
#else
#define TO8(x) (x).toLocal8Bit().constData()
#define FROM8(x) QString::fromLocal8Bit(x)
#endif

Translator::Translator()
: mDstUpdate( false ), mDstLayerOverwrite( true )
{
Expand Down Expand Up @@ -122,7 +130,7 @@ bool Translator::translate()
// TODO: Support translation of all layers from input data source
//for (int i = 0; i < OGR_DS_GetLayerCount(); ++i)

OGRLayerH srcLayer = OGR_DS_GetLayerByName( srcDs, mSrcLayer.toAscii().constData() );
OGRLayerH srcLayer = OGR_DS_GetLayerByName( srcDs, TO8( mSrcLayer ) );
if ( 0 == srcLayer )
{
QgsDebugMsg( "Can not find layer: " + mSrcLayer );
Expand Down Expand Up @@ -198,8 +206,7 @@ bool Translator::translateLayer( OGRDataSourceH srcDs, OGRLayerH srcLayer, OGRDa
// TODO: Implement SRS transformation
OGRSpatialReferenceH dstLayerSrs = OGR_L_GetSpatialRef( srcLayer );

dstLayer = OGR_DS_CreateLayer( dstDs, mDstLayer.toAscii().constData(),
dstLayerSrs, geomType, 0 );
dstLayer = OGR_DS_CreateLayer( dstDs, TO8( mDstLayer ), dstLayerSrs, geomType, 0 );
}
// TODO: Append and createion options not implemented
// else if (!mDstLayerAppend)
Expand Down Expand Up @@ -369,7 +376,8 @@ OGRLayerH Translator::findLayer( OGRDataSourceH ds, QString const& name, int& in

OGRDataSourceH Translator::openDataSource( QString const& url, bool readOnly )
{
OGRDataSourceH ds = OGROpen( url.toAscii().constData(), !readOnly, 0 );
OGRDataSourceH ds = OGROpen( TO8( url ), !readOnly, 0 );

if ( 0 == ds )
{
QgsDebugMsg( "Failed to open: " + url );
Expand Down Expand Up @@ -400,7 +408,7 @@ OGRDataSourceH Translator::openDataTarget( QString const& url, bool update )
// Create the output data source
//
// TODO: Add support for creation options
ds = OGR_Dr_CreateDataSource( drv, url.toAscii().constData(), 0 );
ds = OGR_Dr_CreateDataSource( drv, TO8( url ), 0 );
if ( 0 == ds )
{
QgsDebugMsg( "Failed to open: " + url );
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/oracle_raster/qgsselectgeoraster_ui.cpp
Expand Up @@ -26,6 +26,12 @@

#include "qgsvectorlayer.h"

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#endif

QgsOracleSelectGeoraster::QgsOracleSelectGeoraster( QWidget* parent,
QgisInterface* iface,
Qt::WFlags fl ) : QDialog( parent, fl ), mIface( iface )
Expand Down Expand Up @@ -187,7 +193,7 @@ void QgsOracleSelectGeoraster::showSelection( const QString & line )
* Try to open georaster dataset
*/

hDS = GDALOpenShared( identification.toAscii(), eAccess );
hDS = GDALOpenShared( TO8( identification ), eAccess );

buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
if ( hDS == NULL )
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/spit/qgsshapefile.cpp
Expand Up @@ -47,13 +47,18 @@
#include <netinet/in.h>
#endif

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsShapeFile::QgsShapeFile( QString name, QString encoding )
{
fileName = name;
features = 0;
QgsApplication::registerOgrDrivers();
ogrDataSource = OGROpen( QFile::encodeName( fileName ).constData(), false, NULL );
ogrDataSource = OGROpen( TO8F( fileName ), false, NULL );
if ( ogrDataSource != NULL )
{
valid = true;
Expand Down

0 comments on commit 803f357

Please sign in to comment.