Opened 8 months ago

Last modified 3 weeks ago

#36626 assigned New feature

Support sub-second resolution in GDAL Features' datetime fields

Reported by: Tilman Koschnick Owned by: Francesco Bruni
Component: GIS Version: dev
Severity: Normal Keywords: microsecond
Cc: Tilman Koschnick Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi,

I have a GPX DataSource with points that have sub-second resolution:

<trkpt lat="47.454540000" lon="8.573658000">
  <ele>436.900</ele>
  <time>2025-09-25T12:24:42.990Z</time>
</trkpt>

The GDAL API returns these only with second resolution, although the underlying datetime presentation is still accessible with the as_string() method:

>>> point
<django.contrib.gis.gdal.feature.Feature object at 0x7f99254b9190>
>>> point.get('time')
datetime.datetime(2025, 9, 25, 12, 24, 42)
>>> point['time']
<django.contrib.gis.gdal.field.OFTDateTime object at 0x7f99253212b0>
>>> point['time'].as_datetime()
(c_int(2025), c_int(9), c_int(25), c_int(12), c_int(24), c_int(42), c_int(100))
>>> point['time'].as_string()
'2025/09/25 12:24:42.990+00'

In my case, I lose information, and end up being at different locations at the same time ;)

Would it be possible to support sub-second resolutions in the GDAL API? As I understand it, OGR_F_GetFieldAsDateTime() is used to return the datetime object:

https://gdal.org/en/stable/doxygen/ogr__api_8h.html#a47ca681bb6099eb8c18004d1f7112d95

GDAL also provides OGR_F_GetFieldAsDateTimeEx() that returns seconds as float with millisecond accuracy:

https://gdal.org/en/stable/doxygen/ogr__api_8h.html#a748995fa28574b25f6b723013a405a8f

I unfortunately don't understand the GDAL API enough to provide a patch myself.

Regards, Til

Change History (6)

comment:1 by Jacob Walls, 8 months ago

Keywords: microsecond added
Resolution: wontfix
Status: newclosed

Hi Til,

Thanks for this suggestion. When suggesting a new feature for Django, the feature idea should first be proposed and discussed with the community. To do that, please raise this on the new feature tracker.

I'll close the ticket for now, but if the community agrees with the proposal, please return to this ticket and reference the forum discussion so we can re-open it. For more information, please refer to the documented guidelines for requesting features.


There's probably a backwards compatibility piece here also, as it sounds like the proposal is to make as_datetime() return something other than tuple[int, int, int, int, int, int] (where the penultimate int is the second). So if you can put some thought to that when writing your new features issue, that would be appreciated.

comment:2 by Tilman Koschnick, 8 months ago

Hi Jacob,

thanks for the pointers, I've created a feature request now: https://github.com/django/new-features/issues/82

comment:3 by Jacob Walls, 2 months ago

Resolution: wontfix
Status: closednew
Triage Stage: UnreviewedAccepted

Accepting from positive forum discussion and discussion about backward compatibility. Happy to look at a PR!

comment:4 by Francesco Bruni, 3 weeks ago

Owner: set to Francesco Bruni
Status: newassigned

comment:5 by Francesco Bruni, 3 weeks ago

Assigning this ticket as part of the Sprint developments in PyconUs 26 in LB.

comment:6 by Francesco Bruni, 3 weeks ago

Has patch: set
Note: See TracTickets for help on using tickets.
Back to Top