QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
analysis
processing
qgsalgorithmrepairshapefile.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsalgorithmrepairshapefile.cpp
3
---------------------
4
begin : December 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
18
#include "
qgsalgorithmrepairshapefile.h
"
19
20
#include <cpl_conv.h>
21
22
#include "
qgsvectordataprovider.h
"
23
#include "
qgsvectorlayer.h
"
24
25
#include <QString>
26
27
using namespace
Qt::StringLiterals;
28
30
31
QString QgsRepairShapefileAlgorithm::name()
const
32
{
33
return
u
"repairshapefile"
_s;
34
}
35
36
QString QgsRepairShapefileAlgorithm::displayName()
const
37
{
38
return
QObject::tr(
"Repair Shapefile"
);
39
}
40
41
QStringList QgsRepairShapefileAlgorithm::tags()
const
42
{
43
return
QObject::tr(
"fix,shp,shx,broken,missing"
).split(
','
);
44
}
45
46
QString QgsRepairShapefileAlgorithm::group()
const
47
{
48
return
QObject::tr(
"Vector general"
);
49
}
50
51
QString QgsRepairShapefileAlgorithm::groupId()
const
52
{
53
return
u
"vectorgeneral"
_s;
54
}
55
56
QString QgsRepairShapefileAlgorithm::shortHelpString()
const
57
{
58
return
QObject::tr(
"Repairs a broken Shapefile by recreating missing or broken SHX files."
);
59
}
60
61
QString QgsRepairShapefileAlgorithm::shortDescription()
const
62
{
63
return
QObject::tr(
"Repairs broken Shapefiles by recreating SHX files."
);
64
}
65
66
QgsRepairShapefileAlgorithm *QgsRepairShapefileAlgorithm::createInstance()
const
67
{
68
return
new
QgsRepairShapefileAlgorithm();
69
}
70
71
void
QgsRepairShapefileAlgorithm::initAlgorithm(
const
QVariantMap & )
72
{
73
addParameter(
74
new
QgsProcessingParameterFile
( u
"INPUT"
_s, QObject::tr(
"Input Shapefile"
),
Qgis::ProcessingFileParameterBehavior::File
, u
"shp"
_s, QVariant(),
false
, QObject::tr(
"ESRI Shapefile"
) + u
" (*.shp *.SHP)"
_s )
75
);
76
77
addOutput(
new
QgsProcessingOutputVectorLayer
( u
"OUTPUT"
_s, QObject::tr(
"Repaired layer"
) ) );
78
}
79
80
QVariantMap QgsRepairShapefileAlgorithm::processAlgorithm(
const
QVariantMap ¶meters,
QgsProcessingContext
&context,
QgsProcessingFeedback
*feedback )
81
{
82
QGS_MARK_ALGORITHM_SOURCE
83
84
const
QString path = parameterAsFile( parameters, u
"INPUT"
_s, context );
85
86
if
( !QFile::exists( path ) )
87
throw
QgsProcessingException
( QObject::tr(
"Could not load source layer for %1."
).arg(
"INPUT"
_L1 ) );
88
89
CPLSetConfigOption(
"SHAPE_RESTORE_SHX"
,
"YES"
);
90
91
auto
layer = std::make_unique<QgsVectorLayer>( path );
92
if
( !layer->isValid() )
93
{
94
CPLSetConfigOption(
"SHAPE_RESTORE_SHX"
,
nullptr
);
95
throw
QgsProcessingException
( QObject::tr(
"Could not repair %1."
).arg( path ) );
96
}
97
98
CPLSetConfigOption(
"SHAPE_RESTORE_SHX"
,
nullptr
);
99
100
feedback->
pushInfo
( QObject::tr(
"Successfully repaired, found %n feature(s)"
,
nullptr
, layer->featureCount() ) );
101
102
QVariantMap outputs;
103
outputs.insert( u
"OUTPUT"
_s, path );
104
return
outputs;
105
}
106
Qgis::ProcessingFileParameterBehavior::File
@ File
Parameter is a single file.
Definition
qgis.h:4052
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition
qgsprocessingcontext.h:45
QgsProcessingException
Custom exception class for processing related exceptions.
Definition
qgsexception.h:76
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition
qgsprocessingfeedback.h:40
QgsProcessingFeedback::pushInfo
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
Definition
qgsprocessingfeedback.cpp:97
QgsProcessingOutputVectorLayer
A vector layer output for processing algorithms.
Definition
qgsprocessingoutputs.h:236
QgsProcessingParameterFile
An input file or folder parameter for processing algorithms.
Definition
qgsprocessingparameters.h:2161
qgsalgorithmrepairshapefile.h
qgsvectordataprovider.h
qgsvectorlayer.h
Generated on
for QGIS API Documentation by
1.17.0