1

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?

5
  • Normally when we talk about cells we mean raster, and to a lesser extent grid cells. Are you trying to limit your roads (and/or other vector features) to only those that intersect your layers? As for speed, your feature type (KML, Esri shp, TAB etc) and coordinate system can have a big impact. What format are your vectors in? Does their spatial reference match the project? – Michael Stimson Jun 23 '15 at 3:15
  • I'm sorry, I'm quite new to all this, but I'll try to answer you questions as best as I can. The projects coordinate system is WGS84/Pseudo mercator, EPSG:3857. The vector grid is outputted as polygons in a shapefile, and the x and y in the parameters seem to be in meters. What I'm trying to do is delete all the cells in the vector grid layer that do not overlap with lines from one of my other layers. The layers containing the linestrings constituting my map are imported from postgis and are in the following CRS: EPSG:32633-WGS 84/UTM zone 33N. The grid is in EPSG:32633-WGS 84/UTM zone 33N. – simonra Jun 23 '15 at 3:31
  • Best practice is to work entirely within the same spatial reference, and if you can't then match the raster dataset with your project. This post should help you gis.stackexchange.com/questions/61753/… – Michael Stimson Jun 23 '15 at 3:43
  • The select by location did the inverse of what I actually wanted to do, but I figured out how to make a new layer based on the selection, and because I could use that layer as the basis for the atlas it solved my problem. I will try to keep in mind that the reference systems should be kept consistent when I get to setting up a project by myself =) – simonra Jun 23 '15 at 4:06
  • That's it, or 'switch selection' to remove. The reason for getting everything the same is that QGIS projects on the fly, which is a lot of maths to do every time you refresh the screen, so by making everything the same spatial reference the thinking has all been done already which makes refresh and print much faster. – Michael Stimson Jun 23 '15 at 4:21
0

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.

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.