Scenario
I have a .csv file containing (amongst others) some date fields, and a matching .csvt file defining the correct field data types. The only way I have been able to add my .csv data and have QGIS recognise the correct date field is by using:
"Manage Layers Toolbar> Add Vector Layer"
Manage Layers Toolbar > Add Vector Layer
Which gives me this dialog:
After selecting my .csv file and clicking open, the layer appears in the layers panel like so:
All the fields are the correct data types and all the data is present, however nothing displays in the map canvas. I figure QGIS does not know these data are geometry points and so treats the layer as a data table.
How can I get QGIS to render this layer as points on the map canvas?
(Note that adding the .csv file using "Manage Layers Toolbar> Add Delimited Text Layer", which does render correctly, is not an option unless there is a way to make this approach recognise the date fields correctly.)
-
1This might help gist.github.com/rbanick/1e96d77a3f5b8d575945 but only if VRT points recognizes the date data.. Dates can be fairly difficult to import from text.Michael Stimson– Michael Stimson2017年11月13日 02:04:48 +00:00Commented Nov 13, 2017 at 2:04
-
Maybe related: gis.stackexchange.com/questions/32352/…AndreJ– AndreJ2017年11月13日 06:53:45 +00:00Commented Nov 13, 2017 at 6:53
-
What kind of problems do you have with the data fields? (when using "Add Delimited Text Layer")AndreasK– AndreasK2017年11月13日 09:13:39 +00:00Commented Nov 13, 2017 at 9:13
-
The date fields come in as strings using "Add Delimited Text Layer", and queries don't work properly on them. Keiko has a good response below but I was hoping there was a way to add a CSV layer that would get everything correct in the process.Sangster– Sangster2018年11月16日 06:35:52 +00:00Commented Nov 16, 2018 at 6:35
1 Answer 1
Why are you not using this tool ?
enter image description here
By this way, you can choose your format, and specify a geometry column (X;Y) :
Then, you can use an update function using a "to_date" conversion.
If you need, you can use the string functions to formate correctly.
For example :
Column containing your dates (Type = bigint) : dates_int (ex : 20171113)
Destination column (Type = date) : dates
[dates =]
to_date(
left(to_string("dates_int"),4) || '-' ||
right(left(to_string("dates_int"),6),2) || '-' ||
right(to_string("dates_int" ),2))
-
Thanks for your response Keiko. Using
Add Delimited Text Layer
(as you suggested) was my first approach but it results in date fields importing as string types, regardless of the CSVT file. Using `Add Vector Layer' with a valid CSVT file results in the date fields importing correctly but no option to specify the coordinate fields, so the features do not display on the map canvas. The suggestion to use an update function is helpful but is there a way to specify the coordinate fields in a data layer so that QGIS will recognise it as containing geometry and render it to the map canvas?Sangster– Sangster2018年11月16日 06:29:17 +00:00Commented Nov 16, 2018 at 6:29