[GIS] Drawing grid cells in QGIS

asciiqgisvector-grid

I have one ASCII text file with eight columns. The first four provide the x-coordinates (e.g. longitude) of the four corners of a grid cell, while the last four provide the y-coordinates (e.g. latitude) of the four corners of the same cell in the same order. Furthermore, the fourth x-coordinate of line k is equal to the first x-coordinate of line k + 1, and the third x-coordinate of line k is equal to the second x-coordinate of line k + 1; similarly for the y-coordinates. This means that the cells described in lines k and k + 1 are adjacent having two corners in common. In this context, the number of lines in the file is the number of grid cells.

Is there a way to draw in QGIS the grid cells described in this way?

Best Answer

If the coordinates describe a regular grid, it might be easier to extract the bounds and cell size and create the grid without going through the trouble of parsing the text file.

If the grid is irregular, one of the easier approaches - requiring no programming skills - would be to open the text file in Calc/Excel and use string concatenation to construct well-known text (WKT) representations of polygons (the cells). Here's an example WKT:

POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))

Of course, the same can be done using a scripting language of your choice.