Polygon to Lines Conversion
Firstly let's start to convert polygon to polyline. To convert polygon to polyline we use QGIS polygontolines processing command. To run this command we just need an input file in polygon geometry and an output path to save the output file. The listing code below shows how to do it. Figure 1a shows a polygon before conversion, and figure 1b shows the result after conversion.
|Figure 1. Polygon to lines conversion. (a) Polygon before conversion. (b) Lines after conversion|
Convert Lines to PointsTo convert line to point, the processing command from SAGA which is called convertlinestopoints is used. This command takes two parameters LINES and POINTS. LINES is input line to be converted and POINTS is output point. Figure 2 shows the result of line to point conversion. It can be seen that points will be created at each line's vertex.
|Figure 2. Line to Point conversion output|
Point to Line ConversionFor point to line conversion the QGIS pointstopath command can be used to do this operation. As usual it needs input point and also output path to keep the result. Another mandatory parameter is ORDER_FIELD. This parameter will be used in the algorithm to define routing point. It means if a set of points that formed a curve line, but the order is not sequence, will produce an incorrect result. One more parameter that can be added is GROUP_FIELD. This parameter will grouped or segmented the output line based on a field value. In figure 3c can be seen the line output that grouped by two values in a field. In that figure can be seen that the two separate lines was created based on field value and they won't connecting to each other.
The following code was used to produce the result as in figure 3a. The next one is command that used GROUP_FIELD and produced result as in 3c.
|Figure 3. (a) Original point dataset. (b) Converted to single line. (c) Converted to two line segments|
That's all the tutorial how to do geometry conversion such as converting polygon to lines, lines to point and point to lines. To learn more about QGIS Python programming. Visit QGIS Python Programming Series that offer other interesting topics.