1

Once a month I get a zip file of 300+ shapefiles made up of lines of individual ship's tracks, and a list of a sub-set of those tracks that I am interested in for analysis and display in QGIS.

I want to develop an efficient workflow that lets me select/isolate the subset without going through the folder and manually importing the subset of tracks.

All shapefiles have the same attribute table layout. The filenames are by ship name. Each ship has a unique name field and a numeric unique ID field called an 'MMSI'.

So far my incomplete/unsuccessful ideas include:

  1. Use the "Package Layers" to collect all the tracks into a single geopackage and use the DB Manager to create a query using my list
  2. Use the "Package Layers" to collect all the tracks into a single geopackage, import all the tracks into QGIS, and create a virtual layer using my list
  3. Somehow query the original folder of shapefiles

I suspect that both options 1 & 2 would work, but my expression/query/SQL skills are a work in progress. The drawback to options 1 and 3 is that I like to view all the data in QGIS to see if there are any strange things/outliers.

ship tracks

5
  • Re 1 and 2, they are almost the same thing - Virtual Layer is just an extension of DB Manager in the sense that you can use DB Manager to output a virtual layer. Are you able to expand a bit more on the list showing the sub-set? Is this a sub-set of shapefiles (e.g. shapefiles A, B, C), or does it specify a sub-set within each shapefile (e.g. all shapefiles, but only tracks after a certain date)? Or is it both?
    – she_weeds
    Jul 8, 2022 at 2:34
  • It is a subset of shapefiles, one file for each ship. I can't figure out the expression to query/select a set of shapefiles (or geopackages in the case of "Package Layers"); most examples select attributes within a layer.
    – CDEdwards
    Jul 8, 2022 at 15:09
  • I dont understand. Select a subset by which criterias? Like ship name x and MMSI y? And then you want to add the shapefiles which meet these criterias to the map in QGIS?
    – BERA
    Jul 8, 2022 at 17:11
  • Select by file name, in each file there is ship name or MMSI#. They are all unique identifiers. For Example, I have a folder of shapefiles or geopackages called A to Z, and I want to import or display the files named D, E, F, and Q.
    – CDEdwards
    Jul 8, 2022 at 17:17
  • I start with a zip folder of shapefiles named A to Z (actually named by ship name and there is 300+ of them) and where I go from there is the workflow question. The geopackage can be whatever I make as part of the workflow, but I am trying to not have to go through the folder of shapefiles and one by one import the handful of files I am interested in.
    – CDEdwards
    Jul 8, 2022 at 17:28

1 Answer 1

2

The following steps should be what you need:

  1. Extract zip file to have all shapefiles in a folder

  2. Use "Merge Vector Layers" processing algorithm the following way:

    1. For input layers select "Add File(s)..."
    2. Go to your folder with the shapefile
    3. Search for ".shp" files
    4. Select all of them
    5. click "Ok" to validate input layers
    6. Optional: select a destination crs if your shapefiles have different crs otherwise they will be reprojected with first shapefile's crs
    7. run the algorithm
  3. Filter your layer:

    1. Right-click on the memory layer created by "Merge Vector Layers" called "Merged"
    2. Click "Filter..."
    3. use an expression on the field containing the relevant id you want to filter with something like : "field_id" in (id1, id2, id3) (if your ids are numeric, use ('id1', 'id2', 'id3') otherwise)
1
  • I rescind (and deleted) my previous comment...this is a nice way to do it. I like that it uses simple tools that are built into the front-end interface of QGIS. I like that the layers get merged on their way into QGIS so I don't waste a bunch of time importing and exporting them. And if I merge the layers into a geopackage, the render and processing is lightyears faster.
    – CDEdwards
    Jul 8, 2022 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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