3

I am trying to expand a polygon in a particular manner with PostGIS. I need a new geometry that is a bit like a Buffer, except Buffer produces rounded corners (lots of vertices) when using it on a square and I need a new square whose sides are N meters away from the inner/original square (and still have only 4 vertices).

My first approach was to use a Buffer and then Simplify, but that is not producing the desired result.

I checked ST_Expand but this returns a BBOX, so it does not work either when the square is not perfectly N-S/E-W oriented nor will it work on irregular polygons.

I also looked into ST_Scale, but this uses a multiplying factor which I don't know how to find out based on a metric distance.

Another function I've looked into is ST_Affine to see if I can scale and translate in one go, but I got no clue how to find out the values I should use in this function.

I have searched and found out nothing. Has anyone done this with PostGIS? then, how?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Marc Compte
  • 233
  • 2
  • 13
  • 4
    Have you looked into "endcap=square" and "join=mitre mitre_limit=1"? http://www.postgis.net/docs/ST_Buffer.html – Fjellrev Jan 11 '19 at 11:49
  • 1
    related (but not duplicate) https://gis.stackexchange.com/questions/277306/creating-square-buffer-in-qgis – Ian Turton Jan 11 '19 at 11:51

1 Answers1

3

Use join=mitre mitre_limit=b where b = buffer distance (and possibly endcap=square)

Mitre joins Square endcaps

ST_Buffer

    SELECT ST_Buffer(
      ST_GeomFromText(
        'LINESTRING(5 5,15 15,15 5)'
           ), 1, 'endcap=square join=mitre mitre_limit=1');
Fjellrev
  • 495
  • 2
  • 17
  • 1
    Actually I had to use a mitre_limit equal to the buffered distance, otherwise in my square test I still got a polygon with more than 4 vertices. – Marc Compte Jan 11 '19 at 12:55