Skip to content

Commit

Permalink
[GRASS] browser import options dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed May 25, 2015
1 parent 407f721 commit 6a6b3b4
Show file tree
Hide file tree
Showing 12 changed files with 658 additions and 109 deletions.
281 changes: 184 additions & 97 deletions src/core/raster/qgsrasterprojector.cpp

Large diffs are not rendered by default.

29 changes: 25 additions & 4 deletions src/core/raster/qgsrasterprojector.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
};

Expand Down
5 changes: 4 additions & 1 deletion src/providers/grass/6/CMakeLists.txt
@@ -1,2 +1,5 @@
INCLUDE_DIRECTORIES(${GRASS_INCLUDE_DIR})
INCLUDE_DIRECTORIES(
${GRASS_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
ADD_GRASSLIB(6)
5 changes: 4 additions & 1 deletion src/providers/grass/7/CMakeLists.txt
@@ -1,2 +1,5 @@
INCLUDE_DIRECTORIES(${GRASS_INCLUDE_DIR7})
INCLUDE_DIRECTORIES(
${GRASS_INCLUDE_DIR7}
${CMAKE_CURRENT_BINARY_DIR}
)
ADD_GRASSLIB(7)
26 changes: 24 additions & 2 deletions src/providers/grass/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrass.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrassimport.cpp
Expand Up @@ -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;
}
Expand Down
52 changes: 52 additions & 0 deletions src/providers/grass/qgsgrassoptions.cpp
@@ -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() );
}
39 changes: 39 additions & 0 deletions src/providers/grass/qgsgrassoptions.h
@@ -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
Copy link
Member

@jef-n jef-n commented on 6a6b3b4 Oct 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member Author

@blazek blazek commented on 6a6b3b4 Oct 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jef-n
Copy link
Member

@jef-n jef-n commented on 6a6b3b4 Oct 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks related to 51fe632

@blazek
Copy link
Member Author

@blazek blazek commented on 6a6b3b4 Oct 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.