qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.4k stars 2.98k forks source link

Support date and datetime data in graduated symbology #58636

Open stragu opened 2 weeks ago

stragu commented 2 weeks ago

Feature description

In QGIS 3.34, using a date or datetime data field in a graduated symbology results in either no symbology at all or 0-to-0 classes, depending on the mode selected.

For example, this small geojson point dataset:

{
"type": "FeatureCollection",
"name": "dated_small",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "fid": 2, "name": "Victor and Evelyn Lewis Fountain", "date": "1969-12-11" }, "geometry": { "type": "Point", "coordinates": [ 153.016106799999989, -27.4989125 ] } },
{ "type": "Feature", "properties": { "fid": 6, "name": null, "date": "1982-06-06" }, "geometry": { "type": "Point", "coordinates": [ 153.0515007, -27.4705868 ] } },
{ "type": "Feature", "properties": { "fid": 7, "name": "Robert Burns Memorial", "date": "1929-08-14" }, "geometry": { "type": "Point", "coordinates": [ 153.0317717, -27.4612333 ] } },
{ "type": "Feature", "properties": { "fid": 9, "name": null, "date": "1993-10-15" }, "geometry": { "type": "Point", "coordinates": [ 153.0155536, -27.4980154 ] } },
{ "type": "Feature", "properties": { "fid": 11, "name": "Harmony Gardens Sound Sculpture", "date": "1988-09-03" }, "geometry": { "type": "Point", "coordinates": [ 153.024725, -27.4962137 ] } },
{ "type": "Feature", "properties": { "fid": 13, "name": "Vietnam Memorial", "date": "1988-04-23" }, "geometry": { "type": "Point", "coordinates": [ 153.0265322, -27.466638 ] } },
{ "type": "Feature", "properties": { "fid": 16, "name": null, "date": "1994-08-26" }, "geometry": { "type": "Point", "coordinates": [ 153.0284766, -27.4478891 ] } },
{ "type": "Feature", "properties": { "fid": 18, "name": "Cannon", "date": "1917-08-18" }, "geometry": { "type": "Point", "coordinates": [ 153.0246091, -27.4723462 ] } },
{ "type": "Feature", "properties": { "fid": 20, "name": "James Warner Memorial", "date": "1996-11-23" }, "geometry": { "type": "Point", "coordinates": [ 153.1689188, -27.4426428 ] } },
{ "type": "Feature", "properties": { "fid": 22, "name": "Thomas Joseph Byrnes Memorial", "date": "1902-08-22" }, "geometry": { "type": "Point", "coordinates": [ 153.032082800000012, -27.4607231 ] } },
{ "type": "Feature", "properties": { "fid": 23, "name": null, "date": "1988-08-27" }, "geometry": { "type": "Point", "coordinates": [ 153.002742399999988, -27.4792554 ] } },
{ "type": "Feature", "properties": { "fid": 25, "name": "2004 Tsunami Memorial", "date": "2005-02-26" }, "geometry": { "type": "Point", "coordinates": [ 153.0170008, -27.4623266 ] } },
{ "type": "Feature", "properties": { "fid": 29, "name": null, "date": "1956-11-10" }, "geometry": { "type": "Point", "coordinates": [ 153.0332913, -27.509545 ] } }
]
}

With a "date" column of type "Date", try using a graduated symbology: Layer - Properties - Symbology - Graduated - Value = date - Method = color - Mode = Equal Interval - Classify - OK.

Actual results: classification only shows zeros. All features coloured with the same end of the gradient.

Expected result: data classified according to the date range and the mode chosen.

Version info:

QGIS version 3.34.10-Prizren QGIS code revision 113de9e1
Qt version 5.15.13
Python version 3.12.5
GDAL/OGR version 3.9.2
PROJ version 9.4.0
EPSG Registry database version v11.004 (2024-02-24)
GEOS version 3.12.2-CAPI-1.18.2
SQLite version 3.45.1
PDAL version 2.6.3
PostgreSQL client version 16.2
SpatiaLite version 5.1.0
QWT version 6.2.0
QScintilla2 version 2.14.1
OS version Windows 11 Version 2009
       

Active Python plugins QuickOSM | 2.2.3 quick_map_services | 0.19.34 db_manager | 0.1.20 grassprovider | 2.12.99 MetaSearch | 0.3.6 processing | 2.12.99

Additional context

No response

roya0045 commented 2 weeks ago

You can use the epoch function as a workaround in the meantime. Or anything to convert them to numbers.

stragu commented 1 week ago

You can use the epoch function as a workaround in the meantime. Or anything to convert them to numbers.

Thank you, that is indeed useful, but does not help for having a meaningful legend. (I don't think the "Legend format" field supports the use of expressions to revert back to dates?)

The fact that these data types are available to be selected in the Graduated symbology makes me think this is a bug rather that a feature request... Has this ever been handled properly in the past?