QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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"
23 #include "qgsgeometrycollection.h"
24 
26 
27 QString QgsSplitGeometryAtAntimeridianAlgorithm::name() const
28 {
29  return QStringLiteral( "antimeridiansplit" );
30 }
31 
32 QString QgsSplitGeometryAtAntimeridianAlgorithm::displayName() const
33 {
34  return QObject::tr( "Geodesic line split at antimeridian" );
35 }
36 
37 QStringList QgsSplitGeometryAtAntimeridianAlgorithm::tags() const
38 {
39  return QObject::tr( "break,cut,dateline,180,-180,longitude,geographic,ellipsoid" ).split( ',' );
40 }
41 
42 QString QgsSplitGeometryAtAntimeridianAlgorithm::group() const
43 {
44  return QObject::tr( "Vector geometry" );
45 }
46 
47 QString QgsSplitGeometryAtAntimeridianAlgorithm::groupId() const
48 {
49  return QStringLiteral( "vectorgeometry" );
50 }
51 
52 QString 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 
57 QString 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 
70 QList<int> QgsSplitGeometryAtAntimeridianAlgorithm::inputLayerTypes() const
71 {
72  return QList<int>() << QgsProcessing::TypeVectorLine;
73 }
74 
75 QgsProcessing::SourceType QgsSplitGeometryAtAntimeridianAlgorithm::outputLayerType() const
76 {
78 }
79 
80 QgsSplitGeometryAtAntimeridianAlgorithm *QgsSplitGeometryAtAntimeridianAlgorithm::createInstance() const
81 {
82  return new QgsSplitGeometryAtAntimeridianAlgorithm();
83 }
84 
85 QString QgsSplitGeometryAtAntimeridianAlgorithm::outputName() const
86 {
87  return QObject::tr( "Split" );
88 }
89 
90 QgsWkbTypes::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 
101 bool QgsSplitGeometryAtAntimeridianAlgorithm::prepareAlgorithm( const QVariantMap &, QgsProcessingContext &context, QgsProcessingFeedback * )
102 {
103  if ( context.project() )
104  {
105  mDa.setEllipsoid( context.project()->ellipsoid() );
106  }
107 
108  mTransformContext = context.transformContext();
109  return true;
110 }
111 
112 QgsFeatureList QgsSplitGeometryAtAntimeridianAlgorithm::processFeature( const QgsFeature &f, QgsProcessingContext &, QgsProcessingFeedback * )
113 {
114  if ( !f.hasGeometry() )
115  {
116  return QgsFeatureList() << f;
117  }
118  else
119  {
120  QgsFeature feat = f;
121  feat.setGeometry( mDa.splitGeometryAtAntimeridian( f.geometry() ) );
122  return QgsFeatureList() << feat;
123  }
124 }
125 
126 
128 
129 
130 
static Type multiType(Type type)
Returns the multi type for a WKB type.
Definition: qgswkbtypes.h:299
Base class for providing feedback from a processing algorithm.
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:571
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
QString ellipsoid
Definition: qgsproject.h:97
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:197
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
This class represents a coordinate reference system (CRS).
Vector line layers.
Definition: qgsprocessing.h:49
void setGeometry(const QgsGeometry &geometry)
Set the feature&#39;s geometry.
Definition: qgsfeature.cpp:137
SourceType
Data source types enum.
Definition: qgsprocessing.h:44
const QgsCoordinateReferenceSystem & outputCrs
QgsGeometry geometry
Definition: qgsfeature.h:67
Contains information about the context in which a processing algorithm is executed.