25 QString QgsRepairShapefileAlgorithm::name()
const
27 return QStringLiteral(
"repairshapefile" );
30 QString QgsRepairShapefileAlgorithm::displayName()
const
32 return QObject::tr(
"Repair Shapefile" );
35 QStringList QgsRepairShapefileAlgorithm::tags()
const
37 return QObject::tr(
"fix,shp,shx,broken,missing" ).split(
',' );
40 QString QgsRepairShapefileAlgorithm::group()
const
42 return QObject::tr(
"Vector general" );
45 QString QgsRepairShapefileAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeneral" );
50 QString QgsRepairShapefileAlgorithm::shortHelpString()
const
52 return QObject::tr(
"Repairs a broken Shapefile by recreating missing or broken SHX files." );
55 QString QgsRepairShapefileAlgorithm::shortDescription()
const
57 return QObject::tr(
"Repairs broken Shapefiles by recreating SHX files." );
60 QgsRepairShapefileAlgorithm *QgsRepairShapefileAlgorithm::createInstance()
const
62 return new QgsRepairShapefileAlgorithm();
65 void QgsRepairShapefileAlgorithm::initAlgorithm(
const QVariantMap & )
68 QStringLiteral(
"shp" ), QVariant(),
false, QObject::tr(
"ESRI Shapefile" ) +
69 QStringLiteral(
" (*.shp *.SHP)" ) ) );
76 const QString path = parameterAsFile( parameters, QStringLiteral(
"INPUT" ), context );
78 if ( !QFile::exists( path ) )
79 throw QgsProcessingException( QObject::tr(
"Could not load source layer for %1." ).arg( QStringLiteral(
"INPUT" ) ) );
81 CPLSetConfigOption(
"SHAPE_RESTORE_SHX",
"YES" );
83 std::unique_ptr< QgsVectorLayer > layer = qgis::make_unique< QgsVectorLayer >( path );
84 if ( !layer->isValid() )
87 CPLSetConfigOption(
"SHAPE_RESTORE_SHX",
nullptr );
89 feedback->
pushInfo( QObject::tr(
"Successfully repaired, found %1 features" ).arg( layer->featureCount() ) );
92 outputs.insert( QStringLiteral(
"OUTPUT" ), path );