0
votes

I am trying to create a polygon around a centroid by projecting the 4 points 2 meter each. But the polygon sides are not 4 meter. I am seeing only 3.7 meter and 2.8 meter.

SELECT ST_AsText(ST_MakeValid(ST_MakeEnvelope(
    ST_X(ST_Project(ST_SetSRID(ST_MakePoint(-94.308946032318019, 41.189416186516212), 4326), 2,  radians(225))::geometry),
    ST_Y(ST_Project(ST_SetSRID(ST_MakePoint(-94.308946032318019, 41.189416186516212), 4326), 2,  radians(225))::geometry),
    ST_X(ST_Project(ST_SetSRID(ST_MakePoint(-94.308946032318019, 41.189416186516212), 4326), 2,  radians(135))::geometry),
    ST_Y(ST_Project(ST_SetSRID(ST_MakePoint(-94.308946032318019, 41.189416186516212), 4326), 2,  radians(315))::geometry),
    4326
)));

The diagonal is also not coming as 4m. It is 4.7m. QGIS

1

1 Answers

0
votes

The distance of 4m is not the side of the box but its diagonal.

If you want the box side to be 4m, you would have to project the point centroid with angles of 0, 90, 180 or 270 degrees.

edit following measurement comment : The diagonal is indeed 4m long. You can measure it in Postgis (using 45degrees for the project leads to the same point that you create using 2 different angles)

SELECT st_distance(
         ST_Project(ST_SetSRID(ST_MakePoint(-94.308946032318019, 41.189416186516212), 4326), 2,  radians(225))::geography,
         ST_Project(ST_SetSRID(ST_MakePoint(-94.308946032318019, 41.189416186516212), 4326), 2,  radians(45))::geography);
 st_distance
-------------
           4

In QGIS, you need to define and use the ellipsoidal distance, else a degree of longitude is consider to be of the same length as a degree of latitude, which is wrong.

enter image description here