-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unwanted removal of ISO8601 datetime string timezone information when reading from GeoJSON #914
Comments
Currently, Fiona supports RFC3339 and is not aware of timezones (= Ignoring potential timezone information from GDAL). Read support could probably be implemented quite easily, writing datetimes with timezones could potential be more tricky. GDAL' s documentation regarding timezone information is as follows:
|
Thanks for the response @rbuffat . I'm not too familiar with configuring GDAL. Would there be a way of disabling the parsing and just treating datetimes as regular strings? |
For the GeoJSON driver, you can use the DATE_AS_STRING or OGR_GEOJSON_DATE_AS_STRING option:
In this case, the date fields are treated as string:
|
The datetime is created and formatted here: Lines 242 to 251 in e46abf2
So I think it should indeed relatively straightforward to calculate a GMT offset from the For the original example (
So
gets back the correct string representation |
The situation is a bit complicated, as setting the pnTZFlag gives a different result depending on the driver: OSGeo/gdal#2696 The timezone flag pnTZFlag of OGR_F_SetFieldDateTimeEx can either be 0=unknown or having one of the following values 100=GMT, 101=GMT+15minute, 99=GMT-15minute and so on. The problem is, that not all drivers understand timezones. E.g. MapInfo File does not support timezones, GPKG driver until GDAL 3.1 supported only the GMT timezone (respectively all datetime are in GMT before GDAL 3.1 (0 = unknown is not supported)). Also setting the pnTZFlag to an unsupported mode does typically not result in an error. I think we should apply the following logic:
Implementing this logic should not be that hard. However, as far as I know, it is not possible to know what a driver supports without testing it. The difficult part is to create tests that cover all cases. Some drivers convert datetime silently to string, which then can have arbitrary formatting, makes it even more messy to create tests. Also, timezone support seems to be a bit lacking in Python without external libraries such as pytz. E.g. datetime.timezone was introduced with Python 3.2. |
Bringing this over from
geopandas
. It seems like reading an ISO8601 datetime string from aGeoJSON
erases the timezone information at some point.geopandas/geopandas#1472
Expected behavior and actual behavior.
Expected to read in timezone aware ISO8601 datetime strings in a
GeoJSON
as strings. Got string that has been stripped of timezone information.I.E. in the
GeoJSON
, we have2010-10-20T12:00:00+07:00
but when read in usingFiona
, got2010-10-20T12:00:00
.Operating system
Mac OS X 10.15.5.
Fiona and GDAL version and provenance
Fiona: 1.8.13.post1 installed via Pypi
GDAL: 2.4.4 installed via Homebrew
The text was updated successfully, but these errors were encountered: