Skip to content

Commit

Permalink
[feature] [mesh] Mesh Calculator
Browse files Browse the repository at this point in the history
Similarly to raster calculator, mesh calculator can take dataset groups from current mesh layer and
combine them with various aritmentic/logical operators to new dataset group.
  • Loading branch information
PeterPetrik committed Jan 14, 2019
1 parent e163caf commit cd9a84e
Show file tree
Hide file tree
Showing 43 changed files with 4,761 additions and 76 deletions.
1 change: 1 addition & 0 deletions doc/CMakeLists.txt
Expand Up @@ -94,6 +94,7 @@ IF(WITH_APIDOC)
${CMAKE_SOURCE_DIR}/src/gui/raster
${CMAKE_SOURCE_DIR}/src/gui/symbology
${CMAKE_SOURCE_DIR}/src/analysis
${CMAKE_SOURCE_DIR}/src/analysis/mesh
${CMAKE_SOURCE_DIR}/src/analysis/interpolation
${CMAKE_SOURCE_DIR}/src/analysis/network
${CMAKE_SOURCE_DIR}/src/analysis/processing
Expand Down
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -379,6 +379,7 @@
<file>themes/default/mActionShowPinnedLabels.svg</file>
<file>themes/default/mActionShowPluginManager.svg</file>
<file>themes/default/mActionShowRasterCalculator.png</file>
<file>themes/default/mActionShowMeshCalculator.png</file>
<file>themes/default/mActionShowSelectedLayers.svg</file>
<file>themes/default/mActionSimplify.svg</file>
<file>themes/default/mActionSplitFeatures.svg</file>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions python/CMakeLists.txt
Expand Up @@ -274,13 +274,15 @@ INCLUDE_DIRECTORIES(BEFORE
${CMAKE_SOURCE_DIR}/src/analysis/processing
${CMAKE_SOURCE_DIR}/src/analysis/vector
${CMAKE_SOURCE_DIR}/src/analysis/vector/geometry_checker
${CMAKE_SOURCE_DIR}/src/analysis/mesh
${CMAKE_SOURCE_DIR}/src/analysis/raster
${CMAKE_SOURCE_DIR}/src/analysis/network
${CMAKE_SOURCE_DIR}/src/analysis/interpolation
${CMAKE_SOURCE_DIR}/src/analysis/openstreetmap

${CMAKE_BINARY_DIR}/src/analysis/processing
${CMAKE_BINARY_DIR}/src/analysis/vector
${CMAKE_BINARY_DIR}/src/analysis/mesh
${CMAKE_BINARY_DIR}/src/analysis/raster
${CMAKE_BINARY_DIR}/src/analysis/network
${CMAKE_BINARY_DIR}/src/analysis/interpolation
Expand Down
1 change: 1 addition & 0 deletions python/analysis/analysis_auto.sip
Expand Up @@ -14,6 +14,7 @@
%Include auto_generated/raster/qgsrastermatrix.sip
%Include auto_generated/raster/qgsrastercalcnode.sip
%Include auto_generated/raster/qgstotalcurvaturefilter.sip
%Include auto_generated/mesh/qgsmeshcalculator.sip
%Include auto_generated/vector/qgsgeometrysnapper.sip
%Include auto_generated/vector/qgsgeometrysnappersinglesource.sip
%Include auto_generated/vector/qgszonalstatistics.sip
Expand Down
109 changes: 109 additions & 0 deletions python/analysis/auto_generated/mesh/qgsmeshcalculator.sip.in
@@ -0,0 +1,109 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/mesh/qgsmeshcalculator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsMeshCalculator
{
%Docstring
Performs mesh layer calculations.

Mesh calculator can do various mathematical operations
between dataset groups from a single mesh layer.
Resulting dataset group is added to the mesh layer.
Result can be filtered by extent or a vector layer mask
spatially and by selection of times.

Note: only dataset groups defined on vertices are
implemented and supported

.. versionadded:: 3.6
%End

%TypeHeaderCode
#include "qgsmeshcalculator.h"
%End
public:

enum Result
{
Success,
Canceled,
CreateOutputError,
InputLayerError,
ParserError,
InvalidDatasets,
EvaluateError,
MemoryError,
};

QgsMeshCalculator( const QString &formulaString,
const QString &outputFile,
const QgsRectangle &outputExtent,
double startTime,
double endTime,
QgsMeshLayer *layer );
%Docstring
Creates calculator with bounding box (rectangular) mask

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param outputFile: file to store the resulting dataset group data
:param outputExtent: spatial filter defined by rectangle
: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
%End

QgsMeshCalculator( const QString &formulaString,
const QString &outputFile,
const QgsGeometry &outputMask,
double startTime,
double endTime,
QgsMeshLayer *layer );
%Docstring
Creates calculator with geometry mask

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param outputFile: file to store the resulting dataset group data
:param outputMask: spatial filter defined by geometry
: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
%End

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

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

:return: QgsMeshCalculator.Success in case of success
%End

static Result expression_valid( const QString &formulaString, QgsMeshLayer *layer );
%Docstring
Returns whether formula is valid for particular mesh layer

:param formulaString: formula/expression to evaluate. Consists of dataset group names, operators and numbers
:param layer: mesh layer with dataset groups references in formulaString

:return: QgsMeshCalculator.Success in case of success
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/mesh/qgsmeshcalculator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
24 changes: 24 additions & 0 deletions python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in
Expand Up @@ -509,6 +509,30 @@ V3 ---- V4 ---- V6-----V8
%Docstring
Returns whether the faces are active for particular dataset

.. versionadded:: 3.6
%End

virtual bool persistDatasetGroup( const QString &path,
const QgsMeshDatasetGroupMetadata &meta,
const QVector<QgsMeshDataBlock> &datasetValues,
const QVector<QgsMeshDataBlock> &datasetActive,
const QVector<double> &times
) = 0;
%Docstring
Creates a new dataset group from a data and
persists it into a destination path

On success, the mesh's dataset group count is changed

:param path: destination path of the stored file
:param meta: new group's metadata
:param datasetValues: scalar/vector values for all datasets and all faces/vertices in the group
:param datasetActive: active flag values for all datasets in the group. Empty array represents can be used
when all faces are active
:param times: times in hours for all datasets in the group

:return: true on failure, false on success

.. versionadded:: 3.6
%End
};
Expand Down
2 changes: 2 additions & 0 deletions python/core/auto_generated/mesh/qgsmeshlayer.sip.in
Expand Up @@ -130,6 +130,8 @@ Returns the provider type for this layer





QgsMeshRendererSettings rendererSettings() const;
%Docstring
Returns renderer settings
Expand Down
14 changes: 14 additions & 0 deletions src/analysis/CMakeLists.txt
Expand Up @@ -137,6 +137,10 @@ SET(QGIS_ANALYSIS_SRCS
vector/qgsgeometrysnappersinglesource.cpp
vector/qgszonalstatistics.cpp

mesh/qgsmeshcalcnode.cpp
mesh/qgsmeshcalculator.cpp
mesh/qgsmeshcalcutils.cpp

network/qgsgraph.cpp
network/qgsgraphbuilder.cpp
network/qgsgraphbuilderinterface.cpp
Expand Down Expand Up @@ -204,14 +208,18 @@ FIND_PACKAGE(EXIV2 REQUIRED)
INCLUDE_DIRECTORIES(SYSTEM ${SPATIALITE_INCLUDE_DIR})
INCLUDE_DIRECTORIES(SYSTEM ${SQLITE3_INCLUDE_DIR})
INCLUDE_DIRECTORIES(BEFORE raster)
INCLUDE_DIRECTORIES(BEFORE mesh)

ADD_FLEX_FILES_PREFIX(QGIS_ANALYSIS_SRCS raster raster/qgsrastercalclexer.ll)
ADD_FLEX_FILES_PREFIX(QGIS_ANALYSIS_SRCS mesh mesh/qgsmeshcalclexer.ll)

ADD_BISON_FILES_PREFIX(QGIS_ANALYSIS_SRCS raster raster/qgsrastercalcparser.yy)
ADD_BISON_FILES_PREFIX(QGIS_ANALYSIS_SRCS mesh mesh/qgsmeshcalcparser.yy)

IF(NOT MSVC)
SET_SOURCE_FILES_PROPERTIES(
${CMAKE_BINARY_DIR}/src/analysis/qgsrastercalcparser.cpp
${CMAKE_BINARY_DIR}/src/analysis/qgsmeshcalcparser.cpp
PROPERTIES COMPILE_FLAGS "-w"
)
ELSE(NOT MSVC)
Expand All @@ -220,6 +228,7 @@ ELSE(NOT MSVC)
# 4702 unreachable code
SET_SOURCE_FILES_PROPERTIES(
${CMAKE_BINARY_DIR}/src/analysis/qgsrastercalcparser.cpp
${CMAKE_BINARY_DIR}/src/analysis/qgsmeshcalcparser.cpp
PROPERTIES COMPILE_FLAGS "-wd4127 -wd4702"
)
ENDIF(PEDANTIC)
Expand Down Expand Up @@ -258,6 +267,10 @@ SET(QGIS_ANALYSIS_HDRS
raster/qgsrastermatrix.h
raster/qgsrastercalcnode.h
raster/qgstotalcurvaturefilter.h

mesh/qgsmeshcalcnode.h
mesh/qgsmeshcalculator.h
mesh/qgsmeshcalcutils.h

vector/mersenne-twister.h
vector/qgsgeometrysnapper.h
Expand Down Expand Up @@ -329,6 +342,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/processing
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/mesh
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/expression
Expand Down
92 changes: 92 additions & 0 deletions src/analysis/mesh/qgsmeshcalclexer.ll
@@ -0,0 +1,92 @@
/***************************************************************************
qgsmeshcalclexer.ll
-------------------
begin : December 19th, 2018
copyright : (C) 2018 by Peter Petrik
email : zilolv at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

%option noyywrap
%option nounput
%option case-insensitive
%option never-interactive

// ensure that lexer will be 8-bit (and not just 7-bit)
%option 8bit

%{
//directly included in the output program
#include "qgsmeshcalcnode.h"
#include "qgsmeshcalcparser.hpp"

// if not defined, searches for isatty()
// which doesn't in MSVC compiler
#define YY_NEVER_INTERACTIVE 1

#ifdef _MSC_VER
#define YY_NO_UNISTD_H
#endif

#ifndef _MSC_VER
#pragma GCC diagnostic ignored "-Wsign-compare"
#endif
%}

white [ \t\r\n]+

dig [0-9]
num1 {dig}+\.?([eE][-+]?{dig}+)?
num2 {dig}*\.{dig}+([eE][-+]?{dig}+)?
number {num1}|{num2}

non_ascii [\x80-\xFF]
dataset_ref_char [A-Za-z0-9_./:]|{non_ascii}|[-]
dataset_ref ({dataset_ref_char}+)
dataset_ref_quoted \"(\\.|[^"])*\"
%%
"sum_aggr" { meshlval.op = QgsMeshCalcNode::opSUM_AGGR; return FUNCTION; }
"max_aggr" { meshlval.op = QgsMeshCalcNode::opMAX_AGGR; return FUNCTION; }
"min_aggr" { meshlval.op = QgsMeshCalcNode::opMIN_AGGR; return FUNCTION; }
"average_aggr" { meshlval.op = QgsMeshCalcNode::opAVG_AGGR; return FUNCTION; }
"abs" { meshlval.op = QgsMeshCalcNode::opABS; return FUNCTION; }
"max" { meshlval.op = QgsMeshCalcNode::opMAX; return FUNCTION2; }
"min" { meshlval.op = QgsMeshCalcNode::opMIN; return FUNCTION2; }
"IF" { return IF; }
"AND" { return AND; }
"OR" { return OR; }
"NOT" { return NOT; }
"!=" { return NE; }
"<=" { return LE; }
">=" { return GE; }
"NODATA" {return NODATA;}
[=><+-/*^] { return yytext[0]; }
[()] { return yytext[0]; }
{number} { meshlval.number = atof(meshtext); return NUMBER; }
{dataset_ref} { return DATASET_REF; }
{dataset_ref_quoted} { return DATASET_REF; }
{white} /* skip blanks and tabs */
%%
void set_mesh_input_buffer(const char* buffer)
{
mesh_scan_string(buffer);
}

0 comments on commit cd9a84e

Please sign in to comment.