QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
QgsWkbTypes::multiType
static Type multiType(Type type)
Returns the multi type for a WKB type.
Definition: qgswkbtypes.h:301
outputCrs
const QgsCoordinateReferenceSystem & outputCrs
Definition: qgswfsgetfeature.cpp:115
qgslinestring.h
QgsProcessingContext::project
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Definition: qgsprocessingcontext.h:99
QgsProcessingFeedback
Definition: qgsprocessingfeedback.h:37
qgscompoundcurve.h
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsProcessing::TypeVectorLine
@ TypeVectorLine
Vector line layers.
Definition: qgsprocessing.h:49
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
QgsFeature::setGeometry
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:137
QgsProcessingContext
Definition: qgsprocessingcontext.h:43
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:572
QgsProcessingContext::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
Definition: qgsprocessingcontext.h:135
qgscircularstring.h
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
qgscurve.h
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:197
qgsgeometrycollection.h
QgsFeature
Definition: qgsfeature.h:55
qgsalgorithmsplitlineantimeridian.h
QgsProject::ellipsoid
QString ellipsoid
Definition: qgsproject.h:100
QgsProcessing::SourceType
SourceType
Data source types enum.
Definition: qgsprocessing.h:44