Opened 13 years ago

Closed 13 years ago

#4082 closed defect (fixed)

GeoJSON driver detects type on first feature

Reported by: barryrowlingson Owned by: Even Rouault
Priority: normal Milestone: 1.8.1
Component: OGR_SF Version: 1.8.0
Severity: normal Keywords: geojson
Cc:

Description

Numbers in OGR can be Integer or Real. If the numeric property of the first feature in a GeoJSON file looks like an Integer, then OGR treats that property as Integer, and numerically truncates any Real values in further features.

Example snippet of two features:

 { "type": "Feature", "properties": { "z1": 4, "z2": 2.100000 } [...]
 { "type": "Feature", "properties": { "z1": 3.2, "z2": 3.100000 } [...]

like that, ogrinfo reports

z1: Integer (0.0)
z2: Real (0.0)

and then drops .2 from 3.2 in the second feature:

OGRFeature(OGRGeoJSON):1
  z1 (Integer) = 3
  z2 (Real) = 3.1
  POINT (2 2)

Changing the first feature to:

{ "type": "Feature", "properties": { "z1": 4.0, "z2": 2.100000 }

(ie adding the ".0" to the "4") causes both fields to be Real.

The JSON spec only has 'number' class, and no differential between integers and reals, so maybe anything numeric should be an OGR Real.

[This was spotted in some GeoJSON generated by Geoserver]

Change History (3)

comment:1 by Even Rouault, 13 years ago

Owner: changed from warmerdam to Even Rouault

comment:2 by Even Rouault, 13 years ago

r22357 /trunk/gdal/ogr/ogrsf_frmts/geojson/ogrgeojsonreader.cpp: GeoJSON: better detection of OGR type for numeric JSON fields ( #4082 )

Will backport in 1.8 branch later

comment:3 by Even Rouault, 13 years ago

Keywords: geojson added
Milestone: 1.8.1
Resolution: fixed
Status: newclosed

r22358 /branches/1.8/gdal/ogr/ogrsf_frmts/geojson/ogrgeojsonreader.cpp: GeoJSON: better detection of OGR type for numeric JSON fields (#4082)

Note: See TracTickets for help on using tickets.