I'm trying to rotate a box around its southwest corner using PostGIS. However, I am not getting the expected results when doing the rotation. I'm using SRID 3785.

The image below shows what distortion I'm talking about.


Basically, the original is a square, but the same polygon rotated 90 degrees is distorted. Rotated by 180 is back to normal, and rotate by 270 is distorted the same way.

They should all be squares. What's going on?

  • Can you share the SQL statement you called ST_rotate with? – L_Holcombe Dec 2 '12 at 7:08
  • It is something along the lines of SELECT ST_Rotate(ST_MakeBox2D(<p1>, <p2>), <rads>, <p1>) where p1, p2, and rads are some variables. – zsalzbank Dec 2 '12 at 7:14

Looks like this is a Mercator problem. Although your bounding box looks like a square, the lengths of the sides are actually unequal. In the spherical Mercator projection, which is cylindrical, scale is maintained longitudinally, but increases latitudinally. For example, at 30 degrees latitude, a degree of latitude is nearly 69 miles, while a degree of longitude is only like 60 miles. So the height of your square is actually less than the width. When your square is rotated 90deg, the former width is now the height, and it has to be stretched to maintain distance. And the former height is now the width, and it has to be contracted to maintain distance. Rotating again to 180deg stretches and contracts in reverse, returning to the original shape.

If you want the dimensions of the rotated box to be predictable, I suggest working in an equidistant projection, like 3786, and then switching back to 3785 later.

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.