22 QString QgsPointsLayerFromTableAlgorithm::name()
const
24 return QStringLiteral(
"createpointslayerfromtable" );
27 QString QgsPointsLayerFromTableAlgorithm::displayName()
const
29 return QObject::tr(
"Create points layer from table" );
32 QStringList QgsPointsLayerFromTableAlgorithm::tags()
const
34 return QObject::tr(
"points,create,values,attributes" ).split(
',' );
37 QString QgsPointsLayerFromTableAlgorithm::group()
const
39 return QObject::tr(
"Vector creation" );
42 QString QgsPointsLayerFromTableAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorcreation" );
47 QString QgsPointsLayerFromTableAlgorithm::shortHelpString()
const
49 return QObject::tr(
"This algorithm generates a points layer based on the values from an input table." )
50 + QStringLiteral(
"\n\n" )
51 + QObject::tr(
"The table must contain a field with the X coordinate of each point and another "
52 "one with the Y coordinate, as well as optional fields with Z and M values. A CRS "
53 "for the output layer has to be specified, and the coordinates in the table are "
54 "assumed to be expressed in the units used by that CRS. The attributes table of "
55 "the resulting layer will be the input table." );
58 QgsPointsLayerFromTableAlgorithm *QgsPointsLayerFromTableAlgorithm::createInstance()
const
60 return new QgsPointsLayerFromTableAlgorithm();
63 void QgsPointsLayerFromTableAlgorithm::initAlgorithm(
const QVariantMap & )
75 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"TARGET_CRS" ), QObject::tr(
"Target CRS" ), QStringLiteral(
"EPSG:4326" ) ) );
82 std::unique_ptr< QgsProcessingFeatureSource > featureSource( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
86 QgsFields fields = featureSource->fields();
87 int xFieldIndex = fields.
lookupField( parameterAsString( parameters, QStringLiteral(
"XFIELD" ), context ) );
88 int yFieldIndex = fields.
lookupField( parameterAsString( parameters, QStringLiteral(
"YFIELD" ), context ) );
90 QString fieldName = parameterAsString( parameters, QStringLiteral(
"ZFIELD" ), context );
92 if ( !fieldName.isEmpty() )
95 fieldName = parameterAsString( parameters, QStringLiteral(
"MFIELD" ), context );
97 if ( !fieldName.isEmpty() )
101 if ( zFieldIndex >= 0 )
103 if ( mFieldIndex >= 0 )
113 double step = featureSource->featureCount() > 0 ? 100.0 / featureSource->featureCount() : 1;
132 double x = attrs.at( xFieldIndex ).toDouble( &xOk );
133 double y = attrs.at( yFieldIndex ).toDouble( &yOk );
135 if ( ! attrs.at( xFieldIndex ).isNull() && ! attrs.at( yFieldIndex ).isNull() && xOk && yOk )
139 if ( zFieldIndex >= 0 && ! attrs.at( zFieldIndex ).isNull() )
140 point.addZValue( attrs.at( zFieldIndex ).toDouble() );
142 if ( mFieldIndex >= 0 && ! attrs.at( mFieldIndex ).isNull() )
143 point.addMValue( attrs.at( mFieldIndex ).toDouble() );
148 sink->addFeature( f );
154 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
This class represents a coordinate reference system (CRS).
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
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 SIP_HOLDGIL
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.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
A geometry is the spatial representation of a feature.
Point geometry type, with support for z-dimension and m-values.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Base class for providing feedback from a processing algorithm.
A coordinate reference system parameter for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A vector layer or feature source field parameter for processing algorithms.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ TypeVectorPoint
Vector point layers.
Type
The WKB type describes the number of dimensions a geometry has.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
const QgsCoordinateReferenceSystem & crs