[Gdal-dev] File extensions
Matt Hanson
mhanson at photon.com
Thu Dec 7 13:19:41 EST 2006
Ray - thanks for the insight, it makes sense and now I understand why
ENVI treats files the way it does (you always deal with the binary file,
which can have any extension or none, then it looks for the hdr file
rather then the other way around)
Frank - Thanks for the heads up on the Metadataitem for the extension.
Didn't even think about the possibility of it existing in the driver.
Makes sense.
The tricky think about my app is that I really don't know the format
when I create it. The user provides the output format, but not the
filename! The reason is that in this app there may not be a single
output file. Output files are created as intermediate files during
processing and thus the filename is generated randomly, with no explicit
knowledge of what the format is (though if it doesn't support Create an
error is generated of course). I'm actually using the boost filesystem
libraries which provide filename parsing functions....getting the
preferred extension from the driver sounds like the perfect solution.
> -----Original Message-----
> From: Frank Warmerdam [mailto:warmerdam at pobox.com]
> Ray has convered some of the general dangers of dependence on
> extensions.
>
> But I think you can still address this at the application
> level if you want to. In order you create files you already
> need to know what format driver you want to use so that you
> can pass that into CreateCopy or Create. Given the driver,
> you can also fetch it's preferred extension from the driver metadata.
>
> Then you could, for instance, add the extension to the user
> provided name if the user provided name has no extension. Or
> possibly even override if they gave a different once, though
> for most formats the extension is just a suggestion, not a
> requirement.
>
> Note that many formats don't even have a preferred extension.
> But if they do the following call should fetch it (NULL if none):
>
> const char *pszExtension =
> GDALGetMetadataItem( hDriver, GDAL_DMD_EXTENSION, NULL );
>
> You may find functions like CPLGetExtension(), and
> CPLResetExtension() in gdal/port/cpl_conv.h helpful for
> parsing and modifying filenames in a portable fashion.
>
> I'm not keen on having drivers actually change extensions
> internally, though if it is sufficiently critical a driver
> could chose to do so.
More information about the Gdal-dev
mailing list