24QString QgsDefineProjectionAlgorithm::name()
const
26 return QStringLiteral(
"definecurrentprojection" );
29QString QgsDefineProjectionAlgorithm::displayName()
const
31 return QObject::tr(
"Define projection" );
34QStringList QgsDefineProjectionAlgorithm::tags()
const
36 return QObject::tr(
"layer,shp,prj,qpj,change,alter" ).split(
',' );
39QString QgsDefineProjectionAlgorithm::group()
const
41 return QObject::tr(
"Vector general" );
44QString QgsDefineProjectionAlgorithm::groupId()
const
46 return QStringLiteral(
"vectorgeneral" );
49QString QgsDefineProjectionAlgorithm::shortHelpString()
const
51 return QObject::tr(
"Sets an existing layer's projection to the provided CRS without reprojecting features. "
52 "Contrary to the \"Assign projection\" algorithm, it will not output a new layer.\n\n"
53 "If the input layer is a shapefile, the .prj file will be overwritten — or created if "
54 "missing — to match the provided CRS." );
57QgsDefineProjectionAlgorithm *QgsDefineProjectionAlgorithm::createInstance()
const
59 return new QgsDefineProjectionAlgorithm();
62void QgsDefineProjectionAlgorithm::initAlgorithm(
const QVariantMap & )
71 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral(
"INPUT" ), context );
77 mLayerId = layer->
id();
79 if ( layer->
providerType().compare( QStringLiteral(
"ogr" ), Qt::CaseSensitivity::CaseInsensitive ) == 0 )
83 if ( parts.size() > 0 )
85 layerPath = parts.value( QStringLiteral(
"path" ) ).toString();
88 if ( !layerPath.isEmpty() && layerPath.endsWith( QStringLiteral(
".shp" ), Qt::CaseSensitivity::CaseInsensitive ) )
90 const QString filePath = layerPath.chopped( 4 );
93 QFile prjFile( filePath + QLatin1String(
".prj" ) );
94 if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
96 QTextStream stream( &prjFile );
97 stream << wkt << Qt::endl;
101 feedback->
pushWarning( QObject::tr(
"Failed to open .prj file for writing." ) );
104 QFile qpjFile( filePath + QLatin1String(
".qpj" ) );
105 if ( qpjFile.exists() )
112 feedback->
pushWarning( QObject::tr(
"Data source isn't a shapefile, skipping .prj creation" ) );
117 feedback->
pushInfo( QObject::tr(
"Data source isn't a shapefile, skipping .prj creation" ) );
128 Q_UNUSED( parameters );
130 Q_UNUSED( feedback );
133 results.insert( QStringLiteral(
"OUTPUT" ), mLayerId );
@ VectorAnyGeometry
Any vector layer with geometry.
@ Wkt1Esri
WKT1 as traditionally output by ESRI software, deriving from OGC 99-049.
This class represents a coordinate reference system (CRS).
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
QString providerType() const
Returns the provider type (provider key) for this layer.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
Contains information about the context in which a processing algorithm is executed.
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 pushWarning(const QString &warning)
Pushes a warning informational message from the algorithm.
A vector layer output for processing algorithms.
A coordinate reference system parameter for processing algorithms.
A vector layer (with or without geometry) parameter for processing algorithms.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Represents a vector layer which manages a vector based data sets.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
const QgsCoordinateReferenceSystem & crs