2

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

This is my circle:

enter image description here

With this code, I obtain a rhombus

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

enter image description here

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

  • 2
    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
4

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.

Circles below were simplified in the same way, but results are different because of location of the first point.

enter image description here enter image description here

  • How could do it in R? – andriatz Aug 24 '18 at 7:45
  • st_simplify is an R function... – Calum You Aug 29 '18 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.