<div dir="ltr">I think the problem here is that the code treats a raster with no SRS differently than a raster with SRS where reprojection will NOT take place (essentially, same Cartesian plane for source raster and destination raster).<div><br></div><div>The key offending(?) line is <a href="https://github.com/postgis/postgis/blob/svn-trunk/raster/rt_core/rt_warp.c#L273">https://github.com/postgis/postgis/blob/svn-trunk/raster/rt_core/rt_warp.c#L273</a></div><div><br></div><div>I'll see if removing that line breaks any existing behavior per unit tests. If no issues, your use case should just-work. I'll probably be able to back-patch this into prior releases (2.1+) as not much has happened in the GDAL Warp wrapper for a few years.</div><div><br></div><div>-bborie</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 12, 2018 at 7:47 AM Birkett, Scott <<a href="mailto:scott.birkett@pioneer.com">scott.birkett@pioneer.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_9047468459191413243WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">The comment that an unset SRID forcing a transformation to happen makes sense.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">You stated that the following would fail because
</span><span style="font-size:11.0pt;color:#1f497d">GDALCreateGenImgProjTransformer2
</span><span style="font-size:11.0pt;color:black">would just return null, and null can’t be transformed into a raster.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">So the following fails, we have seen that.<u></u><u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt">SELECT <u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt"> ST_Resample(<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt"> ST_SetSRID(<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt">'0100000200000000000000F03F000000000000F0BF00000000000000000000000000000000000000000000000000000000000000000000000002000200080000000000000000000000000000000000000000080000000001000000010000000100000001000000'::raster,<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt"> 4326),<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt"> 2, 2)<u></u><u></u></span></b></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">But the following still returns the same
<i><span style="color:red">error</span></i>, when a height and width change is requested.<u></u><u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt">SELECT <u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt"> ST_Resample(<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt"> ST_SetSRID(<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt">'0100000200000000000000F03F000000000000F0BF00000000000000000000000000000000000000000000000000000000000000000000000002000200080000000000000000000000000000000000000000080000000001000000010000000100000001000000'::raster,<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt"> 4326),<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt"> 4, 4)<u></u><u></u></span></b></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">While this works<u></u><u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt">SELECT <u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt"> ST_Resample(<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt">'0100000200000000000000F03F000000000000F0BF00000000000000000000000000000000000000000000000000000000000000000000000002000200080000000000000000000000000000000000000000080000000001000000010000000100000001000000'::raster,<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt"> 4, 4)<u></u><u></u></span></b></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Should a resample that changes the height and width still create an error?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thanks for your help so far.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="color:black">From: </span></b><span style="color:black">postgis-users <<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a>> on behalf of Regina Obe <<a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a>><br>
<b>Reply-To: </b>PostGIS Users Discussion <<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>><br>
<b>Date: </b>Monday, June 11, 2018 at 4:33 PM<br>
<b>To: </b>'PostGIS Users Discussion' <<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>><br>
<b>Cc: </b>"Gruca, Justin" <<a href="mailto:justin.gruca@pioneer.com" target="_blank">justin.gruca@pioneer.com</a>>, "Conrad, Gabe" <<a href="mailto:gabe.conrad@pioneer.com" target="_blank">gabe.conrad@pioneer.com</a>><br>
<b>Subject: </b>[EXTERNAL] Re: [postgis-users] ST_Resample function question.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">That error happens when gdal GDALCreateGenImgProjTransformer2 returns a NULL transform which I'm guessing happens if that data is already at that sampling.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">I know other conditions for that are if GDAL can't load the proj library or GDAL_DATA path is not set.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">Your data already has a width of 2,2 so I assume that if its already at the desired sampling it may return NULL.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">For example:</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">SELECT ST_Resample(ST_ASRaster(</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> 'SRID=4326;POLYGON((0 0,2 0,2 -2,0 -2,0 0))'::geometry, 2, 2),2,2);</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">Yields the error you describe:</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Source Code Pro";color:#333333;background:white">ERROR: rt_raster_gdal_warp: Could not create GDAL transformation object for output dataset creation</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Source Code Pro";color:#333333;background:white"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Source Code Pro";color:#333333;background:white">But if my original dimensions were width / height 4/4 and I request 2/2, then this works</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">SELECT ST_Resample(ST_ASRaster(</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> 'SRID=4326;POLYGON((0 0,2 0,2 -2,0 -2,0 0))'::geometry, 4, 4),2,2);</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">But that doesn't explain why this doesn't work:</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">SELECT ST_Resample(ST_ASRaster(</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> 'SRID=4326;POLYGON((0 0,2 0,2 -2,0 -2,0 0))'::geometry, 4, 4),2,2);</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">As far as why it works when you have no SRID, the raster code uses a hard-coded geotransform matrix when it's an unknown raster so it always gets a geotransform back it can use to apply.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">Hope that helps,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d">Regina</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1f497d"> </span><u></u><u></u></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">From:</span></b><span style="font-size:11.0pt"> postgis-users [mailto:<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a>]
<b>On Behalf Of </b>Birkett, Scott<br>
<b>Sent:</b> Monday, June 11, 2018 4:27 PM<br>
<b>To:</b> <a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<b>Cc:</b> Gruca, Justin <<a href="mailto:justin.gruca@pioneer.com" target="_blank">justin.gruca@pioneer.com</a>>; Conrad, Gabe <<a href="mailto:gabe.conrad@pioneer.com" target="_blank">gabe.conrad@pioneer.com</a>><br>
<b>Subject:</b> [postgis-users] ST_Resample function question.</span><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">"PostgreSQL 9.5.10 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit POSTGIS="2.2.5 r15298" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016"
GDAL="GDAL 2.0.3, released 2016/07/01" LIBXML="2.9.1" LIBJSON="0 (...)"</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black">The raster created by …</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black">SELECT '0100000200000000000000F03F000000000000F0BF00000000000000000000000000000000000000000000000000000000000000000000000002000200080000000000000000000000000000000000000000080000000001000000010000000100000001000000'::raster,
is a two band raster with zeros in the first band and ones in the second band.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black">The following Resample works.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black">//////////////////////////////////////////</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><b><span style="color:black">SELECT ST_Resample('0100000200000000000000F03F000000000000F0BF00000000000000000000000000000000000000000000000000000000000000000000000002000200080000000000000000000000000000000000000000080000000001000000010000000100000001000000'::raster,
2, 2)</span></b><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">//////////////////////////////////////////////</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">The following ST_SetSRID works</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">//////////////////////////////////////////////</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;color:black">SELECT ST_SetSRID('0100000200000000000000F03F000000000000F0BF00000000000000000000000000000000000000000000000000000000000000000000000002000200080000000000000000000000000000000000000000080000000001000000010000000100000001000000'::raster::geometry
,4326);</span></b><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">//////////////////////////////////////////////</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black">The following Resample does not work.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black">//////////////////////////////////////////</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><b><span style="color:black">SELECT ST_Resample(ST_SetSRID('0100000200000000000000F03F000000000000F0BF00000000000000000000000000000000000000000000000000000000000000000000000002000200080000000000000000000000000000000000000000080000000001000000010000000100000001000000'::raster,
4326), 2, 2)</span></b><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">//////////////////////////////////////////////</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">Error Follows</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Monaco;color:black">ERROR: rt_raster_gdal_warp: Could not create GDAL transformation object for output dataset creation</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Monaco;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Monaco;color:black">********** Error **********</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Monaco;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Monaco;color:black">ERROR: rt_raster_gdal_warp: Could not create GDAL transformation object for output dataset creation</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Monaco;color:black">SQL state: XX000</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">Raster in the first band follows…</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">SELECT ST_AsText(geom), * FROM ST_PixelAsCentroids(ST_SetSRID('0100000200000000000000F03F000000000000F0BF00000000000000000000000000000000000000000000000000000000000000000000000002000200080000000000000000000000000000000000000000080000000001000000010000000100000001000000'::raster,
4326), 1);</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">"POINT(0.5 -0.5)";"0101000020E6100000000000000000E03F000000000000E0BF";0;1;1</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">"POINT(1.5 -0.5)";"0101000020E6100000000000000000F83F000000000000E0BF";0;2;1</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">"POINT(0.5 -1.5)";"0101000020E6100000000000000000E03F000000000000F8BF";0;1;2</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">"POINT(1.5 -1.5)";"0101000020E6100000000000000000F83F000000000000F8BF";0;2;2</span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">Is there something with the ST_Resample function that I am missing? I don’t understand why setting the SRID to 4326 breaks ST_Resample in this instance. ST_SetSRID for the above raster works
fine, the raster is returned and the coordinates are valid for 4326.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black">Any help is appreciated.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:"Times New Roman",serif"><br>
<br>
This communication is for use by the intended recipient and contains information that may be Privileged, confidential or copyrighted under applicable law. If you are not the intended recipient, you are hereby formally notified that any use, copying or distribution
of this e-mail,in whole or in part, is strictly prohibited. Please notify the sender by return e-mail and delete this e-mail from your system. Unless explicitly and conspicuously designated as "E-Contract Intended", this e-mail does not constitute a contract
offer, a contract amendment, or an acceptance of a contract offer. This e-mail does not constitute a consent to the use of sender's contact information for direct marketing purposes or for transfers of data to third parties. Francais Deutsch Italiano Espanol
Portugues Japanese Chinese Korean <a href="http://www.DuPont.com/corp/email_disclaimer.html" target="_blank">
http://www.DuPont.com/corp/email_disclaimer.html</a> </span><u></u><u></u></p>
</div>
</div>
<br>
<br>
This communication is for use by the intended recipient and contains information that may be Privileged, confidential or copyrighted under applicable law. If you are not the intended recipient, you are hereby formally notified that any use, copying or distribution
of this e-mail,in whole or in part, is strictly prohibited. Please notify the sender by return e-mail and delete this e-mail from your system. Unless explicitly and conspicuously designated as "E-Contract Intended", this e-mail does not constitute a contract
offer, a contract amendment, or an acceptance of a contract offer. This e-mail does not constitute a consent to the use of sender's contact information for direct marketing purposes or for transfers of data to third parties. Francais Deutsch Italiano Espanol
Portugues Japanese Chinese Korean <a href="http://www.DuPont.com/corp/email_disclaimer.html" target="_blank">http://www.DuPont.com/corp/email_disclaimer.html</a>
</div>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a></blockquote></div>