QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsalgorithmsplitlineantimeridian.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmsplitlineantimeridian.cpp
3 -------------------------------------
4 begin : January 2019
5 copyright : (C) 2019 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7
8 ***************************************************************************/
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "qgscurve.h"
20#include "qgslinestring.h"
21#include "qgscircularstring.h"
22#include "qgscompoundcurve.h"
24
26
27QString QgsSplitGeometryAtAntimeridianAlgorithm::name() const
28{
29 return QStringLiteral( "antimeridiansplit" );
30}
31
32QString QgsSplitGeometryAtAntimeridianAlgorithm::displayName() const
33{
34 return QObject::tr( "Geodesic line split at antimeridian" );
35}
36
37QStringList QgsSplitGeometryAtAntimeridianAlgorithm::tags() const
38{
39 return QObject::tr( "break,cut,dateline,180,-180,longitude,geographic,ellipsoid" ).split( ',' );
40}
41
42QString QgsSplitGeometryAtAntimeridianAlgorithm::group() const
43{
44 return QObject::tr( "Vector geometry" );
45}
46
47QString QgsSplitGeometryAtAntimeridianAlgorithm::groupId() const
48{
49 return QStringLiteral( "vectorgeometry" );
50}
51
52QString QgsSplitGeometryAtAntimeridianAlgorithm::shortDescription() const
53{
54 return QObject::tr( "Splits lines into multiple geodesic segments when the line crosses the antimeridian (±180 degrees longitude)." );
55}
56
57QString QgsSplitGeometryAtAntimeridianAlgorithm::shortHelpString() const
58{
59 return QObject::tr( "This algorithm splits a line into multiple geodesic segments, whenever the line crosses the antimeridian (±180 degrees longitude).\n\n"
60 "Splitting at the antimeridian helps the visual display of the lines in some projections. The returned "
61 "geometry will always be a multi-part geometry.\n\n"
62 "Whenever line segments in the input geometry cross the antimeridian, they will be "
63 "split into two segments, with the latitude of the breakpoint being determined using a geodesic "
64 "line connecting the points either side of this segment. The current project ellipsoid setting will "
65 "be used when calculating this breakpoint.\n\n"
66 "If the input geometry contains M or Z values, these will be linearly interpolated for the new vertices "
67 "created at the antimeridian." );
68}
69
70QList<int> QgsSplitGeometryAtAntimeridianAlgorithm::inputLayerTypes() const
71{
72 return QList<int>() << QgsProcessing::TypeVectorLine;
73}
74
75QgsProcessing::SourceType QgsSplitGeometryAtAntimeridianAlgorithm::outputLayerType() const
76{
78}
79
80QgsSplitGeometryAtAntimeridianAlgorithm *QgsSplitGeometryAtAntimeridianAlgorithm::createInstance() const
81{
82 return new QgsSplitGeometryAtAntimeridianAlgorithm();
83}
84
85QString QgsSplitGeometryAtAntimeridianAlgorithm::outputName() const
86{
87 return QObject::tr( "Split" );
88}
89
90QgsWkbTypes::Type QgsSplitGeometryAtAntimeridianAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
91{
92 return QgsWkbTypes::multiType( inputWkbType );
93}
94
96{
97 mDa.setSourceCrs( inputCrs, mTransformContext );
98 return inputCrs;
99}
100
101bool QgsSplitGeometryAtAntimeridianAlgorithm::prepareAlgorithm( const QVariantMap &, QgsProcessingContext &context, QgsProcessingFeedback * )
102{
103 mDa.setEllipsoid( context.ellipsoid() );
104 mTransformContext = context.transformContext();
105 return true;
106}
107
108QgsFeatureList QgsSplitGeometryAtAntimeridianAlgorithm::processFeature( const QgsFeature &f, QgsProcessingContext &, QgsProcessingFeedback * )
109{
110 if ( !f.hasGeometry() )
111 {
112 return QgsFeatureList() << f;
113 }
114 else
115 {
116 QgsFeature feat = f;
117 feat.setGeometry( mDa.splitGeometryAtAntimeridian( f.geometry() ) );
118 return QgsFeatureList() << feat;
119 }
120}
121
122
124
125
126
This class represents a coordinate reference system (CRS).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
QgsGeometry geometry
Definition: qgsfeature.h:67
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:233
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:170
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QString ellipsoid() const
Returns the ellipsoid to use for distance and area calculations.
Base class for providing feedback from a processing algorithm.
SourceType
Data source types enum.
Definition: qgsprocessing.h:46
@ TypeVectorLine
Vector line layers.
Definition: qgsprocessing.h:50
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
static Type multiType(Type type) SIP_HOLDGIL
Returns the multi type for a WKB type.
Definition: qgswkbtypes.h:304
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:922
const QgsCoordinateReferenceSystem & outputCrs