Esempio n. 1
0
QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check,
    const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
    const QgsPointXY &errorLocation, QgsVertexId vidx,
    const QVariant &value, ValueType valueType )
  : mCheck( check )
  , mLayerId( layerFeature.layer().id() )
  , mFeatureId( layerFeature.feature().id() )
  , mErrorLocation( errorLocation )
  , mVidx( vidx )
  , mValue( value )
  , mValueType( valueType )
  , mStatus( StatusPending )
{
  if ( vidx.part != -1 )
  {
    mGeometry = QgsGeometryCheckerUtils::getGeomPart( layerFeature.geometry(), vidx.part )->clone();
  }
  else
  {
    mGeometry = layerFeature.geometry()->clone();
  }
  if ( layerFeature.geometryCrs() != layerFeature.layerToMapTransform().destinationCrs().authid() )
  {
    mGeometry->transform( layerFeature.layerToMapTransform() );
    mErrorLocation = layerFeature.layerToMapTransform().transform( mErrorLocation );
  }
}
QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check,
    const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
    const QgsPointXY &errorLocation,
    QgsVertexId vidx,
    const QVariant &value,
    ValueType valueType )
  : mCheck( check )
  , mLayerId( layerFeature.layerId() )
  , mFeatureId( layerFeature.feature().id() )
  , mErrorLocation( errorLocation )
  , mVidx( vidx )
  , mValue( value )
  , mValueType( valueType )
  , mStatus( StatusPending )
{
  if ( vidx.part != -1 )
  {
    mGeometry = QgsGeometry( QgsGeometryCheckerUtils::getGeomPart( layerFeature.geometry().constGet(), vidx.part )->clone() );
  }
  else
  {
    mGeometry = layerFeature.geometry();
  }
  if ( !layerFeature.useMapCrs() )
  {
    QgsVectorLayer *vl = layerFeature.layer().data();
    if ( vl )
    {
      QgsCoordinateTransform ct( vl->crs(), check->context()->mapCrs, check->context()->transformContext );
      try
      {
        mGeometry.transform( ct );
        mErrorLocation = ct.transform( mErrorLocation );
      }
      catch ( const QgsCsException &e )
      {
        QgsDebugMsg( QStringLiteral( "Can not show error in current map coordinate reference system" ) );
      }
    }
  }
}