# QGIS calculate radius of an arc to attributes

I have QGIS 2.18.16 installed. My problem is, how to calculate radius of an arc / curve feature (line)? The lines are originated from .dgn file, which I read with FME and wrote to PostGis DB. I have created primary keys etc, and the table is fully editable. I calculated lengths for the arcs successfully, but cant figure out how to calculate radius for these curves. This ( https://www.mathopenref.com/arcradius.html ) might give some idea on the math side, though I can't figure out how to use it in QGIS calculator. So I need to calculate the "R" for all the lines i have in the DB.

Bellow is an example. My data has Arcs / Curves on different table than "normal" polylines. • When I click on an arc with the Identify tool, one of the derived attributes listed is the "closest vertex radius." So there's no need to calculate the radius, you only need to figure out how to access this property in the field calculator. Or simply copy it from the identify tool. – csk Feb 8 '18 at 18:26
• You can also view the properties of a vertex when a layer is in edit mode by selecting vertices with the Node Tool. Then the vertex coordinates (x,y,r) display in the Vertex Editor panel. – csk Feb 8 '18 at 18:30
• Nice to know it is at least possible to see the radius via identify tool. With only few arcs copy-paste would be an option, but I plan to use this to the whole data I have, which has too many arc features to be done manually. :/ – Sisuaski Feb 9 '18 at 8:01
• I googled around a bit, and it seems like not many people use circular string features in QGIS, so there's not a ready-made tool or function in the field calculator. You may need to define a custom Python function. If you want to go that route, add the pygis tag to your question. – csk Feb 9 '18 at 17:31
• How many vertexs do you have for feature? What do you see in the Vertex Editor when you click the Node Tool? – Marco Feb 12 '18 at 12:01

## 2 Answers

Lightly tested formulas follow, so proceed with caution. But following along with an example here: https://www.mathopenref.com/arcradius.html If your circular arcs have a vertex at the middle point along the arc (which I am saying is x1, y1 in the figure), you could use it along with the start and end points to calculate the chord length "W" and the height "h" to get the radius "R" using the following formula:

and saying W =

sqrt(
( $x_at(-1) -$x_at(0) )^2 +
( $y_at(-1) -$y_at(0) )^2
)


and H =

sqrt(
( $x_at(1) - ($x_at(-1) + $x_at(0) )/2 )^2 + ($y_at(1) - ( $y_at(-1) +$y_at(0) )/2 )^2
)


in your Expression Dialog of the Field Calculator you'd have this long equation for the radius calculation: R =

sqrt(
( $x_at(1) - ($x_at(-1) + $x_at(0) )/2 )^2 + ($y_at(1) - ($y_at(-1) +$y_at(0))/2 )^2
) /2
+
(   ( $x_at(-1) -$x_at(0) )^2 )  +
( $y_at(-1) -$y_at(0) )^2 )  )
/ ( 8 * sqrt(
( ($x_at(1) - ($x_at(-1) + $x_at(0) )/2 )^2 + ($y_at(1) - ($y_at(-1) +$y_at(0) )/2 )^2
)
)

• In LaTe X $$W= \sqrt {(x_{-1} - x_0)^2 +(y_{-1}-y_0)^2}$$ $$H = \sqrt { (x_1- \frac {(x_{-1}+x_0)} 2 )^2 + (y_1- \frac {(y_{-1}+y_0)} 2 )^2}$$ and $$R = \frac {\sqrt { (x_1- \frac {(x_{-1}+x_0)} 2 )^2 + (y_1- \frac {(y_{-1}+y_0)} 2 )^2}} {2} + \frac {(x_{-1} - x_0)^2 +(y_{-1}-y_0)^2} {8 \sqrt { (x_1- \frac {(x_{-1}+x_0)} 2 )^2 + (y_1- \frac {(y_{-1}+y_0)} 2 )^2}}$$ – Marco Feb 17 '18 at 16:22
• Very good! I did not imagine how to access the vertexes. Is it possible in PostGIS? – Marco Feb 17 '18 at 16:26
• Marco, I believe it is possible to extract whatever vertice you are looking for. See the link here: postgis.net/docs/ST_PointN.html. Thank you for the most-excellent formula additions and edits. – cm1 Feb 18 '18 at 20:17
• While waiting for developers to add a button to "easy calculate radius", this is most helpful answer I could hope for. Now I (and possibly others too) have at least some way to extract radius. :) I have not yet tested this, but I will in a few days when I have enough time. Thank you a lot for your help! – Sisuaski Feb 19 '18 at 13:25

What about extracting the radius while extracting the data with FME? There you have the ArcPropertyExtractor transformer, which should give you the radius values in attributes ready to set in your PostGIS DB

• That would be one possible way to proceed, a good way to handle the whole data. My problem is, there is not enough FME users in my organization and I need to make the process as easy as possible. That means, the whole process, including arcs, areas, lines etc., should be able to be done with Qgis. Ability to update Arc feature radius to new objects is what I need to be done with Qgis. Thank you for your reply though, I'll be updating radius attributes with FME for now, but hope there will be a way to do it with QGIS. – Sisuaski Feb 12 '18 at 10:00