In my previous article, I showed how you can convert point coordinates into a polygon vector layer in QGIS. So how about GRASS GIS? Like in my previous post, let’s assume you have a text file with two columns with the coordinates. With the v.in.ascii function you can import this text file as a point layer. Next, you can use v.hull or v.delaunay to create polygon layers.
With a little bit more work, you can convert the above mentioned text file into a ASCII vector file. A vector map in GRASS native vector format is a simple text file which may contain a mix of primitives including points, lines, boundaries, centroids, areas, faces, and kernels. The text file may contain also a header with various metadata. Below I will show you the minimum input needed to create a polygon map with one polygon. For more options, you can consult the help file.
In GRASS GIS, a polygon vector consists of a boundary and a centroid. The example above defines the boundary as the line through the four points and a centroid within the boundary.
A) The header contains meta-data information and is optional. See the help file about what meta-data you can include in the header
B) This is the first line of the body and is obligatory
C) The letter indicates the type of ‘primitive’ (type of vector). The ‘B’ stands for ‘boundary’. This is followed by the number of elements (points).
D) The coordinates of the four boundary points
E) To close the boundary, you need to repeat the coordinates of the first point
F) The letter indicates the type of ‘primitive’ (type of vector). The ‘C’ stands for ‘centroid’. Here, we have one centroid in layer one.
G) The coordinates of the centroid. I used the average of the coordinates of the four boundary points.
H) This defines the category of the centroid (category 1 in layer 1).
Note that you can also create the boundary only, and use the v.centroids function to add the missing centroid later. This might be a better option if you are working with highly irregular shaped polygons and you want to be sure the centroid lies within the boundaries.
In the next tab, you need to tell GRASS that you are using a ASCII vector map as input (Input file format = standard). Last step, click ‘Run’ to create the polygon layer.
Your vector layer does not contain an attribute table yet. If you need one, you can add one using the v.db.addtable command. In the example below, I am adding a table with a column ‘Description’. I then fill this column using db.execute.
v.db.addtable map=OutputFile v.db.addcolumn map=OutputFile layer=1 columns='Description VARCHAR' echo "update OutputFile set Citation='Test'" | db.execute input=-
Although these steps are easy enough, I wanted to make it a bit easier. I therefore created a small spreadsheet template. It will take the coordinates of your boundary points and generate the GRASS GIS code to create a polygon vector layer and export this to a kml file.
I just created this as a quick aid for myself and it only lets you create one polygon (that is all I needed it for). But it is easy enough to adapt it, e.g., if you want to create one vector layer with multiple polygons. Or even better, write a small script.