コード例 #1
0
ファイル: qgsmeshlayer.cpp プロジェクト: anitagraser/QGIS
QgsMeshDatasetValue QgsMeshLayer::datasetValue( const QgsMeshDatasetIndex &index, const QgsPointXY &point ) const
{
  QgsMeshDatasetValue value;

  if ( mTriangularMesh && dataProvider() && dataProvider()->isValid() && index.isValid() )
  {
    int faceIndex = mTriangularMesh->faceIndexForPoint( point ) ;
    if ( faceIndex >= 0 )
    {
      int nativeFaceIndex = mTriangularMesh->trianglesToNativeFaces().at( faceIndex );
      if ( dataProvider()->isFaceActive( index, nativeFaceIndex ) )
      {

        if ( dataProvider()->datasetGroupMetadata( index ).dataType() == QgsMeshDatasetGroupMetadata::DataOnFaces )
        {
          int nativeFaceIndex = mTriangularMesh->trianglesToNativeFaces().at( faceIndex );
          value = dataProvider()->datasetValue( index, nativeFaceIndex );
        }
        else
        {
          const QgsMeshFace &face = mTriangularMesh->triangles()[faceIndex];
          const int v1 = face[0], v2 = face[1], v3 = face[2];
          const QgsPoint p1 = mTriangularMesh->vertices()[v1], p2 = mTriangularMesh->vertices()[v2], p3 = mTriangularMesh->vertices()[v3];
          const QgsMeshDatasetValue val1 = dataProvider()->datasetValue( index, v1 );
          const QgsMeshDatasetValue val2 = dataProvider()->datasetValue( index, v2 );
          const QgsMeshDatasetValue val3 = dataProvider()->datasetValue( index, v3 );
          const double x = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.x(), val2.x(), val3.x(), point );
          double y = std::numeric_limits<double>::quiet_NaN();
          bool isVector = dataProvider()->datasetGroupMetadata( index ).isVector();
          if ( isVector )
            y = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, val1.y(), val2.y(), val3.y(), point );

          value = QgsMeshDatasetValue( x, y );
        }

      }
    }
  }

  return value;
}
コード例 #2
0
void QgsMeshRendererActiveDatasetWidget::updateMetadata( QgsMeshDatasetIndex datasetIndex )
{
  if ( !mMeshLayer ||
       !mMeshLayer->dataProvider() ||
       !datasetIndex.isValid() )
  {
    mActiveDatasetMetadata->setText( tr( "No dataset selected" ) );
  }
  else
  {
    QString msg;
    msg += QStringLiteral( "<table>" );

    const QgsMeshDatasetMetadata meta = mMeshLayer->dataProvider()->datasetMetadata( datasetIndex );
    msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" )
           .arg( tr( "Is valid" ) )
           .arg( meta.isValid() ? tr( "Yes" ) : tr( "No" ) );

    msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" )
           .arg( tr( "Time" ) )
           .arg( meta.time() );

    const QgsMeshDatasetGroupMetadata gmeta = mMeshLayer->dataProvider()->datasetGroupMetadata( datasetIndex );
    msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" )
           .arg( tr( "Data Type" ) )
           .arg( gmeta.dataType() == QgsMeshDatasetGroupMetadata::DataOnVertices ? tr( "Defined on vertices" ) : tr( "Defined on faces" ) );

    msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" )
           .arg( tr( "Is vector" ) )
           .arg( gmeta.isVector() ? tr( "Yes" ) : tr( "No" ) );

    for ( auto it = gmeta.extraOptions().constBegin(); it != gmeta.extraOptions().constEnd(); ++it )
    {
      msg += QStringLiteral( "<tr><td>%1</td><td>%2</td></tr>" ).arg( it.key() ).arg( it.value() );
    }

    msg += QStringLiteral( "</table>" );
    mActiveDatasetMetadata->setText( msg );
  }

}