diff --git a/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h b/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h index 7b2cb92ae76dacd8f8bda4fb52313aab01c012c9..9f54de2daf949207a7a9fe06905351cf44822387 100644 --- a/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h +++ b/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h @@ -22,6 +22,7 @@ #define otbOGRVectorDataIO_h #include <string> +#include <map> #include <cassert> #include "otbVectorDataIOBase.h" @@ -124,6 +125,19 @@ private: GDALDataset * m_DataSource; + const std::map<std::string, std::string> + m_OGRExtensionsToDrivers = { + { ".SHP", "ESRI Shapefile"}, + { ".TAB", "MapInfo File"}, + { ".GML", "GML"}, + { ".GPX", "GPX"}, + { ".SQLITE", "SQLite"}, + {".KML", "KML"}, + { ".GMT", "OGR_GMT"}, + { ".GPKG", "GPKG"}, + { ".JSON", "GeoJSON"}, + { ".GEOJSON", "GeoJSON"} + }; }; } // end namespace otb diff --git a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx index 8376a60d6b7e11af725af29b02963d492e331a80..37dace233af58511e43834c904b688bc998f9dea 100644 --- a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx +++ b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx @@ -349,16 +349,9 @@ OGRVectorDataIO::GetOGRDriverName(std::string name) const else { 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 if (extension == ".GMT") driverOGR = "OGR_GMT"; + if(m_OGRExtensionsToDrivers.count(extension)==1) driverOGR = m_OGRExtensionsToDrivers.at(extension); else driverOGR = "NOT-FOUND"; } - //std::cout << name << " " << driverOGR <<" "<<upperName<< " "<< upperName.substr(0, 3) << std::endl; return driverOGR; }