Skip to content
Permalink
Browse files
[GRASS] browser import options dialog
  • Loading branch information
blazek committed May 25, 2015
1 parent 407f721 commit 6a6b3b41510fbc8bae7974a08b9b30de387a9587

Large diffs are not rendered by default.

@@ -38,6 +38,14 @@ class QgsPoint;
class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
{
public:
/** Precison defines if each pixel is reprojected or approximate reprojection based
* on an approximation matrix of reprojected points is used. */
enum Precision
{
Approximate = 0, //!< Approximate (default), fast but possibly inaccurate
Exact = 1, //!< Exact, precise but slow
};

/** \brief QgsRasterProjector implements approximate projection support for
* it calculates grid of points in source CRS for target CRS + extent
* which are used to calculate affine transformation matrices.
@@ -101,12 +109,21 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
}

Precision precision() const { return mPrecision; }
void setPrecision( Precision precision ) { mPrecision = precision; }
// Translated precision mode, for use in ComboBox etc.
static QString precisionLabel( Precision precision );

QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) override;

/** Calculate destination extent and size from source extent and size
*/
/** Calculate destination extent and size from source extent and size */
bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
QgsRectangle& theDestExtent, int& theDestXSize, int& theDesYSize );
QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );

/** Calculate destination extent and size from source extent and size */
static bool extentSize( const QgsCoordinateTransform* ct,
const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );

private:
/** get source extent */
@@ -265,7 +282,11 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
double mMaxSrcXRes;
double mMaxSrcYRes;

/** Use approximation */
/** Requested precision */
Precision mPrecision;

/** Use approximation (requested precision is Approximate and it is possible to calculate
* an approximation matrix with a sufficient precision) */
bool mApproximate;
};

@@ -1,2 +1,5 @@
INCLUDE_DIRECTORIES(${GRASS_INCLUDE_DIR})
INCLUDE_DIRECTORIES(
${GRASS_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
ADD_GRASSLIB(6)
@@ -1,2 +1,5 @@
INCLUDE_DIRECTORIES(${GRASS_INCLUDE_DIR7})
INCLUDE_DIRECTORIES(
${GRASS_INCLUDE_DIR7}
${CMAKE_CURRENT_BINARY_DIR}
)
ADD_GRASSLIB(7)
@@ -22,9 +22,29 @@ MACRO(ADD_GRASSLIB GRASS_BUILD_VERSION)
SET(GRASS_MAJOR_VERSION ${GRASS_MAJOR_VERSION${GRASS_BUILD_VERSION}})
SET(GRASS_MINOR_VERSION ${GRASS_MINOR_VERSION${GRASS_BUILD_VERSION}})

QT4_WRAP_CPP(GRASS_LIBRARY_MOC_SRCS ../qgsgrassprovider.h ../qgsgrassimport.h)
QT4_WRAP_CPP(GRASS_LIBRARY_MOC_SRCS
../qgsgrassprovider.h
../qgsgrassimport.h
../qgsgrassoptions.h
)

SET (GRASS_LIBRARY_SRCS
../qgsgrass.cpp
../qgsgrassfeatureiterator.cpp
../qgsgrassprovider.cpp
../qgsgrassimport.cpp
../qgsgrassoptions.cpp
)

ADD_LIBRARY(qgisgrass${GRASS_BUILD_VERSION} SHARED ../qgsgrass.cpp ../qgsgrassfeatureiterator.cpp ../qgsgrassprovider.cpp ../qgsgrassimport.cpp ${GRASS_LIBRARY_MOC_SRCS})
QT4_WRAP_UI (GRASS_LIBRARY_UIS_H
../qgsgrassoptionsbase.ui
)

ADD_LIBRARY(qgisgrass${GRASS_BUILD_VERSION} SHARED
${GRASS_LIBRARY_SRCS}
${GRASS_LIBRARY_MOC_SRCS}
${GRASS_LIBRARY_UIS_H}
)

SET_TARGET_PROPERTIES(qgisgrass${GRASS_BUILD_VERSION} PROPERTIES
CLEAN_DIRECT_OUTPUT 1
@@ -53,6 +73,7 @@ MACRO(ADD_GRASSLIB GRASS_BUILD_VERSION)
IF (GRASS_MAJOR_VERSION LESS 7 )
SET(GRASS_TARGET_LINK_LIBRARIES${GRASS_BUILD_VERSION}
qgis_core
qgis_gui
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_vect}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmibase}
@@ -62,6 +83,7 @@ MACRO(ADD_GRASSLIB GRASS_BUILD_VERSION)
ELSE (GRASS_MAJOR_VERSION LESS 7 )
SET(GRASS_TARGET_LINK_LIBRARIES${GRASS_BUILD_VERSION}
qgis_core
qgis_gui
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_vector}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_raster}
@@ -201,7 +201,7 @@ QRegExp GRASS_LIB_EXPORT QgsGrassObject::newNameRegExp( Type type )
}
else
{
rx.setPattern( "[A-Za-z0-9_.]+" );
rx.setPattern( "[A-Za-z0-9_\\-][A-Za-z0-9_\\-.]+" );
}
return rx;
}
@@ -214,7 +214,7 @@ bool QgsGrassRasterImport::import()
{
if ( !block->convert( qgis_out_type ) )
{
setError( "cannot convert data type" );
setError( tr( "Cannot convert block (%1) to data type %2" ).arg( block->toString() ).arg( qgis_out_type ) );
delete block;
return false;
}
@@ -0,0 +1,52 @@
/***************************************************************************
qgsgrassoptions.cpp
-------------------
begin : May, 2015
copyright : (C) 2015 Radim Blazek
email : radim.blazek@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsrasterprojector.h"

#include "qgsgrassoptions.h"
#include "ui_qgsgrassoptionsbase.h"

QgsGrassOptions::QgsGrassOptions(QWidget *parent)
: QDialog(parent)
, QgsGrassOptionsBase()
, mImportSettingsPath("/GRASS/browser/import")
{
setupUi(this);

connect( this, SIGNAL( accepted() ), this, SLOT( saveOptions() ) );

QSettings settings;

QgsRasterProjector::Precision crsTransform = (QgsRasterProjector::Precision) settings.value( mImportSettingsPath + "/crsTransform", QgsRasterProjector::Approximate).toInt();
mCrsTransformationComboBox->addItem ( QgsRasterProjector::precisionLabel(QgsRasterProjector::Approximate), QgsRasterProjector::Approximate);
mCrsTransformationComboBox->addItem ( QgsRasterProjector::precisionLabel(QgsRasterProjector::Exact), QgsRasterProjector::Exact);
mCrsTransformationComboBox->setCurrentIndex ( mCrsTransformationComboBox->findData(crsTransform) );

mImportExternalCheckBox->setChecked( settings.value(mImportSettingsPath + "/external", true).toBool() );
}

QgsGrassOptions::~QgsGrassOptions()
{
}

void QgsGrassOptions::saveOptions()
{
QSettings settings;

settings.setValue( mImportSettingsPath + "/crsTransform",
mCrsTransformationComboBox->itemData( mCrsTransformationComboBox->currentIndex() ).toInt() );

settings.setValue( mImportSettingsPath + "/external", mImportExternalCheckBox->isChecked() );
}
@@ -0,0 +1,39 @@
/***************************************************************************
qgsgrassoptions.h
-------------------
begin : May, 2015
copyright : (C) 2015 Radim Blazek
email : radim.blazek@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGRASSOPTIONS_H
#define QGSGRASSOPTIONS_H

#include <QDialog>

#include "ui_qgsgrassoptionsbase.h"

class GRASS_LIB_EXPORT QgsGrassOptions : public QDialog, private Ui::QgsGrassOptionsBase
{
Q_OBJECT

public:
explicit QgsGrassOptions(QWidget *parent = 0);
~QgsGrassOptions();

private slots:
void saveOptions();

private:
QString mImportSettingsPath;

};

#endif // QGSGRASSOPTIONS_H

4 comments on commit 6a6b3b4

@jef-n

This comment has been minimized.

Copy link
Member

@jef-n jef-n replied Oct 25, 2015

@blazek Bisected #13665 down to this commit. Reverting the raster projector part fixes it. Was that added intentionally? The commit message doesn't mention it.

@blazek

This comment has been minimized.

Copy link
Member Author

@blazek blazek replied Oct 29, 2015

Yes, it was added intentionally, unfortunately transformBoundingBox() is not precise enough.
Fixed in 1c22445.

@jef-n

This comment has been minimized.

Copy link
Member

@jef-n jef-n replied Oct 29, 2015

Looks related to 51fe632

@blazek

This comment has been minimized.

Copy link
Member Author

@blazek blazek replied Oct 30, 2015

Yes, the same problem. 51fe632 does not fix the problem with cutted outer edges of rasters described in #13665.

Please sign in to comment.