[gdal-dev] Call for discussion on RFC 67 : Null values in OGR
Even Rouault
even.rouault at spatialys.com
Thu Jan 26 03:24:49 PST 2017
Ari,
> In the RFC you write that for JSON OGR currently returns unset fields
> when a field does not exist and when it is null. However, in a simple
> test I wrote this JSON
>
> { "type": "FeatureCollection", "features": [ { "foo" : "bar" }, { "foo"
>
> : null }, { } ] }
The above is valid JSON but invalid GeoJSON. There's some logic to deal with attributes that
wouldn't be properly declared as GeoJSON properties, but it takes a different code path and
is less advanced regarding null detection.
If I fix it with :
{ "type": "FeatureCollection", "features": [
{ "type": "Feature", "properties" : { "foo" : "bar" } },
{ "type": "Feature", "properties" : { "foo" : null } },
{ "type": "Feature", "properties" : { } } ] }
I get the current expected behaviour :
$ ogrinfo test.json -al
INFO: Open of `test.json'
using driver `GeoJSON' successful.
Layer name: test
Geometry: Unknown (any)
Feature Count: 3
Layer SRS WKT:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
foo: String (0.0)
OGRFeature(test):0
foo (String) = bar
OGRFeature(test):1
foo (String) = (null)
OGRFeature(test):2
foo (String) = (null)
The case of the ogrinfo output is interesting. Currently we report unset as (null). I guess that
with RFC 67 we should rather report
OGRFeature(test):0
foo (String) = bar
OGRFeature(test):1
foo (String) = (null)
OGRFeature(test):2
That is not report the foo field in the last field. Or report foo (String ) = (unset) ?
> For PostgreSQL tables NULL is mapped to unset.
>
> It would be logical if null field would map to null in JSON and NULL in
> SQL
That's my plan.
> but maybe that's not possible in a backwards compatible way.
Yes, there will be some backward compatibility as raised in the RFC. Basically to get the
current behaviour when reading a OGR datasource you will need to test both for unset and
null.
--
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170126/5e6d68a7/attachment.html>
More information about the gdal-dev
mailing list