32QString QgsMeshSurfaceToPolygonAlgorithm::shortHelpString()
const
34 return QObject::tr(
"This algorithm exports a polygon file containing mesh layer boundary. It may contain holes and it may be a multi-part polygon." );
37QString QgsMeshSurfaceToPolygonAlgorithm::name()
const
39 return QStringLiteral(
"surfacetopolygon" );
42QString QgsMeshSurfaceToPolygonAlgorithm::displayName()
const
44 return QObject::tr(
"Surface to polygon" );
47QString QgsMeshSurfaceToPolygonAlgorithm::group()
const
49 return QObject::tr(
"Mesh" );
52QString QgsMeshSurfaceToPolygonAlgorithm::groupId()
const
54 return QStringLiteral(
"mesh" );
59 return new QgsMeshSurfaceToPolygonAlgorithm();
62void QgsMeshSurfaceToPolygonAlgorithm::initAlgorithm(
const QVariantMap &configuration )
64 Q_UNUSED( configuration );
68 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS_OUTPUT" ), QObject::tr(
"Output coordinate system" ), QVariant(),
true ) );
75 QgsMeshLayer *meshLayer = parameterAsMeshLayer( parameters, QStringLiteral(
"INPUT" ), context );
77 if ( !meshLayer || !meshLayer->
isValid() )
101 return QVariantMap();
103 feedback->
pushInfo( QObject::tr(
"Creating output vector layer" ) );
110 return QVariantMap();
115 return QVariantMap();
121 QMap<std::pair<int, int>,
int> edges;
122 std::pair<int, int> edge;
125 feedback->
setProgressText( QObject::tr(
"Parsing mesh faces to extract edges." ) );
127 for (
int i = 0; i < mNativeMesh.faceCount(); i++ )
132 return QVariantMap();
135 face = mNativeMesh.face( i );
137 for (
int j = 0; j < face.size(); j++ )
140 if ( j == face.size() - 1 )
144 int edgeFirstVertex = face.at( j );
145 int edgeSecondVertex = face.at( indexEnd );
148 if ( edgeSecondVertex < edgeFirstVertex )
149 edge = std::make_pair( edgeSecondVertex, edgeFirstVertex );
151 edge = std::make_pair( edgeFirstVertex, edgeSecondVertex );
154 auto it = edges.find( edge );
155 if ( it != edges.end() )
157 int count = edges.take( edge ) + 1;
158 edges.insert( edge, count );
162 edges.insert( edge, 1 );
167 feedback->
setProgress( 100.0 *
static_cast<double>( i ) / mNativeMesh.faceCount() );
179 for (
auto it = edges.begin(); it != edges.end(); it++ )
184 return QVariantMap();
188 if ( it.value() == 1 )
190 std::unique_ptr<QgsLineString> line(
new QgsLineString( mNativeMesh.vertex( it.key().first ), mNativeMesh.vertex( it.key().second ) ) );
191 multiLineString->addGeometry( line.release() );
195 feedback->
setProgress( 100.0 *
static_cast<double>( i ) / edges.size() );
202 feedback->
setProgressText( QObject::tr(
"Creating final geometry." ) );
204 return QVariantMap();
213 QVector<QgsAbstractGeometry *> polygons;
221 return QVariantMap();
226 polygon->
setExteriorRing( qgsgeometry_cast<QgsLineString *>( *pit )->clone() );
229 if ( polygons.empty() )
231 polygons.push_back( polygon );
242 for (
int i = 0; i < polygons.count(); i++ )
244 QgsPolygon *p = qgsgeometry_cast<QgsPolygon *>( polygons.at( i ) );
247 if ( engine->contains( p ) )
249 polygons.removeAt( i );
254 else if ( engine->within( p ) )
264 polygons.append( polygon );
271 std::unique_ptr<QgsMultiPolygon> multiPolygon = std::make_unique<QgsMultiPolygon>();
272 multiPolygon->addGeometries( polygons );
277 return QVariantMap();
290 feedback->
reportError( QObject::tr(
"Could not transform point to destination CRS" ) );
301 feedback->
pushInfo( QObject::tr(
"Output vector layer created" ) );
303 return QVariantMap();
307 ret[QStringLiteral(
"OUTPUT" )] = 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.
This class 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.
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.
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
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...
Line string geometry type, with support for z-dimension and m-values.
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.
Multi line string geometry collection.
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.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
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.
QVector< int > QgsMeshFace
List of vertex indexes.
const QgsCoordinateReferenceSystem & outputCrs