# Calculating polygon length and width using open source GIS?

FWIW, in Postgis is a function since 1.5, ST_Longestline that returns the longestline between two geometries. If you feed that function with the same geometry twice instead of two different, you will get the longest line in that geometry. http://postgis.net/docs/ST_LongestLine.html

@Whuber. you write above that the longest line doesn't have to start and end in the polygons vertexes. You use the letter I as example. I don't get it. If I is represented by a Line with two vertexes, then that line has to be the longest line itself, right?

If the I letter is represented by a thin polygon, the longestline will be a diagonal line from say left upper vertex to right lower vertex.

But I cannot understand how there could be a longest line that doesn't end and start in polygon vertexes.

Do I miss understand something?

/Nicklas

Ok, Whuber, I misunderstood you, I read your answer once more. I was talking about what you call the diameter and you were talking about something else. Sorry

/Nicklas

JTS provides a Minimum Bounding Circle (http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/algorithm/MinimumBoundingCircle.html) and a Minimum Diameter (http://tsusiatsoftware.net/jts/javadoc/index.html) - once you have those the rectangle should be easy to calculate.