Commit 168dbba1 authored by Charles Peyrega's avatar Charles Peyrega

ENH: Replace use of GetPathName, GetShortFileName and GetExtension methods of...

ENH: Replace use of GetPathName, GetShortFileName and GetExtension methods of otbSystem.h by similar ones of itksys/SystemTools.hxx
parent d2c2b410
......@@ -161,9 +161,9 @@ private:
std::vector<std::string> options;
ogrDS = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Overwrite);
std::string layername = otb::System::GetShortFileName(shapefile);
std::string extension = otb::System::GetExtension(shapefile);
layername = layername.substr(0,layername.size()-(extension.size()+1));
std::string layername = itksys::SystemTools::GetFilenameName(shapefile);
std::string extension = itksys::SystemTools::GetFilenameLastExtension(shapefile);
layername = layername.substr(0,layername.size()-(extension.size()));
layer = ogrDS->CreateLayer(layername, &oSRS, wkbMultiPolygon, options);
OGRFieldDefn labelField("label", OFTInteger);
......@@ -342,7 +342,7 @@ private:
layer.ogr().CommitTransaction();
if(extension=="shp"){
if(extension==".shp"){
sqloss.str("");
sqloss<<"REPACK "<<layername;
ogrDS->ogr().ExecuteSQL(sqloss.str().c_str(), NULL, NULL);
......
......@@ -87,8 +87,8 @@ bool BSQImageIO::CanReadFile(const char* filename)
{
std::fstream header_file;
std::string lFileName(filename);
std::string extension = System::GetExtension(filename);
if ((extension != "HD") && (extension != "hd"))
std::string extension = itksys::SystemTools::GetFilenameLastExtension(filename);
if ((extension != ".HD") && (extension != ".hd"))
{
return false;
}
......@@ -96,7 +96,7 @@ bool BSQImageIO::CanReadFile(const char* filename)
{
return false;
}
if (System::SetToLower(System::GetExtension(lFileName)) != "hd")
if (System::SetToLower(itksys::SystemTools::GetFilenameLastExtension(lFileName)) != ".hd")
{
return false;
}
......@@ -467,8 +467,8 @@ bool BSQImageIO::InternalReadHeaderInformation(const std::string& file_name, std
bool BSQImageIO::CanWriteFile(const char* filename)
{
std::string lFileName(filename);
std::string extension = System::GetExtension(filename);
if ((extension != "HD") && (extension != "hd"))
std::string extension = itksys::SystemTools::GetFilenameLastExtension(filename);
if ((extension != ".HD") && (extension != ".hd"))
{
return false;
}
......@@ -476,8 +476,8 @@ bool BSQImageIO::CanWriteFile(const char* filename)
{
return false;
}
const std::string Extension = System::GetExtension(filename);
if ((Extension == "hd") || (Extension == "HD"))
const std::string Extension = itksys::SystemTools::GetFilenameLastExtension(filename);
if ((Extension == ".hd") || (Extension == ".HD"))
{
return true;
}
......
......@@ -22,6 +22,7 @@
#include "otbGDALImageIO.h"
#include "otbMacro.h"
#include "otbSystem.h"
#include "itksys/SystemTools.hxx"
#include "otbImage.h"
#include "itkVariableLengthVector.h"
......@@ -1602,23 +1603,23 @@ std::string GDALImageIO::FilenameToGdalDriverShortName(const std::string& name)
std::string gdalDriverShortName;
// Get extension in lowercase
extension = otb::System::SetToLower( System::GetExtension(name) );
extension = otb::System::SetToLower( itksys::SystemTools::GetFilenameLastExtension(name) );
if ( extension == "tif" || extension == "tiff" )
if ( extension == ".tif" || extension == ".tiff" )
gdalDriverShortName = "GTiff";
else if ( extension == "hdr" )
else if ( extension == ".hdr" )
gdalDriverShortName = "ENVI";
else if ( extension == "img" )
else if ( extension == ".img" )
gdalDriverShortName = "HFA";
else if ( extension == "ntf" )
else if ( extension == ".ntf" )
gdalDriverShortName = "NITF";
else if ( extension == "png" )
else if ( extension == ".png" )
gdalDriverShortName="PNG";
else if ( extension == "jpg" || extension== "jpeg" )
else if ( extension == ".jpg" || extension== ".jpeg" )
gdalDriverShortName="JPEG";
else if ( extension == "pix" )
else if ( extension == ".pix" )
gdalDriverShortName="PCIDSK";
else if ( extension == "lbl" || extension == "pds" )
else if ( extension == ".lbl" || extension == ".pds" )
gdalDriverShortName="ISIS2";
else
gdalDriverShortName = "NOT-FOUND";
......
......@@ -639,8 +639,8 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
{
std::string strFileName(filename);
std::string extension = System::GetExtension(strFileName);
if ((extension == "HDR") || (extension == "hdr"))
std::string extension = itksys::SystemTools::GetFilenameLastExtension(strFileName);
if ((extension == ".HDR") || (extension == ".hdr"))
{
//Supprime l'extension
GdalFileName = System::GetRootName(strFileName);
......
......@@ -318,12 +318,12 @@ int JPEG2000InternalReader::Open(const char *filename, unsigned int resolution)
// Find the codec file format
std::string lFileName(filename);
if (System::SetToLower(System::GetExtension(lFileName)) == "j2k")
if (System::SetToLower(itksys::SystemTools::GetFilenameLastExtension(lFileName)) == ".j2k")
{
this->m_CodecFormat = CODEC_J2K;
}
else if (System::SetToLower(System::GetExtension(lFileName)) == "jp2"
|| System::SetToLower(System::GetExtension(lFileName)) == "jpx")
else if (System::SetToLower(itksys::SystemTools::GetFilenameLastExtension(lFileName)) == ".jp2"
|| System::SetToLower(itksys::SystemTools::GetFilenameLastExtension(lFileName)) == ".jpx")
{
this->m_CodecFormat = CODEC_JP2;
}
......
......@@ -31,6 +31,7 @@
#include "otbMacro.h"
#include "otbSystem.h"
#include "itksys/SystemTools.hxx"
#include "otbDataNode.h"
#include "itkPreOrderTreeIterator.h"
#include "otbMetaDataKey.h"
......@@ -57,7 +58,7 @@ KMLVectorDataIO::CanReadFile(const char* filename) const
{
return false;
}
if (System::SetToLower(System::GetExtension(lFileName)) != "kml")
if (System::SetToLower(itksys::SystemTools::GetFilenameLastExtension(lFileName)) != ".kml")
{
return false;
}
......@@ -503,7 +504,7 @@ bool KMLVectorDataIO::CanWriteFile(const char* filename) const
{
return false;
}
if (System::SetToLower(System::GetExtension(lFileName)) != "kml")
if (System::SetToLower(itksys::SystemTools::GetFilenameLastExtension(lFileName)) != ".kml")
{
return false;
}
......
......@@ -83,8 +83,8 @@ bool LUMImageIO::CanReadFile(const char* filename)
{
std::string lFileName(filename);
// Test the extension
std::string extension = System::GetExtension(filename);
if ((extension != "LUM") && (extension != "lum"))
std::string extension = itksys::SystemTools::GetFilenameLastExtension(filename);
if ((extension != ".LUM") && (extension != ".lum"))
{
return false;
}
......@@ -310,8 +310,8 @@ bool LUMImageIO::InternalReadHeaderInformation(std::fstream& file, const bool re
bool LUMImageIO::CanWriteFile(const char* filename)
{
std::string lFileName(filename);
std::string extension = System::GetExtension(filename);
if ((extension != "LUM") && (extension != "lum"))
std::string extension = itksys::SystemTools::GetFilenameLastExtension(filename);
if ((extension != ".LUM") && (extension != ".lum"))
{
return false;
}
......@@ -319,8 +319,8 @@ bool LUMImageIO::CanWriteFile(const char* filename)
{
return false;
}
const std::string Extension = System::GetExtension(filename);
if ((Extension == "lum") || (Extension == "LUM"))
const std::string Extension = itksys::SystemTools::GetFilenameLastExtension(filename);
if ((Extension == ".lum") || (Extension == ".LUM"))
{
return true;
}
......
......@@ -315,13 +315,13 @@ OGRVectorDataIO::GetOGRDriverName(std::string name) const
}
else
{
extension = System::GetExtension(upperName);
if (extension == "SHP") driverOGR = "ESRI Shapefile";
else if ((extension == "TAB")) driverOGR = "MapInfo File";
else if (extension == "GML") driverOGR = "GML";
else if (extension == "GPX") driverOGR = "GPX";
else if (extension == "SQLITE") driverOGR = "SQLite";
else if (extension=="KML") driverOGR="KML";
extension = itksys::SystemTools::GetFilenameLastExtension(upperName);
if (extension == ".SHP") driverOGR = "ESRI Shapefile";
else if ((extension == ".TAB")) driverOGR = "MapInfo File";
else if (extension == ".GML") driverOGR = "GML";
else if (extension == ".GPX") driverOGR = "GPX";
else if (extension == ".SQLITE") driverOGR = "SQLite";
else if (extension==".KML") driverOGR="KML";
else driverOGR = "NOT-FOUND";
}
//std::cout << name << " " << driverOGR <<" "<<upperName<< " "<< upperName.substr(0, 3) << std::endl;
......
......@@ -99,7 +99,7 @@ bool RADImageIO::CanReadFile(const char* filename)
{
return false;
}
if (System::SetToLower(System::GetExtension(lFileName)) != "rad")
if (System::SetToLower(itksys::SystemTools::GetFilenameLastExtension(lFileName)) != ".rad")
{
return false;
}
......@@ -449,7 +449,7 @@ bool RADImageIO::InternalReadHeaderInformation(const std::string& file_name, std
}
// Read FileName information
std::string lPathName = System::GetPathName(file_name);
std::string lPathName = itksys::SystemTools::GetFilenamePath(file_name);
m_ChannelsFileName.clear();
for (unsigned int i = 0; i < m_NbOfChannels; ++i)
{
......@@ -489,7 +489,7 @@ bool RADImageIO::InternalReadHeaderInformation(const std::string& file_name, std
bool RADImageIO::CanWriteFile(const char* filename)
{
std::string lFileName(filename);
if (System::SetToLower(System::GetExtension(lFileName)) != "rad")
if (System::SetToLower(itksys::SystemTools::GetFilenameLastExtension(lFileName)) != ".rad")
{
return false;
}
......@@ -726,7 +726,7 @@ void RADImageIO::WriteImageInformation()
for (unsigned int i = 0; i < m_NbOfChannels; ++i)
{
m_HeaderFile << System::GetShortFileName(this->m_ChannelsFileName[i].c_str()) << std::endl;
m_HeaderFile << itksys::SystemTools::GetFilenameName(this->m_ChannelsFileName[i].c_str()) << std::endl;
}
m_HeaderFile.close();
......
......@@ -77,12 +77,12 @@ struct ExtensionDriverAssociation
*/
const ExtensionDriverAssociation k_ExtensionDriverMap[] =
{
{"SHP", "ESRI Shapefile"},
{"TAB", "MapInfo File"},
{"GML", "GML"},
{"GPX", "GPX"},
{"SQLITE", "SQLite"},
{"KML", "KML"},
{".SHP", "ESRI Shapefile"},
{".TAB", "MapInfo File"},
{".GML", "GML"},
{".GPX", "GPX"},
{".SQLITE", "SQLite"},
{".KML", "KML"},
};
/**\ingroup GeometryInternals
* \brief Returns the OGR driver name associated to a filename.
......@@ -99,7 +99,7 @@ char const* DeduceDriverName(std::string filename)
{
return "PostgreSQL";
}
const std::string extension = otb::System::GetExtension(filename);
const std::string extension = itksys::SystemTools::GetFilenameLastExtension(filename);
ExtensionDriverAssociation const* whichIt =
std::find_if(
boost::begin(k_ExtensionDriverMap), boost::end(k_ExtensionDriverMap),
......
......@@ -17,7 +17,7 @@
=========================================================================*/
#include "otbAeronetData.h"
#include "otbAeronetFileReader.h"
#include "otbSystem.h"
#include "itksys/SystemTools.hxx"
#include <fstream>
#include <iomanip>
......@@ -40,7 +40,7 @@ int otbAeronetExtractData(int argc, char * argv[])
std::ofstream fout(argv[8]);
fout << "Aeronet data extracted:" << std::endl;
fout << "Input file name: " << otb::System::GetShortFileName(std::string(argv[1])) << std::endl;
fout << "Input file name: " << itksys::SystemTools::GetFilenameName(std::string(argv[1])) << std::endl;
fout << "Inputs user parameters:" << std::endl;
fout << " Day: " << reader->GetDay() << std::endl;
fout << " Month: " << reader->GetMonth() << std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment