Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#6867 closed defect (fixed)

GDAL truncates GeoJSON attributes

Reported by: dr Owned by: warmerdam
Priority: normal Milestone: 2.1.4
Component: default Version: 2.1.3
Severity: normal Keywords: GeoJSON
Cc:

Description

I have GeoJSON file with attribute:

"name": "2016-11-04--11-02-08"

As I know JSON does not specify how dates should be represented, but GDAL treats it as date and truncates end part:

$ ogrinfo -ro http://rykovd.nextgis.com/api/resource/171/geojson OGRGeoJSON
INFO: Open of `http://rykovd.nextgis.com/api/resource/171/geojson'
      using driver `GeoJSON' successful.

Layer name: OGRGeoJSON
Geometry: Multi Line String
Feature Count: 1
Extent: (9316559.435264, 6796713.323408) - (9488008.227544, 7053792.572699)
Layer SRS WKT:
PROJCS["WGS 84 / Pseudo-Mercator",
    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"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["X",EAST],
    AXIS["Y",NORTH],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],
    AUTHORITY["EPSG","3857"]]
src: String (0.0)
cmt: String (0.0)
name: Date (0.0)
link1_href: String (0.0)
number: String (0.0)
link2_text: String (0.0)
link2_href: String (0.0)
link1_type: String (0.0)
link2_type: String (0.0)
type1: String (0.0)
link1_text: String (0.0)
desc: String (0.0)
OGRFeature(OGRGeoJSON):1
  src (String) = (null)
  cmt (String) = (null)
  name (Date) = 2016/11/04
  link1_href (String) = (null)
  number (String) = (null)
  link2_text (String) = (null)
  link2_href (String) = (null)
  link1_type (String) = (null)
  link2_type (String) = (null)
  type1 (String) = (null)
  link1_text (String) = (null)
  desc (String) = (null)

Python example:

$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import ogr
>>> ds = ogr.Open('http://rykovd.nextgis.com/api/resource/171/geojson')
>>> lyr = ds.GetLayer('OGRGeoJSON')
>>> feat = lyr.GetFeature(1)
>>> feat.GetFieldAsString(2)
'2016/11/04'

Change History (7)

comment:1 by Jukka Rahkonen, 7 years ago

What is the desired behavior that you have in your mind?

comment:2 by dr, 7 years ago

I've expected that this attribute will be treated as string without any implicit conversions.

comment:3 by Jukka Rahkonen, 7 years ago

So GDAL should do better job with checking if string is formatted to some of the ISO date/time expressions https://en.wikipedia.org/wiki/ISO_8601? Do you agree that generally it is good to recognize dates?

comment:4 by Even Rouault, 7 years ago

Resolution: fixed
Status: newclosed

In 38075:

OGRParse: fix parsing logic to avoid false positive detection of string as datetime (fixes #6867)

comment:5 by Even Rouault, 7 years ago

In 38076:

OGRParse: fix parsing logic to avoid false positive detection of string as datetime (fixes #6867)

comment:6 by Even Rouault, 7 years ago

In 38077:

OGRParse: fix parsing logic to avoid false positive detection of string as datetime (fixes #6867)

comment:7 by Even Rouault, 7 years ago

Milestone: 2.1.4
Note: See TracTickets for help on using tickets.