Skip to content

Commit

Permalink
Virtual dataset groups for mesh layer (qgis#37605)
Browse files Browse the repository at this point in the history
[FEATURE] Introduces mesh virtual datasets

With the mesh calculator the user can choose to create those "virtual" dataset groups that will be added to the layer. Then, for these dataset groups, values are not stored in memory but each dataset is calculated when needed whit the formula entered in the mesh calculator.

Those virtual dataset groups are saved with the project.

If needed, the user can remove them or can persist them on files to make them persistent.

Co-authored-by: Étienne Trimaille <[email protected]>
  • Loading branch information
vcloarec and Gustry authored Jul 23, 2020
1 parent 282d5f9 commit de68f83
Show file tree
Hide file tree
Showing 42 changed files with 2,018 additions and 655 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ IF (PEDANTIC)
# ADD_DEFINITIONS( -fstrict-aliasing -Wstrict-aliasing=1 -Wredundant-decls )

IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type-c-linkage -Wno-overloaded-virtual -Wimplicit-fallthrough")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type-c-linkage -Wno-overloaded-virtual -Wimplicit-fallthrough")
ENDIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")

# add any extra CXXFLAGS flags set by user. can be -D CXX_EXTRA_FLAGS or environment variable
Expand Down
5 changes: 5 additions & 0 deletions external/mdal/api/mdal.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ MDAL_EXPORT void MDAL_G_closeEditMode( MDAL_DatasetGroupH group );
*/
MDAL_EXPORT const char *MDAL_G_referenceTime( MDAL_DatasetGroupH group );

/**
* Sets reference time for dataset group expressed in date with ISO8601 format
*/
MDAL_EXPORT void MDAL_G_setReferenceTime( MDAL_DatasetGroupH group, const char *referenceTimeISO8601 );

/**
* Returns whether the dataset group is temporal, i.e. has time-related datasets
*
Expand Down
14 changes: 13 additions & 1 deletion external/mdal/mdal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static const char *EMPTY_STR = "";

const char *MDAL_Version()
{
return "0.6.90";
return "0.6.91";
}

MDAL_Status MDAL_LastStatus()
Expand Down Expand Up @@ -874,6 +874,18 @@ const char *MDAL_G_referenceTime( MDAL_DatasetGroupH group )
return _return_str( g->referenceTime().toStandardCalendarISO8601() );
}

void MDAL_G_setReferenceTime( MDAL_DatasetGroupH group, const char *referenceTimeISO8601 )
{
if ( !group )
{
MDAL::Log::error( MDAL_Status::Err_IncompatibleDataset, "Dataset Group is not valid (null)" );
return;
}
MDAL::DatasetGroup *g = static_cast< MDAL::DatasetGroup * >( group );
const std::string datetime( referenceTimeISO8601 );
g->setReferenceTime( MDAL::DateTime( datetime ) );
}

void MDAL_G_setMetadata( MDAL_DatasetGroupH group, const char *key, const char *val )
{
if ( !group )
Expand Down
31 changes: 31 additions & 0 deletions external/mdal/mdal_datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,37 @@ MDAL::DateTime::DateTime( double value, Epoch epoch ): mValid( true )
}
}

MDAL::DateTime::DateTime( const std::string &fromISO8601 )
{
std::vector<std::string> splitedDateTime = split( fromISO8601, 'T' );

if ( splitedDateTime.size() != 2 )
return;
//parse date
std::vector<std::string> splitedDate = split( splitedDateTime.at( 0 ), '-' );
if ( splitedDate.size() != 3 )
return;

//parse time
splitedDateTime[1] = replace( splitedDateTime.at( 1 ), "Z", "", ContainsBehaviour::CaseInsensitive );
std::vector<std::string> splitedTime = split( splitedDateTime.at( 1 ), ':' );
if ( splitedTime.size() < 2 || splitedTime.size() > 3 )
return;

DateTimeValues dateTimeValues;
dateTimeValues.year = toInt( splitedDate[0] );
dateTimeValues.month = toInt( splitedDate[1] );
dateTimeValues.day = toInt( splitedDate[2] );
dateTimeValues.hours = toInt( splitedTime[0] );
dateTimeValues.minutes = toInt( splitedTime[1] );
if ( splitedTime.size() == 3 )
dateTimeValues.seconds = toDouble( splitedTime[2] );
else
dateTimeValues.seconds = 0.0;

setWithGregorianCalendarDate( dateTimeValues );
}

std::string MDAL::DateTime::toStandardCalendarISO8601() const
{
if ( mValid )
Expand Down
3 changes: 3 additions & 0 deletions external/mdal/mdal_datetime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ namespace MDAL
//! Constructor with Julian day or Unix Epoch
DateTime( double value, Epoch epoch );

//! Constructor with ISO 8601 string
DateTime( const std::string &fromISO8601 );

//! Returns a string with the date/time expressed in Greogrian proleptic calendar with ISO8601 format (local time zone)
//! Do not support negative year
std::string toStandardCalendarISO8601() const;
Expand Down
1 change: 0 additions & 1 deletion python/analysis/analysis_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
%Include auto_generated/interpolation/qgsidwinterpolator.sip
%Include auto_generated/interpolation/qgsinterpolator.sip
%Include auto_generated/interpolation/qgstininterpolator.sip
%Include auto_generated/mesh/qgsmeshcalculator.sip
%Include auto_generated/mesh/qgsmeshcontours.sip
%Include auto_generated/network/qgsgraph.sip
%Include auto_generated/network/qgsgraphanalyzer.sip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/mesh/qgsmeshcalculator.h *
* src/core/mesh/qgsmeshcalculator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
Expand Down Expand Up @@ -131,16 +131,19 @@ Creates calculator with geometry mask

QgsMeshCalculator( const QString &formulaString,
const QString &outputGroupName,
double startTime,
double endTime,
const QgsRectangle &outputExtent,
QgsMeshLayer *layer );
const QgsMeshDatasetGroup::Type &destination,
QgsMeshLayer *layer,
double startTime,
double endTime );
%Docstring
Creates calculator with bounding box (rectangular) mask, store the result in the memory
Creates calculator with bounding box (rectangular) mask, store the result in ``destination`` (must be on memory or virtual),
see QgsMeshCalculator.Destination

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param outputGroupName: output group name
:param outputExtent: spatial filter defined by rectangle
:param destination: destination of the calculation (memory or virtual)
:param startTime: time filter defining the starting dataset
:param endTime: time filter defining the ending dataset
:param layer: mesh layer with dataset groups references in formulaString
Expand All @@ -150,27 +153,29 @@ Creates calculator with bounding box (rectangular) mask, store the result in the

QgsMeshCalculator( const QString &formulaString,
const QString &outputGroupName,
double startTime,
double endTime,
const QgsGeometry &outputMask,
QgsMeshLayer *layer );
const QgsMeshDatasetGroup::Type &destination,
QgsMeshLayer *layer,
double startTime,
double endTime );
%Docstring
Creates calculator with with geometry mask, store the result in the memory
Creates calculator with with geometry mask, store the result in ``destination`` (must be on memory or virtual),
see QgsMeshCalculator.Destination

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param outputGroupName: output group name
:param outputMask: spatial filter defined by geometry
:param destination: destination of the calculation (memory or virtual)
:param startTime: time filter defining the starting dataset
:param endTime: time filter defining the ending dataset
:param layer: mesh layer with dataset groups references in formulaString

.. versionadded:: 3.16
%End


Result processCalculation( QgsFeedback *feedback = 0 );
%Docstring
Starts the calculation, writes new dataset group to file and adds it to the mesh layer
Starts the calculation, creates new dataset group and adds it to the mesh layer

:param feedback: The optional feedback argument for progress reporting and cancellation support

Expand Down Expand Up @@ -211,7 +216,7 @@ Returns whether formula is valid for particular mesh layer
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/mesh/qgsmeshcalculator.h *
* src/core/mesh/qgsmeshcalculator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
Loading

0 comments on commit de68f83

Please sign in to comment.