# Simplify a circle into square with SF

I want to obtain a square from a circle using simplification function in sf.

This is my circle:

With this code, I obtain a rhombus

`plot(st_simplify(st_geometry(sfdf),dTolerance = 1000))`

How can I obtain a square? in QGIS I manage to obtain it using SnapToGrid option in simplification process.

• I doubt you'll ever get a square output with an ellipse input. – Vince Aug 23 '18 at 13:36
• Would an envelope/minimum bounding rectangle do for you? – user30184 Aug 23 '18 at 14:42
• sure, a rectangle is a good option too – andriatz Aug 24 '18 at 7:45
• If you have a centre point and a radius that defines your circle then getting the four points of an axis-aligned internal square, is basic trigonometry. Do you have radius and centre coordinate for these circles or just the spatial data object (which is only actually an approximation to a circle)? – Spacedman Aug 24 '18 at 13:23

`st_simplify` function uses a maximum distance difference algorithm similar to the one used in the Douglas-Peucker algorithm and this algorithm preserves the first point of the shape. Therefore, to obtain a square from a circle using simplification function, the first point of the circle has to be located in direction 45, 135, 225 or 315 degree. In your circle, I guess, direction must be 0, 90, 180 or 270 degree.
• `st_simplify` is an R function... – Calum You Aug 29 '18 at 21:32