How to properly rotate a raster
Eloi Ribeiro
mail at eloiribeiro.eu
Mon Mar 18 11:11:06 PDT 2024
Hi Regina and all,
Elaborating a bit more. I have a vector layer consisting of a rectangle (farm plot), and this rectangle is subdivided into several (polygons) stripes parallel to the outer edge of the rectangle. I want to produce a raster where the rectangle and stripes long edges are parallel to the latitude line.
Using ST_Rotate(geom, -0.035, x, y) in all vector layers together with ST_AsRaster(), I managed to get what I want. Good.
Nevertheless, if I first produce the raster and then try to rotated it using ST_SetRotation(rast, -0.035), I barely see any rotation. In this step, I must be doing something wrong.
I would like to first rasterize vector and then rotate the raster. Instead of rasterize non rotated vector and then, again rasterize rotated vector.
The change in size (width and height), I mentioned in my first message, was while testing with 0.5 rad, not with -0.035 rad.
-- input raster
SELECT ST_Width(rast), ST_Height(rast), ST_SkewX(rast) FROM plot_3;
-- st_width | st_height | st_skewx
-- ----------+-----------+----------
-- 1000 | 1000 | 0
-- output raster of ST_SetRotation(rast, -0.035162353342492736)
SELECT ST_Width(rast), ST_Height(rast), ST_SkewX(rast) FROM plot_3_rotated_from_raster;
-- st_width | st_height | st_skewx
-- ----------+-----------+----------------------
-- 1000 | 1000 | 0.006952538312005269
-- output raster of ST_SetRotation(rast, -0.035162353342492736)
SELECT ST_Width(rast), ST_Height(rast), ST_SkewX(rast) FROM plot_3_rotated_from_vect;
-- st_width | st_height | st_skewx
-- ----------+-----------+----------
-- 977 | 964 | 0
-- output raster of ST_SetRotation(rast, -0.5)
SELECT ST_Width(rast), ST_Height(rast), ST_SkewX(rast) FROM plot_3_rotated_from_raster_05;
-- st_width | st_height | st_skewx
-- ----------+-----------+---------------------
-- 1000 | 1000 | 0.09481479675190897
Cheers,
Eloi
On Monday, March 18th, 2024 at 14:01, Regina Obe <lr at pcorp.us> wrote:
> By size, what do you mean exactly? It would change the width and height.
>
> What are you expecting rotation to do. Perhaps you can give example out of the below and some sample
>
> ST_Width, ST_Height, ST_SkewX before and after and what you were expecting.
>
> https://postgis.net/docs/en/RT_ST_SetRotation.html
>
> From: Eloi Ribeiro <mail at eloiribeiro.eu>
> Sent: Monday, March 18, 2024 4:57 AM
> To: PostGIS Users Discussion <postgis-users at lists.osgeo.org>
> Subject: How to properly rotate a raster
>
> Hi all,
>
> I need to rotate a raster, for that I'm using the function ST_SetRotation, like so:
>
> CREATE TABLE plot_3_rotated AS
> SELECT ST_SetRotation(rast, 0.03516235334249185) rast
> FROM plot_3;
>
> But I see that is not producing the expected results and is changing size of the raster. What am I doing wrong?
>
> Cheers,
>
> Eloi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20240318/d575aeea/attachment.htm>
More information about the postgis-users
mailing list