31using namespace Qt::StringLiterals;
36QString QgsMeshSurfaceToPolygonAlgorithm::shortHelpString()
const
38 return QObject::tr(
"This algorithm exports a polygon layer containing a mesh layer's boundary. It may contain holes and it may be a multi-part polygon." );
41QString QgsMeshSurfaceToPolygonAlgorithm::shortDescription()
const
43 return QObject::tr(
"Exports a polygon layer containing a mesh layer's boundary." );
46QString QgsMeshSurfaceToPolygonAlgorithm::name()
const
48 return u
"surfacetopolygon"_s;
51QString QgsMeshSurfaceToPolygonAlgorithm::displayName()
const
53 return QObject::tr(
"Surface to polygon" );
56QString QgsMeshSurfaceToPolygonAlgorithm::group()
const
58 return QObject::tr(
"Mesh" );
61QString QgsMeshSurfaceToPolygonAlgorithm::groupId()
const
68 return new QgsMeshSurfaceToPolygonAlgorithm();
71void QgsMeshSurfaceToPolygonAlgorithm::initAlgorithm(
const QVariantMap &configuration )
73 Q_UNUSED( configuration );
77 addParameter(
new QgsProcessingParameterCrs( u
"CRS_OUTPUT"_s, QObject::tr(
"Output coordinate system" ), QVariant(),
true ) );
84 QgsMeshLayer *meshLayer = parameterAsMeshLayer( parameters, u
"INPUT"_s, context );
86 if ( !meshLayer || !meshLayer->
isValid() )
94 outputCrs = meshLayer->
crs();
108 return QVariantMap();
110 feedback->
pushInfo( QObject::tr(
"Creating output vector layer" ) );
116 return QVariantMap();
119 return QVariantMap();
124 QMap<std::pair<int, int>,
int> edges;
125 std::pair<int, int> edge;
127 feedback->
setProgressText( QObject::tr(
"Parsing mesh faces to extract edges." ) );
129 for (
int i = 0; i < mNativeMesh.faceCount(); i++ )
132 return QVariantMap();
134 face = mNativeMesh.face( i );
136 for (
int j = 0; j < face.size(); j++ )
139 if ( j == face.size() - 1 )
143 int edgeFirstVertex = face.at( j );
144 int edgeSecondVertex = face.at( indexEnd );
147 if ( edgeSecondVertex < edgeFirstVertex )
148 edge = std::make_pair( edgeSecondVertex, edgeFirstVertex );
150 edge = std::make_pair( edgeFirstVertex, edgeSecondVertex );
153 auto it = edges.find( edge );
154 if ( it != edges.end() )
156 int count = edges.take( edge ) + 1;
157 edges.insert( edge, count );
161 edges.insert( edge, 1 );
165 feedback->
setProgress( 100.0 *
static_cast<double>( i ) / mNativeMesh.faceCount() );
171 auto multiLineString = std::make_unique<QgsMultiLineString>();
174 for (
auto it = edges.begin(); it != edges.end(); it++ )
177 return QVariantMap();
180 if ( it.value() == 1 )
182 auto line = std::make_unique<QgsLineString>( mNativeMesh.vertex( it.key().first ), mNativeMesh.vertex( it.key().second ) );
183 multiLineString->addGeometry( line.release() );
186 feedback->
setProgress( 100.0 *
static_cast<double>( i ) / edges.size() );
191 feedback->
setProgressText( QObject::tr(
"Creating final geometry." ) );
193 return QVariantMap();
201 QVector<QgsAbstractGeometry *> polygons;
207 return QVariantMap();
214 if ( polygons.empty() )
216 polygons.push_back( polygon );
227 for (
int i = 0; i < polygons.count(); i++ )
232 if ( engine->contains( p ) )
234 polygons.removeAt( i );
239 else if ( engine->within( p ) )
249 polygons.append( polygon );
256 auto multiPolygon = std::make_unique<QgsMultiPolygon>();
257 multiPolygon->addGeometries( polygons );
260 return QVariantMap();
271 feedback->
reportError( QObject::tr(
"Could not transform point to destination CRS" ) );
285 feedback->
pushInfo( QObject::tr(
"Output vector layer created" ) );
287 return QVariantMap();
290 ret[u
"OUTPUT"_s] = identifier;
@ VectorPolygon
Vector polygon layers.
@ MultiPolygon
MultiPolygon.
Abstract base class for all geometries.
const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary const part after the last part of the geometry.
const_part_iterator const_parts_begin() const
Returns STL-style iterator pointing to the const first part of the geometry.
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Custom exception class for Coordinate Reference System related exceptions.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
QgsCurve * clone() const override=0
Clones the geometry by performing a deep copy.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
QgsGeometry mergeLines(const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry, double precision=0.0, Qgis::GeosCreationFlags flags=Qgis::GeosCreationFlag::SkipEmptyInteriorRings)
Creates and returns a new geometry engine representing the specified geometry using precision on a gr...
QgsCoordinateReferenceSystem crs
Represents a mesh layer supporting display of data on structured or unstructured meshes.
void updateTriangularMesh(const QgsCoordinateTransform &transform=QgsCoordinateTransform())
Gets native mesh and updates (creates if it doesn't exist) the base triangular mesh.
QgsMesh * nativeMesh()
Returns native mesh (nullptr before rendering or calling to updateMesh).
bool isEditable() const override
Returns true if the layer can be edited.
void setExteriorRing(QgsCurve *ring) override
Sets the exterior ring of the polygon.
void addInteriorRing(QgsCurve *ring) override
Adds an interior ring to the geometry (takes ownership).
Abstract base class for processing algorithms.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
void featureAddedToSink(const QString &output)
Reports that a feature was added to the the sink associated with the specified algorithm output.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
void featureSinkFinalized(const QString &output)
Reports that a feature sink has been finalized.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
virtual void setProgressText(const QString &text)
Sets a progress report text string.
A coordinate reference system parameter for processing algorithms.
A feature sink output for processing algorithms.
A mesh layer parameter for processing algorithms.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QVector< int > QgsMeshFace
List of vertex indexes.