Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Georeferencer: Implement resampling with user-specified target resolu…
…tion (enhancement request #2447).

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12965 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mmassing committed Feb 23, 2010
1 parent 9fd773a commit 84752bb
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 280 deletions.
37 changes: 27 additions & 10 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Expand Up @@ -264,7 +264,7 @@ bool QgsGeorefPluginGui::getTransformSettings()
}

d.getTransformSettings(mTransformParam, mResamplingMethod, mCompressionMethod,
mModifiedRasterFileName, mProjection, mUseZeroForTrans, mLoadInQgis);
mModifiedRasterFileName, mProjection, mUseZeroForTrans, mLoadInQgis, mUserResX, mUserResY);
mTransformParamLabel->setText(tr("Transform: ") + convertTransformEnumToString(mTransformParam));
mGeorefTransform.selectTransformParametrisation(mTransformParam);
mGCPListWidget->setGeorefTransform(&mGeorefTransform);
Expand Down Expand Up @@ -300,9 +300,12 @@ void QgsGeorefPluginGui::generateGDALScript()
QString gdalwarpCommand;
QString resamplingStr = convertResamplingEnumToString(mResamplingMethod);
if (QgsGeorefTransform::ThinPlateSpline == mTransformParam)
gdalwarpCommand = gdalwarpCommandTPS(resamplingStr, mCompressionMethod, mUseZeroForTrans);
gdalwarpCommand = gdalwarpCommandTPS(resamplingStr, mCompressionMethod, mUseZeroForTrans,
mUserResX, mUserResY);
else
gdalwarpCommand = gdalwarpCommandGCP(resamplingStr, mCompressionMethod, mUseZeroForTrans, polynomeOrder(mTransformParam));
gdalwarpCommand = gdalwarpCommandGCP(resamplingStr, mCompressionMethod, mUseZeroForTrans,
polynomeOrder(mTransformParam),
mUserResX, mUserResY);

showGDALScript(2, gdal_translateCommand().toAscii().data(), gdalwarpCommand.toAscii().data());
}
Expand Down Expand Up @@ -1072,7 +1075,7 @@ bool QgsGeorefPluginGui::georeference()
{
QgsImageWarper warper(this);
int res = warper.warpFile( mRasterFileName, mModifiedRasterFileName, mGeorefTransform,
mResamplingMethod, mUseZeroForTrans, mCompressionMethod, mProjection);
mResamplingMethod, mUseZeroForTrans, mCompressionMethod, mProjection, mUserResX, mUserResY);
if (res == 0) // fault to compute GCP transform
{
//TODO: be more specific in the error message
Expand Down Expand Up @@ -1177,22 +1180,36 @@ QString QgsGeorefPluginGui::gdal_translateCommand(bool generateTFW)
}

QString QgsGeorefPluginGui::gdalwarpCommandGCP(QString resampling, QString compress,
bool useZeroForTrans, int order)
bool useZeroForTrans, int order,
double targetResX, double targetResY)
{
QStringList gdalCommand;
gdalCommand << "gdalwarp" << "-r" << resampling << "-order" << QString::number(order)
<< "-co COMPRESS" << compress << (useZeroForTrans ? "-dstalpha" : "")
<< mTranslatedRasterFileName << mModifiedRasterFileName;
<< "-co COMPRESS="+compress << (useZeroForTrans ? "-dstalpha" : "");

if (targetResX != 0.0 && targetResY != 0.0)
{
gdalCommand << "-tr" << QString::number(targetResX, 'f') << QString::number(targetResY, 'f');
}

gdalCommand << mTranslatedRasterFileName << mModifiedRasterFileName;

return gdalCommand.join(" ");
}

QString QgsGeorefPluginGui::gdalwarpCommandTPS(QString resampling, QString compress, bool useZeroForTrans)
QString QgsGeorefPluginGui::gdalwarpCommandTPS(QString resampling, QString compress, bool useZeroForTrans,
double targetResX, double targetResY)
{
QStringList gdalCommand;
gdalCommand << "gdalwarp" << "-r" << resampling << "-tps"
<< "-co COMPRESS" << compress << (useZeroForTrans ? "-dstalpha" : "")
<< mTranslatedRasterFileName << mModifiedRasterFileName;
<< "-co COMPRESS="+compress << (useZeroForTrans ? "-dstalpha" : "");

if (targetResX != 0.0 && targetResY != 0.0)
{
gdalCommand << "-tr" << QString::number(targetResX, 'f') << QString::number(targetResY, 'f');
}

gdalCommand << mTranslatedRasterFileName << mModifiedRasterFileName;

return gdalCommand.join(" ");
}
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/georeferencer/qgsgeorefplugingui.h
Expand Up @@ -136,9 +136,10 @@ private slots:
// gdal script
void showGDALScript(int argNum...);
QString gdal_translateCommand(bool generateTFW = true);
QString gdalwarpCommandGCP(QString resampling, QString compress, bool useZeroForTrans,
int order);
QString gdalwarpCommandTPS(QString resampling, QString compress, bool useZeroForTrans);
QString gdalwarpCommandGCP(QString resampling, QString compress, bool useZeroForTrans, int order,
double targetResX, double targetResY);
QString gdalwarpCommandTPS(QString resampling, QString compress, bool useZeroForTrans,
double targetResX, double targetResY);

// log
void showMessageInLog(const QString &description, const QString &msg);
Expand Down Expand Up @@ -180,6 +181,7 @@ private slots:
QString mTranslatedRasterFileName;
QString mGCPpointsFileName;
QString mProjection;
double mUserResX, mUserResY; // User specified target scale

QgsGeorefTransform::TransformParametrisation mTransformParam;
QgsImageWarper::ResamplingMethod mResamplingMethod;
Expand Down
68 changes: 0 additions & 68 deletions src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.cpp

This file was deleted.

34 changes: 0 additions & 34 deletions src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.h

This file was deleted.

158 changes: 0 additions & 158 deletions src/plugins/georeferencer/qgsgeorefwarpoptionsdialogbase.ui

This file was deleted.

0 comments on commit 84752bb

Please sign in to comment.