33 #include "gdal_priv.h"
41 readDirectory(
const char* dir,
const char* label, ostream &xml,
int depth,
int* seq )
49 CPLSetErrorHandler( CPLQuietErrorHandler );
64 if ( myDir.find(
"." ) == 1 ) {
67 if ( myDir.find_first_of(
".",0 ) == 1 ) {
71 if ( myDir.find_last_of(
"/" ) != myDir.size() - 1 ) {
77 struct dirent **nameList;
81 n = scandir( myDir.c_str(), &nameList, 0, alphasort );
94 xml <<
"<LayersGroup Id=\"" << *seq <<
"\">";
98 xml <<
"<Label>" << label <<
"</Label>";
102 for (
int i = 0; i < n; i++ ) {
105 if ( strcmp( nameList[i]->d_name,
"." ) == 0 || strcmp( nameList[i]->d_name,
".." ) == 0 ) {
111 if ( strstr( nameList[i]->d_name,
".aux" ) != 0 ) {
117 string fullName( myDir );
118 fullName.append( nameList[i]->d_name );
121 if ( stat( fullName.c_str(), &buf ) == -1 ) {
127 if ( S_ISDIR( buf.st_mode ) ) {
135 string label =
getLayerLabel( myDir, nameList[i]->d_name,
true );
137 xmlFiles.append(
"<Layer Id=\"" );
138 xmlFiles.append( fullName );
139 xmlFiles.append(
"\" HasProjection=\"");
140 xmlFiles.append( hasProj );
141 xmlFiles.append(
"\">" );
142 xmlFiles.append(
"<Label>" );
143 xmlFiles.append( label );
144 xmlFiles.append(
"</Label>" );
145 xmlFiles.append(
"</Layer>" );
149 r =
readDirectory( fullName.c_str(), nameList[i]->d_name, xml, depth, seq );
153 else if ( S_ISREG( buf.st_mode ) ) {
161 string label =
getLayerLabel( myDir, nameList[i]->d_name,
false );
163 xmlFiles.append(
"<Layer Id=\"" );
164 xmlFiles.append( fullName );
165 xmlFiles.append(
"\" HasProjection=\"");
166 xmlFiles.append( hasProj );
167 xmlFiles.append(
"\">" );
168 xmlFiles.append(
"<Label>" );
169 xmlFiles.append( label );
170 xmlFiles.append(
"</Label>" );
171 xmlFiles.append(
"</Layer>" );
185 xml <<
"</LayersGroup>";
195 string metaFile = path;
201 metaFile = metaFile.append(name).append(
".meta");
206 size_t pos = name.find_last_of(
"." );
208 if ( pos != string::npos ) {
211 string metaName = name.substr( 0, pos ).append(
".meta");
212 metaFile = metaFile.append( metaName );
217 metaFile = metaFile.append(name).append(
".meta");
221 FILE * file = fopen( metaFile.c_str(),
"r" );
223 if ( file != NULL ) {
229 return fParser.
get(
"LABEL" );
241 GDALDataset * testFile = (GDALDataset *)GDALOpen( fileName, GA_ReadOnly );
243 if ( testFile == NULL ) {
251 GDALClose( testFile );
262 GDALDataset * testFile = (GDALDataset *)GDALOpen( fileName, GA_ReadOnly );
264 const char *projectionString = testFile->GetProjectionRef();
266 GDALClose( testFile );
268 if ( projectionString ) {
static Log * instance()
Returns the instance pointer, creating the object on the first call.
string getLayerLabel(const string path, const string name, bool isDir)
bool isValidGdalFile(const char *fileName)
bool readDirectory(const char *dir, const char *label, ostream &xml, int depth, int *seq)
bool hasValidGdalProjection(const char *fileName)
std::string get(const std::string &key) const
void debug(const char *format,...)
'Debug' level.