-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge GH-1793 (KMZ ground overlay support)
- Loading branch information
Showing
28 changed files
with
1,233 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2020 Kai Pastor | ||
* | ||
* This file is part of OpenOrienteering. | ||
* | ||
* OpenOrienteering is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* OpenOrienteering is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "gdal_file.h" | ||
|
||
#include <cpl_conv.h> | ||
#include <cpl_vsi.h> | ||
#include <gdal.h> | ||
|
||
#include <QByteArray> | ||
#include <QString> | ||
|
||
|
||
namespace OpenOrienteering { | ||
|
||
namespace GdalFile { | ||
|
||
bool exists(const QByteArray& filepath) | ||
{ | ||
VSIStatBufL stat_buf; | ||
return VSIStatExL(filepath, &stat_buf, VSI_STAT_EXISTS_FLAG) == 0; | ||
} | ||
|
||
bool isRelative(const QByteArray& filepath) | ||
{ | ||
return CPLIsFilenameRelative(filepath) == TRUE; | ||
} | ||
|
||
|
||
bool isDir(const QByteArray& filepath) | ||
{ | ||
VSIStatBufL stat_buf; | ||
return VSIStatExL(filepath, &stat_buf, VSI_STAT_EXISTS_FLAG | VSI_STAT_NATURE_FLAG) == 0 | ||
&& VSI_ISDIR(stat_buf.st_mode); | ||
} | ||
|
||
bool mkdir(const QByteArray& filepath) | ||
{ | ||
// 0777 would be right for POSIX mkdir with umask, but we | ||
// cannot rely on umask for all paths supported by VSIMkdir. | ||
return VSIMkdir(filepath, 0755) == 0; | ||
} | ||
|
||
|
||
QByteArray tryToFindRelativeTemplateFile(const QByteArray& template_path, const QByteArray& map_path) | ||
{ | ||
QByteArray filepath = map_path + '/' + template_path; | ||
if (!exists(filepath)) | ||
filepath = QByteArray(CPLGetDirname(map_path)) + '/' + template_path; | ||
if (!exists(filepath)) | ||
filepath.clear(); | ||
return filepath; | ||
} | ||
|
||
} // namespace GdalUtil | ||
|
||
} // namespace OpenOrienteering |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2020 Kai Pastor | ||
* | ||
* This file is part of OpenOrienteering. | ||
* | ||
* OpenOrienteering is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* OpenOrienteering is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef OPENORIENTEERING_GDAL_FILE_H | ||
#define OPENORIENTEERING_GDAL_FILE_H | ||
|
||
class QByteArray; | ||
|
||
namespace OpenOrienteering { | ||
|
||
|
||
/** | ||
* Utility functions which use GDAL's VSI-aware file API. | ||
* | ||
* Paths must be passed as, and are returned as, UTF-8. | ||
* | ||
* \see https://gdal.org/user/virtual_file_systems.html | ||
*/ | ||
namespace GdalFile { | ||
|
||
/** | ||
* Checks if a file exists. | ||
*/ | ||
bool exists(const QByteArray& filepath); | ||
|
||
/** | ||
* Checks if a path is regarded as relative. | ||
*/ | ||
bool isRelative(const QByteArray& filepath); | ||
|
||
/** | ||
* Checks if a path is an existing directory. | ||
*/ | ||
bool isDir(const QByteArray& filepath); | ||
|
||
/** | ||
* Creates a directory. | ||
*/ | ||
bool mkdir(const QByteArray& filepath); | ||
|
||
|
||
/** | ||
* GDAL-based implementation of Template::tryToFindRelativeTemplateFile(). | ||
* | ||
* Returns an absolute path when the given template path identifies an existing | ||
* file relative to the map path, or an empty value otherwise. | ||
*/ | ||
QByteArray tryToFindRelativeTemplateFile(const QByteArray& template_path, const QByteArray& map_path); | ||
|
||
|
||
} // namespace GdalUtil | ||
|
||
} // namespace OpenOrienteering | ||
|
||
#endif // OPENORIENTEERING_GDAL_FILE_H |
Oops, something went wrong.