1

I have a question regarding ogr2ogr's auto-conversion of text fields to date fields, specifically in the case of additional text following the date.

input.geojson file:

   {
      "type": "FeatureCollection",
      "name": "abc",
      "features": [
        {
          "type": "Feature",
          "properties": {
            "Notes": "2022/05/12 blah blah blah"
          },
          "geometry": {
            "type": "Point",
            "coordinates": [
              -76,
              39
            ]
          }
        }
      ]
    }

After running: ogr2ogr output.geojson input.geojson, I get the warning:

Warning 1: The output driver does not natively support Date type for field Notes. Misconversion can happen. -mapFieldType can be used to control field type conversion.

When I run the above again but with the options -mapFieldType Date=String or -mapFieldType All=String, the warning disappears. However, in all three cases, my output.geojson file reads:

{
  "type": "FeatureCollection",
  "name": "abc",
  "features": [
    {
      "type": "Feature",
      "properties": { "Notes": "2022/05/12" },
      "geometry": { "type": "Point", "coordinates": [-76.0, 39.0] }
    }
  ]
}

As you can see, the Notes property is stripped of its text, leaving only the date.

Is there is not an option in ogr2ogr to preserve the content of Notes, what are the rules that govern ogr2ogr's auto-conversion of types so that I can better understand this behavior?

1

1 Answer 1

1

You found a bug in the GDAL GeoJSON driver that did not check if the field had content after a string that looks like date/time/datetime.

The bug is fixed by https://github.com/OSGeo/gdal/pull/6357

The CI test suite is also updated and now the strings which are tested are these:

{ "type": "Feature", "properties": { "dt": "2014-11-20 12:34:56+0100", "dt2": "2014\\/11\\/20", "date":"2014\\/11\\/20", "time":"12:34:56", "no_dt": "2014-11-20 12:34:56+0100", "no_dt2": "2014-11-20 12:34:56+0100", "no_date": "2022/05/12 blah" }, "geometry": null },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.