Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#6517 closed defect (fixed)

GeoJSON: improper type detection (String) when first value of a field is null

Reported by: Even Rouault Owned by: Even Rouault
Priority: normal Milestone: 2.1.1
Component: OGR_SF Version: unspecified
Severity: normal Keywords: geojson null
Cc:

Description

Reported as https://lists.osgeo.org/pipermail/gdal-dev/2016-May/044435.html

At the moment the geojson reader automatically converts an attribute where
the first feature is null to string. Is it possible to check values also
from the next features and based on that to set the type of the column?

For example for the following geojson the type of int_prop2 and dbl_prop1
will be string:

{
    "features": [
        {
            "geometry": {
                "coordinates": [ 1.0, 0.0 ],
                "type": "Point"
            },
            "properties": {
                "name": "point2",
                "int_prop1": 2,
                "int_prop2": null,
                "dbl_prop1": 2.1,
                "dbl_prop2": null
            },
            "type": "Feature"
        },
        {
            "geometry": {
                "coordinates": [ 0.0, 0.0 ],
                "type": "Point"
            },
            "properties": {
                "name": "point1",
                "int_prop1": 1,
                "int_prop2": 1,
                "dbl_prop1": 1.1,
                "dbl_prop2": 1.1
            },
            "type": "Feature"
        }
    ],
    "type": "FeatureCollection"
}

Result in the console when using ogrinfo with gdal version 2.1.0, released
2016/04/25: 

name: String (0.0)
int_prop1: Integer (0.0)
int_prop2: String (0.0)
dbl_prop1: Real (0.0)
dbl_prop2: String (0.0)
OGRFeature(OGRGeoJSON):0
  name (String) = point2
  int_prop1 (Integer) = 2
  int_prop2 (String) = (null)
  dbl_prop1 (Real) = 2.1
  dbl_prop2 (String) = (null)
  POINT (1 0)

OGRFeature(OGRGeoJSON):1
  name (String) = point1
  int_prop1 (Integer) = 1
  int_prop2 (String) = 1
  dbl_prop1 (Real) = 1.1
  dbl_prop2 (String) = 1.1000
  POINT (0 0)

Change History (2)

comment:1 by Even Rouault, 8 years ago

Milestone: 2.1.1
Resolution: fixed
Status: newclosed

Fixed in trunk (r34245) and branches/2.1 (r34246) "GeoJSON: fix field type detection when first value of a field is null (#6517)"

comment:2 by Even Rouault, 8 years ago

trunk r34247, branches/2.1 r34248 "GeoJSON: fix previous commit by explicitly including <set> (ref #6517)"

Note: See TracTickets for help on using tickets.