[GIS] How to remove vector grid cells that don’t overlap with features from a certain layer in QGIS

atlasqgisvector-grid

I am working on displaying a road network with QGIS (2.4). Doing this I have a couple of layers, including a base network of roads, and my modified layer. All in all they become a huge network. Therefore when exporting the map, I decided to use the atlas function in QGIS. The approach is to make a vector grid bound by my road map, and each cell in the grid of a reasonable size for the desired level of detail.

All in all this process works well, except for that my map is rather irregular and doesn't really fill the vector grid area. To prevent a lot of empty and useless pages in the generated atlas, I started deleting empty cells. This process was significantly improved when I figured out that I could select the cells by rectangle instead of one by one, but is still extremely tedious because of the amount of cells and map detail that has to be examined.

My question is therefore if there exists a way to (more easily) delete all cells in the vector layer that do not bound or intersect features from my main layer?

Best Answer

I managed to solve the problem thanks to the comments provided by Michael! To make a vector grid for generating an atlas in QGIS that only has cells that contain features from the layer you want the atlas to detail, these steps can be followed:

  • Make a vector grid that that covers the entire layer you want atlased
    • Go to Vector → Research tools → Vector grid
    • In the resulting dialog select the layer in the first drop down box (in "Grid extent"), and press the "Update extents from layer" button.
    • In the parameters section enter more reasonable values than the default, in my case the units appeared to be meters, so i used 30 in both to get the desired level of detail.
    • Select the "Output grid as polygons" radio toggle, select/create an appropriate .shp file in the "Output shapefile box", check the "Add results to canvas" box, and wait for the grid to be generated once you hit Ok (this might take a while and possibly crash QGIS if you did as me initially and try to create a grid whit a resolution of 0.0001 meters in a project the size of a couple of square kilometers).
      • To make the generated grid not obscure everything in your main window it might be an idea to change its style form "Simple fill" to "Simple line".
  • Once the grid has been created, select the tiles that contain features from the layer of interest:
    • Go to Vector → Research tools → Select by location
    • In the "Select features in" box select the vector grid layer.
    • In the "that intersect features in" box select the layer with the features.
    • In the "Modify current selection by" box select "creating new selection", and hit Ok.
  • Now that the relevant grid cells have been selected, make a new grid layer that only contains those cells:
    • Right click the grid-layer in the Layers panel, and select "Save as".
    • In the dialog that appears select/create a .shp file for the output, and check the boxes "Save only selected features" and "Add saved file to map".

At this point you should have a new vector grid layer that only has cells which contain/overlap features from the layer you want to create an atlas of. All that remains is to dispose of the intermediary vector grid layer that was created, change the style of the new vector grid layer to something you like, and use it for generating your atlas.

Related Question