Creating and Orienting Vector Grids in QGIS 2.18
In this QGIS tutorial I will use a real-life geophysical survey to detail how I use QGIS to create polygon grids, how I orientate them to fit the area of interest and how I export the grid as points to use with a GPS or Total Station system.
In archaeology, laying out a grid before a survey or excavation is an essential part of keeping a fieldwork project organised. Grids can be aligned to real-world coordinates, such the British National Grid here in the UK, or can be on an arbitrary alignment, called a site grid, chosen to best fit the terrain or landscape. A site grid will commonly use a field boundary, verge, fence line or other linear feature as a baseline from which to measure out the grid.
Gridding out, as it’s called, can be done quickly in the field by one or two people using surveyor’s tapes. I’m fortunate to have access to a GPS Rover which can achieve the same result as using hand tapes, but much more quickly and with millimetre accuracy. The other benefit of using a GPS is that the grid can be created in QGIS in the office and transferred precisely onto the field.
QGIS Tutorial Contents
- Creating the grid
- Orienting the grid
- Converting polygons to points
- Exporting point layers
- How does this workflow compare with ArcGIS?
Creating the grid1
- Either search for grid in the Processing Toolbox, or navigate to Vector grid under QGIS geoalgorithms > Vector creation tools.
- Define the extent of the grid by clicking the three dots to the right of the input field and choosing Select extent on canvas. You’ll be taken back to your map where you can select a rectangular area by left clicking and dragging.
- X spacing and Y spacing defines the size of your grid squares in map units.
- Set the Grid type to polygons or lines as you prefer.
- Leave the Grid field as [Create temporary layer]. You can save this layer as a shape file once we have it aligned correctly, but it’s not necessary.
- Click Run.
You’ll now have a temporary layer containing your newly created grid. I would normally change the polygon fill to transparent, thicken the outline to make it more visible and also choose a contrasting colour so that it stands out better from the background.
Orienting the grid
- With the Select Features tool, drag a polygon marquee over the new grid to select all.
- If your selection is displayed as solid yellow, go to Project > Project properties (Ctrl+Shift+P) and under the General tab change the Selection color to transparent2.
- The next step uses the Rotate Feature (Advanced Digitizing Tools) and Move Feature tools to reposition the grid along a baseline, typically a field boundary or hedge line. With the Rotate Feature tool, left click the selected grid once to activate the rotate tool and then free rotate the grid to align it with your area of interest, left clicking once more to deactivate the rotate tool. With the Move Feature tool, left click and drag the grid to reposition it more precisely. Redo these steps until you are satisfied with the result.
- All that’s left to do now is delete any unwanted grid squares that fall outside of the area of interest. With the Select Features by Freehand tool, in an editing session, simply Ctrl + left click each unwanted grid square and then hit delete.
- Save your edits and end the editing session.
- Right click the grid layer and select Save as and choose ESRI Shapefile as the Format.
If you aren’t using a GPS system to stakeout the grid and are using tapes instead, then you are done. All that remains is to measure to a location on the grid, e.g., to a grid corner, or to the edge of the grid adjacent to the map feature you used as your baseline, and use these measurements to locate the edge of the grid in the field.
If you are using a GPS system, then you need to convert the polygon grid to a point grid and export this point layer to a format that the GPS controller can understand. In this example, I will be using the CSV format, or Comma Separated Value.
Converting polygons to points
I’ve found two ways to create points from polygon features, one way sounds easy, but isn’t, the other sounds time consuming but can be much quicker.
The first way is to use the Vector > Geometry Tools > Extract nodes3. The dialogue for this tool asks which polygon layer is to be used and the type of layer in which the points are to be created. Clicking run immediately adds a new layer with points at each grid intersection. Brilliant! But for some reason, and I have no idea why, it creates multiple points for each intersection that need to be manually selected and deleted. This turns what should be a simple job into one that can consume quite a lot of time.
The second method is to create a new point shape layer and manually add a point at each grid intersection. This usually turns out to the quickest method, but can become quite laborious on larger grids.
Exporting point layers
Whichever of the two above methods you used, the end result is the same. Right click the new point layer and choose Save As. In the dialogue that opens, under Format, choose Comma Separated Value [CSV], choose a file name and then hit Save.
If you ran the Extract nodes tool, you’ll find that when you view the CSV file in Excel, there are extra columns called xmin, xmax, ymin and ymax. These can be deleted. The coordinates in the X and Y columns are in the coordinate system of your map.
How does this workflow compare with ArcGIS?
This is an easy win for QGIS. Often, ArcGIS can perform tasks with built in tools that QGIS requires third-party plugins to achieve. In this case, ArcGIS (I’m using 10.3) requires a third-party plugin (ET GeoWizards) to create a grid, as I’ve found no way to perform this task with built-in tools alone. The only way I can see to do this in ArcGIS is to draw a single polygon and use copy/paste to build up the grid. This is the kind of repetitive task that computers are supposed to free us from!
QGIS exports points more efficiently than ArcGIS too, as it includes coordinates for each point by default. While exporting points in ArcGIS is not difficult, you must first create X and Y columns in the layer’s attribute table, then use the Calculate Geometry tool to extract the coordinates for each point.
- gis.stackexchange.com – http://gis.stackexchange.com/questions/123444/how-to-create-a-fishnet-grid-shapefile-in-qgis/123446#123446. ↩
- gis.stackexchange.com – http://gis.stackexchange.com/questions/11964/when-im-in-editing-mode-in-qgis-how-do-i-make-the-selection-color-transparent/11965#11965. ↩
- gis.stackexchange.com – http://gis.stackexchange.com/questions/130208/convert-polygon-to-point-with-qgis/130211#130211. ↩