Add ability to detect geojson files without an extension
|Reported by:||springmeyer||Owned by:||warmerdam|
Description (last modified by )
GeoJSON is becoming a very common format for data apis. And therefore it is common for applications to grab it remotely. OGR nicely supports reading geojson (and detecting it as geojson) from a string via url or locally.
But in some cases an application may wish to first download the data locally, cache it, and then pass that data to ogr. In the common case that the url does not end in a well know geojson extension, simply saving the file without an extension and passing the filename to ogr fails.
This failure to detect as geojson a file like 'jsonwithoutextension' is understandable. You would have to open it to see if there is json inside and because OGR already has a ton of other checks for different file types if each driver did this you would likely see quite slow initialization of OGR datasources. So, feel free to reject this patch outright if this seems like to much to ask of OGR.
But, from my limited view, it would be nice if ogr would handle this kind of detection better for GeoJSON because it seems like a potentially common situation. Instead of requiring the calling application to open the file and detect if it is geojson just to give it a filename extension, ogr could do this in one pass (from the perspective of the calling application).
The attached patch is a first stab at that. I'm totally unfamiliar with CPL usage and coding styles (eg. I free the
char* but should the
CPLString also be freed?), so please have mercy.