1

I'm trying to filter some data of a shapefile (with "Filter") for QGIS to show points in a date interval of a shapefile. I have a shapefile which has a table of attributes of sightings of animals with time and date and other attributes relevant for me. I'm now trying to create shape files of each month, I do a query using the "Filter" and I can't seem to do it. I used to be able to do it; don't know if something changed or if I'm doing it the wrong way! Something really basic but it is puzzling me and I couldn't find any way that worked in here.

  • What is the format of the date attribute? You could create a new field which contains only the month (via some expression depending on how the date is stored) and then run the Split vector layer tool. – Joseph Nov 16 '18 at 14:51
  • Using dd/mm/yyyy – João Nuno Gonçalves Nov 16 '18 at 15:00
  • The shapefile is a series of points (sightings) from 6 months worth of data. All I'm trying to do is just to filter the shapefile in order to show me on the map to publish the month that I need to data to be shown... – João Nuno Gonçalves Nov 16 '18 at 15:02
  • For say March 2018, why couldnt you do: Select * from Table where Date < 4/1/2018 AND Date >= 3/1/2018 – ed.hank Nov 16 '18 at 15:03
  • 1
    You could use the month() function in the field calculator to populate a new field with the month values, which would make it easier for filtering. – FSimardGIS Nov 16 '18 at 15:06
1

QGIS and the shapefile format both use 'yyyy-mm-dd' as date object string format, so I'm pretty sure you are working with plain strings. You'd need to confirm, though.

Assuming that, you could use to_int(substr("Date", 4, 2)) to extract the month as integer.
From here, you could either filter the shapefile data on that (or create a new field or whatever), i.e.:

to_int(substr("Date", 4, 2)) = 11

or, and I would possibly go that way, create a categorized symbology with to_int(substr("Date", 4, 2)) as Column expression. You can then selectively switch the month in question on and off via Symbology (in the Layers panel, even) and create a map composer export for each...provided that is what you had in mind.

In either way, don't pollute your disk with a bunch of unnecessary extra files; I would almost always recommend to implement sorting/grouping/categorizing logic as part of the data itself, not via file system (chaos).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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