Ejemplo n.º 1
0
QgsGeorefDataPoint::QgsGeorefDataPoint( const QgsGeorefDataPoint &p )
{
  // we share item representation on canvas between all points
//  mGCPSourceItem = new QgsGCPCanvasItem(p.srcCanvas(), p.pixelCoords(), p.mapCoords(), p.isEnabled());
//  mGCPDestinationItem = new QgsGCPCanvasItem(p.dstCanvas(), p.pixelCoords(), p.mapCoords(), p.isEnabled());
  mPixelCoords = p.pixelCoords();
  mMapCoords = p.mapCoords();
  mEnabled = p.isEnabled();
  mResidual = p.residual();
  mId = p.id();
}
Ejemplo n.º 2
0
void QgsGCPList::createGCPVectors( QVector<QgsPointXY> &mapCoords, QVector<QgsPointXY> &pixelCoords )
{
  mapCoords   = QVector<QgsPointXY>( size() );
  pixelCoords = QVector<QgsPointXY>( size() );
  for ( int i = 0, j = 0; i < sizeAll(); i++ )
  {
    QgsGeorefDataPoint *pt = at( i );
    if ( pt->isEnabled() )
    {
      mapCoords[j] = pt->mapCoords();
      pixelCoords[j] = pt->pixelCoords();
      j++;
    }
  }
}
Ejemplo n.º 3
0
void QgsGCPListModel::updateModel()
{
  //clear();
  if ( !mGCPList )
    return;

  bool bTransformUpdated = false;

  QVector<QgsPointXY> mapCoords, pixelCoords;
  mGCPList->createGCPVectors( mapCoords, pixelCoords );

  //  // Setup table header
  QStringList itemLabels;
  QString unitType;
  QgsSettings s;
  bool mapUnitsPossible = false;

  if ( mGeorefTransform )
  {
    bTransformUpdated = mGeorefTransform->updateParametersFromGCPs( mapCoords, pixelCoords );
    mapUnitsPossible = mGeorefTransform->providesAccurateInverseTransformation();
  }


  if ( s.value( QStringLiteral( "/Plugin-GeoReferencer/Config/ResidualUnits" ) ) == "mapUnits" && mapUnitsPossible )
  {
    unitType = tr( "map units" );
  }
  else
  {
    unitType = tr( "pixels" );
  }

  itemLabels << tr( "Visible" )
             << tr( "ID" )
             << tr( "Source X" )
             << tr( "Source Y" )
             << tr( "Dest. X" )
             << tr( "Dest. Y" )
             << tr( "dX (%1)" ).arg( unitType )
             << tr( "dY (%1)" ).arg( unitType )
             << tr( "Residual (%1)" ).arg( unitType );

  setHorizontalHeaderLabels( itemLabels );
  setRowCount( mGCPList->size() );

  for ( int i = 0; i < mGCPList->sizeAll(); ++i )
  {
    int j = 0;
    QgsGeorefDataPoint *p = mGCPList->at( i );

    if ( !p )
      continue;

    p->setId( i );

    QStandardItem *si = new QStandardItem();
    si->setTextAlignment( Qt::AlignCenter );
    si->setCheckable( true );
    if ( p->isEnabled() )
      si->setCheckState( Qt::Checked );
    else
      si->setCheckState( Qt::Unchecked );

    setItem( i, j++, si );
    setItem( i, j++, new QgsStandardItem( i ) );
    setItem( i, j++, new QgsStandardItem( p->pixelCoords().x() ) );
    setItem( i, j++, new QgsStandardItem( p->pixelCoords().y() ) );
    setItem( i, j++, new QgsStandardItem( p->mapCoords().x() ) );
    setItem( i, j++, new QgsStandardItem( p->mapCoords().y() ) );

    double residual;
    double dX = 0;
    double dY = 0;
    // Calculate residual if transform is available and up-to-date
    if ( mGeorefTransform && bTransformUpdated && mGeorefTransform->parametersInitialized() )
    {
      QgsPointXY dst;
      QgsPointXY pixel = mGeorefTransform->hasCrs() ? mGeorefTransform->toColumnLine( p->pixelCoords() ) : p->pixelCoords();
      if ( unitType == tr( "pixels" ) )
      {
        // Transform from world to raster coordinate:
        // This is the transform direction used by the warp operation.
        // As transforms of order >=2 are not invertible, we are only
        // interested in the residual in this direction
        if ( mGeorefTransform->transformWorldToRaster( p->mapCoords(), dst ) )
        {
          dX = ( dst.x() - pixel.x() );
          dY = -( dst.y() - pixel.y() );
        }
      }
      else if ( unitType == tr( "map units" ) )
      {
        if ( mGeorefTransform->transformRasterToWorld( pixel, dst ) )
        {
          dX = ( dst.x() - p->mapCoords().x() );
          dY = ( dst.y() - p->mapCoords().y() );
        }
      }
    }
    residual = std::sqrt( dX * dX + dY * dY );

    p->setResidual( QPointF( dX, dY ) );

    if ( residual >= 0.f )
    {
      setItem( i, j++, new QgsStandardItem( dX ) );
      setItem( i, j++, new QgsStandardItem( dY ) );
      setItem( i, j++, new QgsStandardItem( residual ) );
    }
    else
    {
      setItem( i, j++, new QgsStandardItem( QStringLiteral( "n/a" ) ) );
      setItem( i, j++, new QgsStandardItem( QStringLiteral( "n/a" ) ) );
      setItem( i, j++, new QgsStandardItem( QStringLiteral( "n/a" ) ) );
    }
  }
}
Ejemplo n.º 4
0
void QgsGCPListModel::updateModel()
{
  clear();
  if (!mGCPList)
    return;

//  // Setup table header
  QStringList itemLabels;
//  // Set column headers
  itemLabels<< "on/off" << "id" << "srcX" << "srcY" << "dstX" << "dstY" << "dX" << "dY" << "residual";
//  setColumnCount(itemLabels.size());
  setHorizontalHeaderLabels(itemLabels);
  setRowCount(mGCPList->size());

  bool bTransformUpdated = false;
  if (mGeorefTransform)
  {
    vector<QgsPoint> mapCoords, pixelCoords;
    mGCPList->createGCPVectors(mapCoords, pixelCoords);

    // TODO: the parameters should probable be updated externally (by user interaction)
    bTransformUpdated = mGeorefTransform->updateParametersFromGCPs(mapCoords, pixelCoords);
  }

  for (int i = 0; i < mGCPList->sizeAll(); ++i)
  {
    int j = 0;
    QgsGeorefDataPoint *p = mGCPList->at(i);
    p->setId(i);

    QStandardItem *si = new QStandardItem();
    si->setTextAlignment(Qt::AlignCenter);
    si->setCheckable(true);
    if (p->isEnabled())
      si->setCheckState(Qt::Checked);
    else
      si->setCheckState(Qt::Unchecked);

    setItem(i, j++, si);
    setItem(i, j++, QGSSTANDARDITEM(i) /*create_item<int>(i)*/);
    setItem(i, j++, QGSSTANDARDITEM(p->pixelCoords().x()) /*create_item<double>( p->pixelCoords().x() )*/);
    setItem(i, j++, QGSSTANDARDITEM(-p->pixelCoords().y()) /*create_item<double>(-p->pixelCoords().y() )*/);
    setItem(i, j++, QGSSTANDARDITEM(p->mapCoords().x()) /*create_item<double>( p->mapCoords().x() )*/);
    setItem(i, j++, QGSSTANDARDITEM(p->mapCoords().y()) /*create_item<double>( p->mapCoords().y() )*/);

    double residual = -1.f;
    double dX, dY;
    // Calculate residual if transform is available and up-to-date
    if (mGeorefTransform && bTransformUpdated && mGeorefTransform->parametersInitialized())
    {
      QgsPoint dst;
      // Transform from world to raster coordinate:
      // This is the transform direction used by the warp operation.
      // As transforms of order >=2 are not invertible, we are only
      // interested in the residual in this direction
      mGeorefTransform->transformWorldToRaster(p->mapCoords(), dst);
      dX = (dst.x() - p->pixelCoords().x());
      dY = (dst.y() - p->pixelCoords().y());
      residual = sqrt(dX*dX + dY*dY);
    }
    else
    {
      dX = dY = residual = 0;
    }
    if (residual >= 0.f) {
      setItem(i, j++, QGSSTANDARDITEM(dX) /*create_item<double>(dX)*/);
      setItem(i, j++, QGSSTANDARDITEM(-dY) /*create_item<double>(-dY)*/);
      setItem(i, j++, QGSSTANDARDITEM(residual) /*create_item<double>(residual)*/);
    }
    else {
      setItem(i, j++, QGSSTANDARDITEM("n/a") /*create_std_item("n/a")*/);
      setItem(i, j++, QGSSTANDARDITEM("n/a") /*create_std_item("n/a")*/);
      setItem(i, j++, QGSSTANDARDITEM("n/a") /*create_std_item("n/a")*/);
    }
  }
  //sort();  // Sort data
  //reset(); // Signal to views that the model has changed
}