Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,269 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
python/analysis/auto_generated/mesh/qgsmeshtriangulation.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/analysis/mesh/qgsmeshtriangulation.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
class QgsMeshTriangulation : QObject | ||
{ | ||
%Docstring | ||
|
||
Class that handles mesh creation with Delaunay constrained triangulation | ||
|
||
.. versionadded:: 3.16 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsmeshtriangulation.h" | ||
%End | ||
public: | ||
|
||
QgsMeshTriangulation(); | ||
%Docstring | ||
Contructor | ||
%End | ||
|
||
~QgsMeshTriangulation(); | ||
|
||
bool addVertices( QgsVectorLayer *vectorLayer, int valueAttribute, const QgsCoordinateTransformContext &transformContext, QgsFeedback *feedback = 0 ); | ||
%Docstring | ||
Adds vertices to the triangulation from a vector layer, return true if success. | ||
|
||
:param vectorLayer: the vector layer with vertices to insert | ||
:param valueAttribute: the index of the attribute that represents the value of vertices, if -1 uses Z coordinate of vertices | ||
:param transformContext: the transform context used to transform coordinates | ||
%End | ||
|
||
bool addBreakLines( QgsVectorLayer *linesSource, int valueAttribute, const QgsCoordinateTransformContext &transformContext, QgsFeedback *feedback = 0 ); | ||
%Docstring | ||
Adds break lines from a vector layer, return true if success | ||
|
||
:param vectorLayer: the vector layer with break lines to insert | ||
:param valueAttribute: the index of the attribute that represents the value of vertices, if -1 uses Z coordinate of vertices | ||
:param transformContext: the transform context used to transform coordinates | ||
|
||
.. note:: | ||
|
||
if the vector layer contain point, only vertices will be added without breaklines | ||
%End | ||
|
||
QgsMesh triangulatedMesh() const; | ||
%Docstring | ||
Returns the triangulated mesh | ||
%End | ||
|
||
void setCrs( const QgsCoordinateReferenceSystem &crs ); | ||
%Docstring | ||
Sets the coordinate reference system used for the triangulation | ||
%End | ||
|
||
private: | ||
QgsMeshTriangulation( const QgsMeshTriangulation &rhs ); | ||
}; | ||
|
||
|
||
class QgsMeshZValueDatasetGroup: QgsMeshDatasetGroup | ||
{ | ||
%Docstring | ||
|
||
Convenient class that can be used to obtain a datasetgroup on vertices that represents the Z value of the mesh vertices | ||
|
||
.. versionadded:: 3.16 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsmeshtriangulation.h" | ||
%End | ||
public: | ||
QgsMeshZValueDatasetGroup( const QString &datasetGroupName, const QgsMesh &mesh ); | ||
%Docstring | ||
Constructor | ||
|
||
:param datasetGroupName: the name of the dataset group | ||
:param mesh: the mesh used to create the Z value dataset | ||
%End | ||
|
||
virtual void initialize(); | ||
|
||
virtual QgsMeshDatasetMetadata datasetMetadata( int datasetIndex ) const; | ||
|
||
virtual int datasetCount() const; | ||
|
||
virtual QgsMeshDataset *dataset( int index ) const; | ||
|
||
virtual QgsMeshDatasetGroup::Type type() const; | ||
virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const; | ||
|
||
|
||
private: | ||
QgsMeshZValueDatasetGroup( const QgsMeshZValueDatasetGroup &rhs ); | ||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/analysis/mesh/qgsmeshtriangulation.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
TinInterpolation.py | ||
--------------------- | ||
Date : August 2020 | ||
Copyright : (C) 2020 by Vincent Cloarec | ||
Email : vcloarec 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. * | ||
* * | ||
*************************************************************************** | ||
""" | ||
|
||
__author__ = 'Vincent Cloarec' | ||
__date__ = 'August 2020' | ||
__copyright__ = '(C) 2020, Vincent Cloarec' | ||
|
||
import os | ||
|
||
from qgis.PyQt.QtGui import QIcon | ||
from qgis.utils import iface | ||
|
||
from qgis.core import (QgsProcessingUtils, | ||
QgsProcessingContext, | ||
QgsProcessingParameterCrs, | ||
QgsProcessingParameterEnum, | ||
QgsProcessingParameterFileDestination, | ||
QgsProcessingException, | ||
QgsProviderRegistry, | ||
QgsMeshDriverMetadata, | ||
QgsMeshLayer) | ||
from qgis.analysis import (QgsMeshTriangulation, | ||
QgsMeshZValueDatasetGroup) | ||
|
||
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm | ||
from processing.algs.qgis.ui.TinMeshWidgets import ParameterTinMeshData | ||
|
||
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0] | ||
|
||
|
||
class TinMeshCreation(QgisAlgorithm): | ||
SOURCE_DATA = 'SOURCE_DATA' | ||
EXTENT = 'EXTENT' | ||
MESH_FORMAT = 'MESH_FORMAT' | ||
CRS = 'CRS_OUTPUT' | ||
OUTPUT_MESH = 'OUTPUT_MESH' | ||
|
||
def group(self): | ||
return self.tr('Mesh') | ||
|
||
def groupId(self): | ||
return 'mesh' | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def initAlgorithm(self, config=None): | ||
self.addParameter(ParameterTinMeshData(self.SOURCE_DATA, self.tr('Input layer(s)'))) | ||
|
||
self.FORMATS = [] | ||
self.providerMetaData = QgsProviderRegistry.instance().providerMetadata("mdal") | ||
meshDriverMetaList = self.providerMetaData.meshDriversMetadata() | ||
meshDriverAvailable = [] | ||
for driver in meshDriverMetaList: | ||
if bool(driver.capabilities() & QgsMeshDriverMetadata.CanWriteMeshData): | ||
meshDriverAvailable.append(driver) | ||
self.FORMATS.append(driver.name()) | ||
|
||
self.addParameter(QgsProcessingParameterEnum(self.MESH_FORMAT, | ||
self.tr('Output format'), | ||
options=self.FORMATS, | ||
defaultValue=0)) | ||
|
||
self.addParameter(QgsProcessingParameterCrs(self.CRS, | ||
self.tr('Output coordinate system'), | ||
optional=True)) | ||
|
||
self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT_MESH, | ||
self.tr('Output file'), | ||
optional=False)) | ||
|
||
def name(self): | ||
return 'tinmeshcreation' | ||
|
||
def displayName(self): | ||
return self.tr('TIN mesh creation') | ||
|
||
def processAlgorithm(self, parameters, context, feedback): | ||
sourceData = ParameterTinMeshData.parseValue(parameters[self.SOURCE_DATA]) | ||
|
||
if sourceData is None: | ||
raise QgsProcessingException( | ||
self.tr('You need to specify at least one input layer.')) | ||
|
||
crs = self.parameterAsCrs(parameters, self.CRS, context) | ||
if not crs.isValid(): | ||
crs = iface.mapCanvas().mapSettings().destinationCrs() | ||
|
||
meshTriangulation = QgsMeshTriangulation() | ||
|
||
for i, row in enumerate(sourceData.split('::|::')): | ||
v = row.split('::~::') | ||
layer = QgsProcessingUtils.mapLayerFromString(v[0], context) | ||
if not crs.isValid(): | ||
crs = layer.sourceCrs() | ||
|
||
valueAttribute = int(v[1]) | ||
|
||
if v[2] == '0': # points | ||
meshTriangulation.addVertices(layer, valueAttribute, context.transformContext(), feedback) | ||
else: # lines | ||
meshTriangulation.addBreakLines(layer, valueAttribute, context.transformContext(), feedback) | ||
|
||
fileName = self.parameterAsFile(parameters, self.OUTPUT_MESH, context) | ||
driverIndex = self.parameterAsEnum(parameters, self.MESH_FORMAT, context) | ||
mesh = meshTriangulation.triangulatedMesh() | ||
self.providerMetaData.createMeshData(mesh, fileName, self.FORMATS[driverIndex], crs) | ||
|
||
#SELAFIN format doesn't support saving Z value on mesh vertices, so create a specific dataset group | ||
if self.FORMATS[driverIndex] == "SELAFIN": | ||
self.addZValueDataset(fileName, mesh) | ||
|
||
context.addLayerToLoadOnCompletion(fileName, QgsProcessingContext.LayerDetails('TIN Mesh', | ||
context.project(), | ||
'TIN', QgsProcessingUtils.LayerHint.Mesh)) | ||
|
||
return {self.OUTPUT_MESH: fileName} | ||
|
||
def addZValueDataset(self, fileName, mesh): | ||
|
||
tempLayer = QgsMeshLayer(fileName, "temp", "mdal") | ||
|
||
zValueDatasetGroup = QgsMeshZValueDatasetGroup(self.tr("Terrain Elevation"), mesh) | ||
tempLayer.addDatasets(zValueDatasetGroup) | ||
datasetGroupIndex = tempLayer.datasetGroupCount() - 1 | ||
tempLayer.saveDataset(fileName, datasetGroupIndex, "SELAFIN") |
Oops, something went wrong.