Skip to content

Commit

Permalink
Pixel -> layer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 21, 2021
1 parent f2f1d70 commit ff195b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
Expand Up @@ -42,9 +42,9 @@ based on a transformation method and a list of GCPs.



virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoordinates, const QVector<QgsPointXY> &pixelCoordinates ) = 0;
virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoordinates, const QVector<QgsPointXY> &layerCoordinates ) = 0;
%Docstring
Fits transformation parameters using the specified Ground Control Points (GCPs) lists of map coordinates and pixel coordinates.
Fits transformation parameters using the specified Ground Control Points (GCPs) lists of map coordinates and layer coordinates.

:return: ``True`` on success, ``False`` on failure
%End
Expand All @@ -71,10 +71,10 @@ Creates a new QgsGcpTransformerInterface subclass representing the specified tra
Caller takes ownership of the returned object.
%End

static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &mapCoordinates, const QVector<QgsPointXY> &pixelCoordinates ) /Factory/;
static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &mapCoordinates, const QVector<QgsPointXY> &layerCoordinates ) /Factory/;
%Docstring
Creates a new QgsGcpTransformerInterface subclass representing the specified transform ``method``, initialized
using the given lists of map and pixel coordinates.
using the given lists of map and layer coordinates.

If the parameters cannot be fit to a transform ``None`` will be returned.

Expand Down
28 changes: 14 additions & 14 deletions src/analysis/georeferencing/qgsgcptransformer.cpp
Expand Up @@ -72,13 +72,13 @@ QgsGcpTransformerInterface *QgsGcpTransformerInterface::create( QgsGcpTransforme
}
}

QgsGcpTransformerInterface *QgsGcpTransformerInterface::createFromParameters( QgsGcpTransformerInterface::TransformMethod method, const QVector<QgsPointXY> &mapCoordinates, const QVector<QgsPointXY> &pixelCoordinates )
QgsGcpTransformerInterface *QgsGcpTransformerInterface::createFromParameters( QgsGcpTransformerInterface::TransformMethod method, const QVector<QgsPointXY> &mapCoordinates, const QVector<QgsPointXY> &layerCoordinates )
{
std::unique_ptr< QgsGcpTransformerInterface > transformer( create( method ) );
if ( !transformer )
return nullptr;

if ( !transformer->updateParametersFromGcps( mapCoordinates, pixelCoordinates ) )
if ( !transformer->updateParametersFromGcps( mapCoordinates, layerCoordinates ) )
return nullptr;

return transformer.release();
Expand All @@ -97,11 +97,11 @@ bool QgsLinearGeorefTransform::getOriginScale( QgsPointXY &origin, double &scale
return true;
}

bool QgsLinearGeorefTransform::updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &pixelCoords )
bool QgsLinearGeorefTransform::updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &layerCoords )
{
if ( mapCoords.size() < minimumGcpCount() )
return false;
QgsLeastSquares::linear( mapCoords, pixelCoords, mParameters.origin, mParameters.scaleX, mParameters.scaleY );
QgsLeastSquares::linear( mapCoords, layerCoords, mParameters.origin, mParameters.scaleX, mParameters.scaleY );
return true;
}

Expand Down Expand Up @@ -168,12 +168,12 @@ int QgsLinearGeorefTransform::linearTransform( void *pTransformerArg, int bDstTo
//
// QgsHelmertGeorefTransform
//
bool QgsHelmertGeorefTransform::updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &pixelCoords )
bool QgsHelmertGeorefTransform::updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &layerCoords )
{
if ( mapCoords.size() < minimumGcpCount() )
return false;

QgsLeastSquares::helmert( mapCoords, pixelCoords, mHelmertParameters.origin, mHelmertParameters.scale, mHelmertParameters.angle );
QgsLeastSquares::helmert( mapCoords, layerCoords, mHelmertParameters.origin, mHelmertParameters.scale, mHelmertParameters.angle );
return true;
}

Expand Down Expand Up @@ -276,10 +276,10 @@ QgsGDALGeorefTransform::~QgsGDALGeorefTransform()
destroyGdalArgs();
}

bool QgsGDALGeorefTransform::updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &pixelCoords )
bool QgsGDALGeorefTransform::updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &layerCoords )
{
assert( mapCoords.size() == pixelCoords.size() );
if ( mapCoords.size() != pixelCoords.size() )
assert( mapCoords.size() == layerCoords.size() );
if ( mapCoords.size() != layerCoords.size() )
return false;
int n = mapCoords.size();

Expand All @@ -289,8 +289,8 @@ bool QgsGDALGeorefTransform::updateParametersFromGcps( const QVector<QgsPointXY>
GCPList[i].pszId = new char[20];
snprintf( GCPList[i].pszId, 19, "gcp%i", i );
GCPList[i].pszInfo = nullptr;
GCPList[i].dfGCPPixel = pixelCoords[i].x();
GCPList[i].dfGCPLine = -pixelCoords[i].y();
GCPList[i].dfGCPPixel = layerCoords[i].x();
GCPList[i].dfGCPLine = -layerCoords[i].y();
GCPList[i].dfGCPX = mapCoords[i].x();
GCPList[i].dfGCPY = mapCoords[i].y();
GCPList[i].dfGCPZ = 0;
Expand Down Expand Up @@ -372,15 +372,15 @@ QgsProjectiveGeorefTransform::QgsProjectiveGeorefTransform()
: mParameters()
{}

bool QgsProjectiveGeorefTransform::updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &pixelCoords )
bool QgsProjectiveGeorefTransform::updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &layerCoords )
{
if ( mapCoords.size() < minimumGcpCount() )
return false;

// HACK: flip y coordinates, because georeferencer and gdal use different conventions
QVector<QgsPointXY> flippedPixelCoords;
flippedPixelCoords.reserve( pixelCoords.size() );
for ( const QgsPointXY &coord : pixelCoords )
flippedPixelCoords.reserve( layerCoords.size() );
for ( const QgsPointXY &coord : layerCoords )
{
flippedPixelCoords << QgsPointXY( coord.x(), -coord.y() );
}
Expand Down
16 changes: 8 additions & 8 deletions src/analysis/georeferencing/qgsgcptransformer.h
Expand Up @@ -60,11 +60,11 @@ class ANALYSIS_EXPORT QgsGcpTransformerInterface SIP_ABSTRACT
QgsGcpTransformerInterface &operator=( const QgsGcpTransformerInterface &other ) = delete;

/**
* Fits transformation parameters using the specified Ground Control Points (GCPs) lists of map coordinates and pixel coordinates.
* Fits transformation parameters using the specified Ground Control Points (GCPs) lists of map coordinates and layer coordinates.
*
* \returns TRUE on success, FALSE on failure
*/
virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoordinates, const QVector<QgsPointXY> &pixelCoordinates ) = 0;
virtual bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoordinates, const QVector<QgsPointXY> &layerCoordinates ) = 0;

/**
* Returns the minimum number of Ground Control Points (GCPs) required for parameter fitting.
Expand All @@ -90,13 +90,13 @@ class ANALYSIS_EXPORT QgsGcpTransformerInterface SIP_ABSTRACT

/**
* Creates a new QgsGcpTransformerInterface subclass representing the specified transform \a method, initialized
* using the given lists of map and pixel coordinates.
* using the given lists of map and layer coordinates.
*
* If the parameters cannot be fit to a transform NULLPTR will be returned.
*
* Caller takes ownership of the returned object.
*/
static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &mapCoordinates, const QVector<QgsPointXY> &pixelCoordinates ) SIP_FACTORY;
static QgsGcpTransformerInterface *createFromParameters( TransformMethod method, const QVector<QgsPointXY> &mapCoordinates, const QVector<QgsPointXY> &layerCoordinates ) SIP_FACTORY;

#ifndef SIP_RUN

Expand Down Expand Up @@ -134,7 +134,7 @@ class ANALYSIS_EXPORT QgsLinearGeorefTransform : public QgsGcpTransformerInterfa
*/
bool getOriginScale( QgsPointXY &origin, double &scaleX, double &scaleY ) const;

bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &pixelCoords ) override;
bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &layerCoords ) override;
int minimumGcpCount() const override;
GDALTransformerFunc GDALTransformer() const override;
void *GDALTransformerArgs() const override;
Expand Down Expand Up @@ -168,7 +168,7 @@ class ANALYSIS_EXPORT QgsHelmertGeorefTransform : public QgsGcpTransformerInterf
*/
bool getOriginScaleRotation( QgsPointXY &origin, double &scale, double &rotation ) const;

bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &pixelCoords ) override;
bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &layerCoords ) override;
int minimumGcpCount() const override;
GDALTransformerFunc GDALTransformer() const override;
void *GDALTransformerArgs() const override;
Expand Down Expand Up @@ -201,7 +201,7 @@ class ANALYSIS_EXPORT QgsGDALGeorefTransform : public QgsGcpTransformerInterface
QgsGDALGeorefTransform( bool useTPS, unsigned int polynomialOrder );
~QgsGDALGeorefTransform() override;

bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &pixelCoords ) override;
bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &layerCoords ) override;
int minimumGcpCount() const override;
GDALTransformerFunc GDALTransformer() const override;
void *GDALTransformerArgs() const override;
Expand Down Expand Up @@ -232,7 +232,7 @@ class ANALYSIS_EXPORT QgsProjectiveGeorefTransform : public QgsGcpTransformerInt
public:
QgsProjectiveGeorefTransform();

bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &pixelCoords ) override;
bool updateParametersFromGcps( const QVector<QgsPointXY> &mapCoords, const QVector<QgsPointXY> &layerCoords ) override;
int minimumGcpCount() const override;
GDALTransformerFunc GDALTransformer() const override;
void *GDALTransformerArgs() const override;
Expand Down

0 comments on commit ff195b3

Please sign in to comment.