Skip to content

Instantly share code, notes, and snippets.

@springmeyer
Created October 27, 2011 20:54
Show Gist options
  • Save springmeyer/1320838 to your computer and use it in GitHub Desktop.
Save springmeyer/1320838 to your computer and use it in GitHub Desktop.
ogrinfo detecting geojson
$ ogrinfo --version
GDAL 1.8.1, released 2011/07/09
# create a normal json file with an ext
$ echo '{ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, "properties": {"prop0": "value0"} } ]}' > file.json
# this works as expected
$ ogrinfo file.json
ERROR 4: GeoJSON Driver doesn't support update.
Had to open data source read-only.
INFO: Open of `file.json'
using driver `GeoJSON' successful.
1: OGRGeoJSON (Point)
# create a json file with no extension
$ echo '{ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, "properties": {"prop0": "value0"} } ]}' > filejson
$ head -n 1 filejson
{ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, "properties": {"prop0": "value0"} } ]}
# this does not work
# this http://trac.osgeo.org/gdal/browser/trunk/gdal/ogr/ogrsf_frmts/geojson/ogrgeojsonutils.cpp#L39 must not be being called for some reason so '{' is not detected
$ ogrinfo filejson
FAILURE:
Unable to open datasource `filejson' with the following drivers.
-> ESRI Shapefile
-> MapInfo File
-> UK .NTF
-> SDTS
-> TIGER
-> S57
-> DGN
-> VRT
-> REC
-> Memory
-> BNA
-> CSV
-> NAS
-> GML
-> GPX
-> LIBKML
-> KML
-> GeoJSON
-> Interlis 1
-> Interlis 2
-> GMT
-> SQLite
-> DODS
-> ODBC
-> PGeo
-> MSSQLSpatial
-> OGDI
-> PostgreSQL
-> MySQL
-> PCIDSK
-> XPlane
-> AVCBin
-> AVCE00
-> DXF
-> Geoconcept
-> GeoRSS
-> GPSTrackMaker
-> VFK
-> PGDump
-> GPSBabel
-> SUA
-> OpenAir
-> PDS
-> WFS
-> HTF
-> AeronavFAA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment