Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a postgis table containing polygons. I want to transform my polygons to 4 points polygons : retrieve the smallest MBR.

Here comes an illustration of what I want :

alt text

My original polygon is in pink color. I guess, it will be quite easy to get the MBR (with ST_Envelope and BBox function) But is there an easy way to get what I want?

Any ideas? Many thanks

share|improve this question

3 Answers 3

A complete answer can be found here however in summary:

  • [S] rotate the polygon to match one of its edges with X axis
  • compute minmax of X and Y for vertices
  • this gives you a candidate for minimum area rectangle (MAR) or MBR
  • store the area of (x2-x1)*(y2-y1)
  • repeat from [S] for all edges
  • find the minimum area which corresponds to MBR
  • rotate found [[x1,y1],[x2,y2]] by -angle applied in [S]

Done.

share|improve this answer

For that simple example you have there, the ST_ConvexHull would give you that answer. For the more complex case, haven't thought much about it, but my guess is that you can

1) Take the ST_ConvexHull - http://www.postgis.org/documentation/manual-1.5SVN/ST_ConvexHull.html

If you are using PostGIS 1.5+ 2) Then get the ST_LongestLine of the convexhull ST_LongestLine(ST_ConvexHull(geom), ST_ConvexHull(geom)) That will give you two corners of the rectangle (though there is another part -- I'm missing) since those two corners may not be the diagonal) http://www.postgis.org/documentation/manual-1.5SVN/ST_LongestLine.html

You may also want to take a look at the code for ST_MinimumBoundingCircle -- its currently just implemented as a plpgsql function -- but what you are doing I think is a simplification of that.

http://www.postgis.org/documentation/manual-1.5SVN/ST_MinimumBoundingCircle.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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