<div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;">Hi all,</div><div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;">Here an example with the code.<br></div><div>If you compare <span><u>rast_rotated_from_raster</u></span> with <span><u>rast_rotated_from_vector</u></span>, the latest is rotated as expected and the first is not.</div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">I guess, I must be doing something wrong when creating <span><u>rast_rotated_from_raster</u></span>.</div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">Any guess?<br></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><div style="font-family: "Droid Sans Mono", "monospace", monospace; font-weight: normal; line-height: 19px; white-space: pre; color: rgb(204, 204, 204); background-color: rgb(31, 31, 31);"><span><span style="color: rgb(106, 153, 85);">-- non rotated raster</span></span><div><span style="color: rgb(86, 156, 214);">DROP</span><span> </span><span style="color: rgb(86, 156, 214);">TABLE</span><span> </span><span style="color: rgb(86, 156, 214);">IF</span><span> </span><span style="color: rgb(86, 156, 214);">EXISTS</span><span> public.rast_not_rotated;</span></div><div><span style="color: rgb(86, 156, 214);">CREATE</span><span> </span><span style="color: rgb(86, 156, 214);">TABLE</span><span> </span><span style="color: rgb(220, 220, 170);">public</span><span>.rast_not_rotated </span><span style="color: rgb(86, 156, 214);">AS</span></div><div><span> </span><span style="color: rgb(86, 156, 214);">SELECT</span><span> ST_AsRaster(t.geom,</span><span style="color: rgb(181, 206, 168);">1000</span><span>,</span><span style="color: rgb(181, 206, 168);">1000</span><span>,</span><span style="color: rgb(206, 145, 120);">'8BUI'</span><span>,</span><span style="color: rgb(181, 206, 168);">1</span><span>,</span><span style="color: rgb(181, 206, 168);">0</span><span>) </span><span style="color: rgb(86, 156, 214);">AS</span><span> rast </span></div><div><span> </span><span style="color: rgb(86, 156, 214);">FROM</span><span> (</span><span style="color: rgb(86, 156, 214);">SELECT</span><span> ST_GeomFromText(</span><span style="color: rgb(206, 145, 120);">'POLYGON((166989.36462303242 505764.77048559673,</span></div><div><span style="color: rgb(206, 145, 120);"> 166996.25788353998 505576.476318614,</span></div><div><span style="color: rgb(206, 145, 120);"> 167265.54134611748 505585.94966528506,</span></div><div><span style="color: rgb(206, 145, 120);"> 167258.67088940175 505774.2438322678,</span></div><div><span style="color: rgb(206, 145, 120);"> 166989.36462303242 505764.77048559673))'</span><span>,</span><span style="color: rgb(181, 206, 168);">28992</span><span>) geom) t;</span></div><div><span style="color: rgb(86, 156, 214);">ALTER</span><span> </span><span style="color: rgb(86, 156, 214);">TABLE</span><span> public.rast_not_rotated </span><span style="color: rgb(86, 156, 214);">ADD</span><span> COLUMN rid </span><span style="color: rgb(86, 156, 214);">SERIAL</span><span> </span><span style="color: rgb(86, 156, 214);">PRIMARY KEY</span><span>;</span></div><div><span style="color: rgb(86, 156, 214);">CREATE</span><span> </span><span style="color: rgb(86, 156, 214);">INDEX</span><span> </span><span style="color: rgb(220, 220, 170);">rast_not_rotated_rast_gist</span><span> </span><span style="color: rgb(86, 156, 214);">ON</span><span> public.rast_not_rotated </span><span style="color: rgb(86, 156, 214);">USING</span><span> gist (st_convexhull(rast));</span></div><div><span style="color: rgb(86, 156, 214);">SELECT</span><span> AddRasterConstraints(</span><span style="color: rgb(206, 145, 120);">'public'</span><span>::</span><span style="color: rgb(86, 156, 214);">name</span><span>, </span><span style="color: rgb(206, 145, 120);">'rast_not_rotated'</span><span>::</span><span style="color: rgb(86, 156, 214);">name</span><span>,</span><span style="color: rgb(206, 145, 120);">'rast'</span><span>::</span><span style="color: rgb(86, 156, 214);">name</span><span>);</span></div><br><div><span style="color: rgb(106, 153, 85);">-- rotate previous raster</span></div><div><span style="color: rgb(86, 156, 214);">DROP</span><span> </span><span style="color: rgb(86, 156, 214);">TABLE</span><span> </span><span style="color: rgb(86, 156, 214);">IF</span><span> </span><span style="color: rgb(86, 156, 214);">EXISTS</span><span> public.rast_rotated_from_raster;</span></div><div><span style="color: rgb(86, 156, 214);">CREATE</span><span> </span><span style="color: rgb(86, 156, 214);">TABLE</span><span> </span><span style="color: rgb(220, 220, 170);">public</span><span>.rast_rotated_from_raster </span><span style="color: rgb(86, 156, 214);">AS</span><span> </span><span style="color: rgb(86, 156, 214);">SELECT</span><span> ST_SetRotation(rast, </span><span style="color: rgb(212, 212, 212);">-</span><span style="color: rgb(181, 206, 168);">0</span><span>.</span><span style="color: rgb(181, 206, 168);">035162353342492736</span><span>) rast </span><span style="color: rgb(86, 156, 214);">FROM</span><span> public.rast_not_rotated;</span></div><div><span style="color: rgb(86, 156, 214);">ALTER</span><span> </span><span style="color: rgb(86, 156, 214);">TABLE</span><span> public.rast_rotated_from_raster </span><span style="color: rgb(86, 156, 214);">ADD</span><span> COLUMN rid </span><span style="color: rgb(86, 156, 214);">SERIAL</span><span> </span><span style="color: rgb(86, 156, 214);">PRIMARY KEY</span><span>;</span></div><div><span style="color: rgb(86, 156, 214);">CREATE</span><span> </span><span style="color: rgb(86, 156, 214);">INDEX</span><span> </span><span style="color: rgb(220, 220, 170);">rast_rotated_from_raster_rast_gist</span><span> </span><span style="color: rgb(86, 156, 214);">ON</span><span> public.rast_rotated_from_raster </span><span style="color: rgb(86, 156, 214);">USING</span><span> gist (st_convexhull(rast));</span></div><div><span style="color: rgb(86, 156, 214);">SELECT</span><span> AddRasterConstraints(</span><span style="color: rgb(206, 145, 120);">'public'</span><span>::</span><span style="color: rgb(86, 156, 214);">name</span><span>, </span><span style="color: rgb(206, 145, 120);">'rast_rotated_from_raster'</span><span>::</span><span style="color: rgb(86, 156, 214);">name</span><span>,</span><span style="color: rgb(206, 145, 120);">'rast'</span><span>::</span><span style="color: rgb(86, 156, 214);">name</span><span>);</span></div><br><div><span style="color: rgb(106, 153, 85);">-- rotate polygon and then save as raster</span></div><div><span style="color: rgb(86, 156, 214);">DROP</span><span> </span><span style="color: rgb(86, 156, 214);">TABLE</span><span> </span><span style="color: rgb(86, 156, 214);">IF</span><span> </span><span style="color: rgb(86, 156, 214);">EXISTS</span><span> public.rast_rotated_from_vector;</span></div><div><span style="color: rgb(86, 156, 214);">CREATE</span><span> </span><span style="color: rgb(86, 156, 214);">TABLE</span><span> </span><span style="color: rgb(220, 220, 170);">public</span><span>.rast_rotated_from_vector </span><span style="color: rgb(86, 156, 214);">AS</span></div><div><span> </span><span style="color: rgb(86, 156, 214);">SELECT</span><span> ST_AsRaster(t.geom,</span><span style="color: rgb(181, 206, 168);">1000</span><span>,</span><span style="color: rgb(181, 206, 168);">1000</span><span>,</span><span style="color: rgb(206, 145, 120);">'8BUI'</span><span>,</span><span style="color: rgb(181, 206, 168);">1</span><span>,</span><span style="color: rgb(181, 206, 168);">0</span><span>) </span><span style="color: rgb(86, 156, 214);">AS</span><span> rast </span></div><div><span> </span><span style="color: rgb(86, 156, 214);">FROM</span><span> (</span><span style="color: rgb(86, 156, 214);">SELECT</span><span> ST_Rotate(</span></div><div><span> ST_GeomFromText(</span><span style="color: rgb(206, 145, 120);">'POLYGON((166989.36462303242 505764.77048559673,</span></div><div><span style="color: rgb(206, 145, 120);"> 166996.25788353998 505576.476318614,</span></div><div><span style="color: rgb(206, 145, 120);"> 167265.54134611748 505585.94966528506,</span></div><div><span style="color: rgb(206, 145, 120);"> 167258.67088940175 505774.2438322678,</span></div><div><span style="color: rgb(206, 145, 120);"> 166989.36462303242 505764.77048559673))'</span><span>,</span><span style="color: rgb(181, 206, 168);">28992</span><span>)</span></div><div><span> ,</span><span style="color: rgb(212, 212, 212);">-</span><span style="color: rgb(181, 206, 168);">0</span><span>.</span><span style="color: rgb(181, 206, 168);">035162353342492736</span><span>, </span><span style="color: rgb(181, 206, 168);">166989</span><span>.</span><span style="color: rgb(181, 206, 168);">36462303242</span><span>, </span><span style="color: rgb(181, 206, 168);">505764</span><span>.</span><span style="color: rgb(181, 206, 168);">77048559673</span><span>) geom) t;</span></div><div><span style="color: rgb(86, 156, 214);">ALTER</span><span> </span><span style="color: rgb(86, 156, 214);">TABLE</span><span> public.rast_rotated_from_vector </span><span style="color: rgb(86, 156, 214);">ADD</span><span> COLUMN rid </span><span style="color: rgb(86, 156, 214);">SERIAL</span><span> </span><span style="color: rgb(86, 156, 214);">PRIMARY KEY</span><span>;</span></div><div><span style="color: rgb(86, 156, 214);">CREATE</span><span> </span><span style="color: rgb(86, 156, 214);">INDEX</span><span> </span><span style="color: rgb(220, 220, 170);">rast_rotated_from_vector_rast_gist</span><span> </span><span style="color: rgb(86, 156, 214);">ON</span><span> public.rast_rotated_from_vector </span><span style="color: rgb(86, 156, 214);">USING</span><span> gist (st_convexhull(rast));</span></div><div><span style="color: rgb(86, 156, 214);">SELECT</span><span> AddRasterConstraints(</span><span style="color: rgb(206, 145, 120);">'public'</span><span>::</span><span style="color: rgb(86, 156, 214);">name</span><span>, </span><span style="color: rgb(206, 145, 120);">'rast_rotated_from_vector'</span><span>::</span><span style="color: rgb(86, 156, 214);">name</span><span>,</span><span style="color: rgb(206, 145, 120);">'rast'</span><span>::</span><span style="color: rgb(86, 156, 214);">name</span><span>);</span></div></div><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div>
<div class="protonmail_signature_block" style="font-family: Arial, sans-serif; font-size: 14px;">
<div class="protonmail_signature_block-user">
<div><div>Eloi<br></div></div><div><br></div>
</div>
<div class="protonmail_signature_block-proton protonmail_signature_block-empty">
</div>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div class="protonmail_quote">
On Monday, March 18th, 2024 at 19:11, Eloi Ribeiro <mail@eloiribeiro.eu> wrote:<br>
<blockquote class="protonmail_quote" type="cite">
<div style="font-family: Arial, sans-serif; font-size: 14px;"><span>Hi Regina and all,</span><div><br></div><div><span>Elaborating a bit more. I have a vector layer consisting of a rectangle (farm plot), and this rectangle is subdivided into several<span> (<span>polygon</span>s)</span> stripes parallel to the outer edge of the <span>rectangle</span>. I want to produce a raster where the rectangle and stripes long edges are parallel to the latitude line.<br></span></div><div><br></div><div><span>Using ST_Rotate(geom, -0.035, x, y) in all vector layers together with ST_AsRaster(), I managed to get what I want. Good.<br></span></div><div><br></div><span>Nevertheless, if I first produce the raster and then try to rotated it using ST_SetRotation(rast, <span>-0.035</span>), I barely see any rotation. In this step, I must be doing something wrong.<br><span style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><br></span></span></div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">I would like to first rasterize vector and then rotate the raster. Instead of rasterize non rotated vector and then, again rasterize rotated vector.<br></div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"><span><span>The change in size (width and height), I mentioned in my first message, was while testing with 0.5 rad, not with <span>-0.035</span> rad.<br></span></span><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;"><span></span><span></span></div><div style="font-family: "Droid Sans Mono", "monospace", monospace; font-weight: normal; line-height: 19px; white-space: pre; color: rgb(204, 204, 204); background-color: rgb(31, 31, 31);"><span><span style="color: rgb(106, 153, 85);">-- input raster</span></span><div><span style="color: rgb(86, 156, 214);">SELECT</span><span> ST_Width(rast), ST_Height(rast), ST_SkewX(rast) </span><span style="color: rgb(86, 156, 214);">FROM</span><span> plot_3;</span></div><div><span style="color: rgb(106, 153, 85);">-- st_width | st_height | st_skewx </span></div><div><span style="color: rgb(106, 153, 85);">-- ----------+-----------+----------</span></div><div><span style="color: rgb(106, 153, 85);">-- 1000 | 1000 | 0</span></div><br><div><span style="color: rgb(106, 153, 85);">-- output raster of ST_SetRotation(rast, -0.035162353342492736)</span></div><div><span style="color: rgb(86, 156, 214);">SELECT</span><span> ST_Width(rast), ST_Height(rast), ST_SkewX(rast) </span><span style="color: rgb(86, 156, 214);">FROM</span><span> plot_3_rotated_from_raster;</span></div><div><span style="color: rgb(106, 153, 85);">-- st_width | st_height | st_skewx </span></div><div><span style="color: rgb(106, 153, 85);">-- ----------+-----------+----------------------</span></div><div><span style="color: rgb(106, 153, 85);">-- 1000 | 1000 | 0.006952538312005269</span></div><br><div><span style="color: rgb(106, 153, 85);">-- output raster of ST_SetRotation(rast, -0.035162353342492736)</span></div><div><span style="color: rgb(86, 156, 214);">SELECT</span><span> ST_Width(rast), ST_Height(rast), ST_SkewX(rast) </span><span style="color: rgb(86, 156, 214);">FROM</span><span> plot_3_rotated_from_vect;</span></div><div><span style="color: rgb(106, 153, 85);">-- st_width | st_height | st_skewx </span></div><div><span style="color: rgb(106, 153, 85);">-- ----------+-----------+----------</span></div><div><span style="color: rgb(106, 153, 85);">-- 977 | 964 | 0</span></div><br><div><span style="color: rgb(106, 153, 85);">-- output raster of ST_SetRotation(rast, -0.5)</span></div><div><span style="color: rgb(86, 156, 214);">SELECT</span><span> ST_Width(rast), ST_Height(rast), ST_SkewX(rast) </span><span style="color: rgb(86, 156, 214);">FROM</span><span> plot_3_rotated_from_raster_05;</span></div><div><span style="color: rgb(106, 153, 85);">-- st_width | st_height | st_skewx </span></div><div><span style="color: rgb(106, 153, 85);">-- ----------+-----------+---------------------</span></div><div><span style="color: rgb(106, 153, 85);">-- 1000 | 1000 | 0.09481479675190897</span></div></div><br><div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px;">Cheers,<br><br></div>
<div style="font-family: Arial, sans-serif; font-size: 14px;" class="protonmail_signature_block">
<div class="protonmail_signature_block-user">
<div><div>Eloi<br></div></div><div><br></div>
</div>
<div class="protonmail_signature_block-proton protonmail_signature_block-empty">
</div>
</div>
<div style="font-family: Arial, sans-serif; font-size: 14px;"><br></div><div class="protonmail_quote">
On Monday, March 18th, 2024 at 14:01, Regina Obe <lr@pcorp.us> wrote:<br>
<blockquote type="cite" class="protonmail_quote">
<div class="WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt">By size, what do you mean exactly? It would change the width and height.</span></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt">What are you expecting rotation to do. Perhaps you can give example out of the below and some sample</span></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt">ST_Width, ST_Height, ST_SkewX before and after and what you were expecting.</span></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt"><a target="_blank" rel="noreferrer nofollow noopener" href="https://postgis.net/docs/en/RT_ST_SetRotation.html">https://postgis.net/docs/en/RT_ST_SetRotation.html</a></span></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Eloi Ribeiro <mail@eloiribeiro.eu> <br><b>Sent:</b> Monday, March 18, 2024 4:57 AM<br><b>To:</b> PostGIS Users Discussion <postgis-users@lists.osgeo.org><br><b>Subject:</b> How to properly rotate a raster</span></p></div></div><p class="MsoNormal"> </p><div><p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">Hi all,</span></p></div><div><p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif"> </span></p></div><div><p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">I need to rotate a raster, for that I'm using the function </span><code><b><span style="font-size:10.0pt">ST_SetRotation</span></b></code><code><span style="font-size:10.0pt">, like so:</span></code><span style="font-size:10.5pt;font-family:"Arial",sans-serif"> </span></p><div><p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:"Courier New";color:#6A9955">CREATE TABLE plot_3_rotated AS <br>SELECT ST_SetRotation(rast, 0.03516235334249185) rast <br>FROM plot_3;</span><span style="font-size:10.5pt;font-family:"Courier New";color:#CCCCCC"></span></p></div><p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif"> </span></p></div><div><p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">But I see that is not producing the expected results and is changing size of the raster. What am I doing wrong?<br><br>Cheers,</span></p></div><div><p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif"> </span></p></div><div><div><div><div><p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">Eloi</span></p></div></div><div><p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif"> </span></p></div></div></div></div></div>
</blockquote><br>
</div>
</blockquote><br>
</div>