<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Monospaced;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.hps
        {mso-style-name:hps;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:70.85pt 85.05pt 70.85pt 85.05pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D'>You probably want to use ST_Reclass  and then ST_DumpAsPolygons.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><a href="http://postgis.net/docs/manual-2.2/RT_ST_Reclass.html">http://postgis.net/docs/manual-2.2/RT_ST_Reclass.html</a> - this will reduce your pixels into a binary of above 70% , not above 70%<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><a href="http://postgis.net/docs/manual-2.2/RT_ST_DumpAsPolygons.html">http://postgis.net/docs/manual-2.2/RT_ST_DumpAsPolygons.html</a> would then give you two sets of polygons with the two new pixel values.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal style='margin-left:.5in'><b>From:</b> postgis-users [mailto:postgis-users-bounces@lists.osgeo.org] <b>On Behalf Of </b>liglio@pobox.com<br><b>Sent:</b> Tuesday, March 08, 2016 3:10 PM<br><b>To:</b> postgis-users@lists.osgeo.org<br><b>Subject:</b> [postgis-users] Raster SQL to separate high value areas<o:p></o:p></p></div></div><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>Hi,<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>I am trying to separate areas of high value of lightning probability (above 70%) in a Raster<span style='color:#1F497D'> and calculate their centroids</span>. I successfully loaded a GeoTiff raster image (one band, gray scale, 982x1108 pixels) in PostgreSQL 9.5 (Postgis 2.2.1). I see the<span style='color:#1F497D'> SQL</span> result<span style='color:#1F497D'>s</span> in OenJump 1.9.<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'><span style='color:#1F497D'>I used </span>the next SQL<span style='color:#1F497D'>, but the function </span><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>ST_PixelAsPoints result in a </span><span style='font-size:10.0pt;font-family:"Verdana",sans-serif;color:#2E2E2E'>geometry points which are of the pixel's upper-left corner. I am not sure that is the right way to do, because of that </span><span class=hps><span lang=EN style='font-family:"Arial",sans-serif;color:#222222'>displacement</span></span><span style='font-size:10.0pt;font-family:"Verdana",sans-serif;color:#2E2E2E'>. Can I do without this transformation raster-geometry ?<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='color:#1F497D'>Thanks.<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>SELECT </span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>row_number() over () </span><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>AS </span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>id,</span><span style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>  ST_NumGeometries(gc),</span><span style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>  gc </span><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>AS </span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>geom_collection,</span><span style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>  ST_Centroid(gc) </span><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>AS </span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>centroid</span><span style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>FROM </span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>(</span><span style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>  </span><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>SELECT unnest</span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>(ST_ClusterWithin(geom, </span><span style='font-size:9.0pt;font-family:Monospaced;color:fuchsia;mso-fareast-language:PT-BR'>0</span><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>.</span><span style='font-size:9.0pt;font-family:Monospaced;color:fuchsia;mso-fareast-language:PT-BR'>1</span><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>)) </span><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>AS </span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>gc</span><span style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>  </span><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>FROM </span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>(</span><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>SELECT </span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>(ST_PixelAsPoints(rast, </span><span style='font-size:9.0pt;font-family:Monospaced;color:fuchsia;mso-fareast-language:PT-BR'>1</span><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>)).* </span><span style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>    </span><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>FROM </span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>tb_lightningprob) foo</span><span style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>    </span><b><span style='font-size:9.0pt;font-family:Monospaced;color:blue;mso-fareast-language:PT-BR'>WHERE </span></b><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>val > </span><span style='font-size:9.0pt;font-family:Monospaced;color:fuchsia;mso-fareast-language:PT-BR'>0</span><span style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>.</span><span style='font-size:9.0pt;font-family:Monospaced;color:fuchsia;mso-fareast-language:PT-BR'>7</span><span style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><span lang=PT-BR style='font-size:9.0pt;font-family:Monospaced;color:black;mso-fareast-language:PT-BR'>) f;</span><span lang=PT-BR style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in;text-autospace:none'><span lang=PT-BR style='font-size:12.0pt;font-family:Monospaced;mso-fareast-language:PT-BR'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p></div></body></html>