<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Thanks for your feedback, Darrel! I hope, your query results will
    look fine.<br>
    <br>
    Regards,<br>
    <br>
    Birgit<br>
    <br>
    <br>
    <div class="moz-cite-prefix">Am 24.11.2015 um 14:00 schrieb Darrel
      Maddy:<br>
    </div>
    <blockquote
cite="mid:DB3PR07MB0730F366ED5A53999CD93072C1060@DB3PR07MB0730.eurprd07.prod.outlook.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@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:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Times New Roman \,serif";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma",sans-serif;
        color:black;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma",sans-serif;}
span.EmailStyle22
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle23
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle24
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle25
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle26
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle27
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle28
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle29
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle30
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle31
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US">Dear
            Birgit,<o:p></o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US">Very many
            thanks. The query is now running – so it is no longer giving
            an error. I will not know for a few hours whether it is
            calculating the necessary values but it seems progress is
            being made.<o:p></o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US">I have a
            book coming on SQL – I clearly need to do my homework more
            thoroughly
          </span><span
            style="font-family:Wingdings;color:#1F497D;mso-fareast-language:EN-US">J</span><span
            style="color:#1F497D;mso-fareast-language:EN-US"><o:p></o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US">I will
            confirm when it stops!<o:p></o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US">Best wishes<o:p></o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US">Darrel<o:p></o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
            style="color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
        <div>
          <div style="border:none;border-top:solid #E1E1E1
            1.0pt;padding:3.0pt 0cm 0cm 0cm">
            <p class="MsoNormal"><b><span style="color:windowtext"
                  lang="EN-US">From:</span></b><span
                style="color:windowtext" lang="EN-US"> postgis-users
                [<a class="moz-txt-link-freetext" href="mailto:postgis-users-bounces@lists.osgeo.org">mailto:postgis-users-bounces@lists.osgeo.org</a>]
                <b>On Behalf Of </b>Birgit Laggner<br>
                <b>Sent:</b> 24 November 2015 12:19<br>
                <b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
                <b>Subject:</b> Re: [postgis-users] Help with SQL query?<o:p></o:p></span></p>
          </div>
        </div>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal" style="margin-bottom:12.0pt">Hi Darrel,<br>
          <br>
          my PostGIS version is too old for testing, but if I read the
          documentation right, then your expression has to be SQL. And
          IF THEN ELSE etc. is not SQL as far as I know - SQL has CASE
          WHEN.<br>
          <br>
          So, I would assume, you would need to write your expression
          like this:<br>
          <br>
          'CASE WHEN [rast2] > 0.0 THEN [rast1] ELSE NULL END'<br>
          <br>
          I am curious if this helps with your error...<br>
          <br>
          Regards,<br>
          <br>
          Birgit<br>
          <br>
          <span style="font-size:12.0pt"><o:p></o:p></span></p>
        <div>
          <p class="MsoNormal">Am 24.11.2015 um 10:09 schrieb Darrel
            Maddy:<o:p></o:p></p>
        </div>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US">Dear
              Roxanne,</span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US">Many
              thanks. I did pickup that issue shortly after my last post
              and it cured the first problem.</span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US">There is
              still an SQL issue with the expression however.</span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US">I tried
              ‘IF [rast2]>0.0 THEN [rast1] ELSE NULL ENDIF’</span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US">This
              produces an error at $2. I can remove that problem by
              doing this</span><o:p></o:p></p>
          <p class="MsoNormal"><a moz-do-not-send="true"
              name="_MailEndCompose"><span
                style="color:#1F497D;mso-fareast-language:EN-US">‘IF
                ([rast2]>0.0) THEN [rast1] ELSE NULL ENDIF’</span></a><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US">But then
              I get the error at THEN</span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US">Curiously
              ‘[rast2]+[rast1]’  works as intended so somehow the
              conditional is being specified incorrectly.</span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US">Unfortunately
              there is nothing in the documentation which helps me with
              this variant.
            </span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US">I will
              keep trying.</span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US">Darrel</span><o:p></o:p></p>
          <p class="MsoNormal"><span
              style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
          <div>
            <div style="border:none;border-top:solid #E1E1E1
              1.0pt;padding:3.0pt 0cm 0cm 0cm">
              <p class="MsoNormal"><b><span style="color:windowtext"
                    lang="EN-US">From:</span></b><span
                  style="color:windowtext" lang="EN-US"> postgis-users [<a
                    moz-do-not-send="true"
                    href="mailto:postgis-users-bounces@lists.osgeo.org">mailto:postgis-users-bounces@lists.osgeo.org</a>]
                  <b>On Behalf Of </b>Roxanne Reid-Bennett<br>
                  <b>Sent:</b> 24 November, 2015 12:46 AM<br>
                  <b>To:</b> <a moz-do-not-send="true"
                    href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
                  <b>Subject:</b> Re: [postgis-users] Help with SQL
                  query?</span><o:p></o:p></p>
            </div>
          </div>
          <p class="MsoNormal"> <o:p></o:p></p>
          <div>
            <p class="MsoNormal">On 11/23/2015 12:41 PM, Darrel Maddy
              wrote:<o:p></o:p></p>
          </div>
          <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US">Dear
                Pierre,</span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US">I was
                not looking for a total solution and I am grateful for
                the suggestion.
              </span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US">Although
                it may not look like it, I did consult the documentation
                and also I have Regina’s book beside me.  Unfortunately,
                for me at least, both documents assume some knowledge of
                SQL – which I do not have.  I am also trying to do this
                simultaneously with a large number of other things that
                are new to me.  I do not find the errors reported at all
                informative and consider the query I am trying to
                perform to be relatively trivial and hence I had hoped
                the structure of the query might have been more
                intuitive.  For others it may be.</span><o:p></o:p></p>
          </blockquote>
          <p class="MsoNormal"><span
              style="font-size:12.0pt;font-family:"Times New Roman
              ,serif",serif"><br>
              FWIW - I don't play with rasters, but this appears to be a
              pure SQL thing... add "as rast" like below and try again.<br>
              <br>
              <br>
            </span><span style="font-size:12.0pt">SELECT
              ST_MapAlgebra(deposition.rast, concentrated.rast, 'IF
              concentrated > 6 THEN deposition ELSE NULL ENDIF ' )
              <br>
            </span><span style="font-size:12.0pt;font-family:"Times
              New Roman ,serif",serif">as rast</span><o:p></o:p></p>
          <p class="MsoNormal"><span style="color:#1F497D">           
              FROM mymodel.deposition, mymodel.concentrated</span><o:p></o:p></p>
          <p class="MsoNormal"><span style="color:#1F497D">           
              WHERE ST_UpperleftX(mymodel.deposition.rast) =
              ST_UpperleftX(mymodel.concentrated.rast) AND
            </span><o:p></o:p></p>
          <p class="MsoNormal"><span style="color:#1F497D">                         ST_UpperleftY(mymodel.deposition.rast)
              = ST_UpperleftY(mymodel.deposition.rast)</span><o:p></o:p></p>
          <p class="MsoNormal"> <o:p></o:p></p>
          <p class="MsoNormal">Roxanne<o:p></o:p></p>
          <p class="MsoNormal"><span
              style="font-size:12.0pt;font-family:"Times New Roman
              ,serif",serif"><br>
              <br>
              <br>
            </span><o:p></o:p></p>
          <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US">I will
                try not to bother you again.</span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US">Darrel</span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span
                style="color:#1F497D;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
            <div>
              <div style="border:none;border-top:solid #E1E1E1
                1.0pt;padding:3.0pt 0cm 0cm 0cm">
                <p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span
                    lang="EN-US"> postgis-users [<a
                      moz-do-not-send="true"
                      href="mailto:postgis-users-bounces@lists.osgeo.org">mailto:postgis-users-bounces@lists.osgeo.org</a>]
                    <b>On Behalf Of </b>Pierre Racine<br>
                    <b>Sent:</b> 23 November 2015 20:30<br>
                    <b>To:</b> PostGIS Users Discussion <a
                      moz-do-not-send="true"
                      href="mailto:postgis-users@lists.osgeo.org">
                      <postgis-users@lists.osgeo.org></a><br>
                    <b>Subject:</b> Re: [postgis-users] Help with SQL
                    query?</span><o:p></o:p></p>
              </div>
            </div>
            <p class="MsoNormal"> <o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US">The expression has to stay as it was: 'IF
                [rast2] > threshold THEN [rast1] ELSE NULL ENDIF '</span><o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US">Just replace the threshold value as you
                did.</span><o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US">Do not try to replace the [rast2] and
                [rast1]. They refer to the first and second raster pixel
                values. Read the ST_Mapalgebra doc…</span><o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US">Don’t expect our suggestions to work
                blindly. I did not test this query. I’m not in your
                context. I expect you read the doc about all the
                mentioned functions and adjust for your specific
                context. I said “your query should “look like” this”…</span><o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US">Pierre</span><o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US"> </span><o:p></o:p></p>
            <p class="MsoNormal"><span style="color:#1F497D"
                lang="EN-US"> </span><o:p></o:p></p>
            <div style="border:none;border-left:solid blue
              1.5pt;padding:0cm 0cm 0cm 4.0pt">
              <div>
                <div style="border:none;border-top:solid #B5C4DF
                  1.0pt;padding:3.0pt 0cm 0cm 0cm">
                  <p class="MsoNormal"><b><span
                        style="font-size:10.0pt;font-family:"Tahoma",sans-serif"
                        lang="EN-US">From:</span></b><span
                      style="font-size:10.0pt;font-family:"Tahoma",sans-serif"
                      lang="EN-US"> postgis-users [<a
                        moz-do-not-send="true"
                        href="mailto:postgis-users-bounces@lists.osgeo.org">mailto:postgis-users-bounces@lists.osgeo.org</a>]
                      <b>On Behalf Of </b>Darrel Maddy<br>
                      <b>Sent:</b> Monday, November 23, 2015 2:47 PM<br>
                      <b>To:</b> PostGIS Users Discussion<br>
                      <b>Subject:</b> Re: [postgis-users] Help with SQL
                      query?</span><o:p></o:p></p>
                </div>
              </div>
              <p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">OK I
                  spoke too soon.</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">I tried
                  this:</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">SELECT
                  (ST_SummaryStats(ST_Union(rast))).sum sum</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">FROM
                  (SELECT ST_MapAlgebra(deposition.rast,
                  concentrated.rast, 'IF concentrated > 6 THEN
                  deposition ELSE NULL ENDIF ' )</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">           
                  FROM mymodel.deposition, mymodel.concentrated</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">           
                  WHERE ST_UpperleftX(mymodel.deposition.rast) =
                  ST_UpperleftX(mymodel.concentrated.rast) AND
                </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">                         ST_UpperleftY(mymodel.deposition.rast)
                  = ST_UpperleftY(mymodel.deposition.rast) ) foo;</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">And all I
                  get is rast does not exist.</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">I’m
                  afraid the penny has not dropped yet
                </span><span style="font-family:Wingdings;color:#1F497D">L</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">Darrel</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <div>
                <div style="border:none;border-top:solid #E1E1E1
                  1.0pt;padding:3.0pt 0cm 0cm 0cm">
                  <p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span
                      lang="EN-US"> postgis-users [<a
                        moz-do-not-send="true"
                        href="mailto:postgis-users-bounces@lists.osgeo.org">mailto:postgis-users-bounces@lists.osgeo.org</a>]
                      <b>On Behalf Of </b>Darrel Maddy<br>
                      <b>Sent:</b> 23 November 2015 16:30<br>
                      <b>To:</b> PostGIS Users Discussion <<a
                        moz-do-not-send="true"
                        href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a>><br>
                      <b>Subject:</b> Re: [postgis-users] Help with SQL
                      query?</span><o:p></o:p></p>
                </div>
              </div>
              <p class="MsoNormal"> <o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">Dear
                  Pierre and Rasmus,</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">Many
                  thanks for trying to help.</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">Rasmus: I
                  am aware of GMT but I was looking for a solution in
                  postgis so that I can keep all of the data extraction
                  in one place.</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">Pierre:
                  That is exactly what I was looking for and very many
                  thanks for including the explanation.  I am a little
                  overwhelmed with the number of functions offered in
                  postgis. It is certainly a remarkable tool.  Watching
                  the queries plough through my datasets is a pleasure –
                  albeit the results do not always please me
                </span><span style="font-family:Wingdings;color:#1F497D">J</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">Hopefully
                  I can put this to work later tonight.</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">Best
                  wishes</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D">Darrel</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"> </span><o:p></o:p></p>
              <div>
                <div style="border:none;border-top:solid #E1E1E1
                  1.0pt;padding:3.0pt 0cm 0cm 0cm">
                  <p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span
                      lang="EN-US"> postgis-users [<a
                        moz-do-not-send="true"
                        href="mailto:postgis-users-bounces@lists.osgeo.org">mailto:postgis-users-bounces@lists.osgeo.org</a>]
                      <b>On Behalf Of </b>Pierre Racine<br>
                      <b>Sent:</b> 23 November 2015 16:17<br>
                      <b>To:</b> PostGIS Users Discussion <<a
                        moz-do-not-send="true"
                        href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a>><br>
                      <b>Subject:</b> Re: [postgis-users] Help with SQL
                      query?</span><o:p></o:p></p>
                </div>
              </div>
              <p class="MsoNormal"> <o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">Darrel,</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US"> </span><o:p></o:p></p>
              <p class="MsoListParagraph" style="text-indent:-18.0pt"><span
                  style="color:#1F497D" lang="EN-US">1)</span><span
                  style="font-size:7.0pt" lang="EN-US">     
                </span><span style="color:#1F497D" lang="EN-US">Create a
                  new raster selecting the right pixels with
                  ST_MapAlgebra(raster, raster)</span><o:p></o:p></p>
              <p class="MsoListParagraph" style="text-indent:-18.0pt"><span
                  style="color:#1F497D" lang="EN-US">2)</span><span
                  style="font-size:7.0pt" lang="EN-US">     
                </span><span style="color:#1F497D" lang="EN-US">Make
                  sure only intersecting rasters are processed by using
                  their upper left corner X and Y coordinates (with
                  ST_UpperLeftX() and UpperLeftY())</span><o:p></o:p></p>
              <p class="MsoListParagraph" style="text-indent:-18.0pt"><span
                  style="color:#1F497D" lang="EN-US">3)</span><span
                  style="font-size:7.0pt" lang="EN-US">     
                </span><span style="color:#1F497D" lang="EN-US">Sum the
                  selected pixels with ST_SummaryStats(rast)</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">All in all a global query should look
                  like this:</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">SELECT
                  (ST_SummaryStats(ST_Union(rast))).sum sum</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">FFOM (SELECT ST_MapAlgebra(tableA.rast,
                  tableB.rast, 'IF [rast2] > threshold THEN [rast1]
                  ELSE NULL</span><span lang="EN-US"> ENDIF
                </span><span style="color:#1F497D" lang="EN-US">' )</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">            FROM tableA, tableB</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">            WHERE
                  ST_UpperleftX(tableA.rast) =
                  ST_UpperleftX(tableB.rast) AND
                </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">                         ST_UpperleftY(tableA.rast)
                  = ST_UpperleftY(tableB.rast) AND
                </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">                         maybe some other
                  condition here if you get time series e.g. tableA.year
                  = tableB.year AND tableA.month = tableB.month) foo</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">If you have millions of tile you could
                  create indexes on ST_UpperleftX(tableA.rast),
                  ST_UpperleftX(tableB.rast), ST_UpperleftY(tableA.rast)
                  and ST_UpperleftY(tableB.rast) to make the query
                  faster.</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">You could also just use WHERE
                  ST_Intersects(tableA.rast, tableB.rast) instead…</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US"> </span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US">Pierre</span><o:p></o:p></p>
              <p class="MsoNormal"><span style="color:#1F497D"
                  lang="EN-US"> </span><o:p></o:p></p>
              <div style="border:none;border-left:solid blue
                1.5pt;padding:0cm 0cm 0cm 4.0pt">
                <div>
                  <div style="border:none;border-top:solid #B5C4DF
                    1.0pt;padding:3.0pt 0cm 0cm 0cm">
                    <p class="MsoNormal"><b><span
                          style="font-size:10.0pt;font-family:"Tahoma",sans-serif"
                          lang="EN-US">From:</span></b><span
                        style="font-size:10.0pt;font-family:"Tahoma",sans-serif"
                        lang="EN-US"> postgis-users [<a
                          moz-do-not-send="true"
                          href="mailto:postgis-users-bounces@lists.osgeo.org">mailto:postgis-users-bounces@lists.osgeo.org</a>]
                        <b>On Behalf Of </b>Darrel Maddy<br>
                        <b>Sent:</b> Monday, November 23, 2015 7:20 AM<br>
                        <b>To:</b> PostGIS Users Discussion<br>
                        <b>Subject:</b> [postgis-users] Help with SQL
                        query?</span><o:p></o:p></p>
                  </div>
                </div>
                <p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
                <p class="MsoNormal">Dear all,<o:p></o:p></p>
                <p class="MsoNormal"> <o:p></o:p></p>
                <p class="MsoNormal">As you know I am relatively new to
                  postgis and SQL and therefore  I have much to learn.
                  However, I am facing a paper deadline and need to do
                  some quick analysis of the data I have and I am
                  struggling to figure out how best to pursue what I
                  need to do.<o:p></o:p></p>
                <p class="MsoNormal"> <o:p></o:p></p>
                <p class="MsoNormal">I have a significant number of
                  rasters which have double precision values.  Without
                  going into detail about what the rasters represent, I
                  need to extract and sum values from one set of rasters
                  in say table A based upon  values in another set of
                  rasters in say table B  where the pixel value in the
                  raster from Table B exceeds a threshold. Both tables
                  are the same size (rasters are tiled) but I also need
                  to figure out how I make sure the correct rasters are
                  compared.  They have filenames like this
                  rastervariable_10.tif, rastervariable_100.tif ,
                  presumably I need to use a logical expression to strip
                  the numerical value (in this case this represents the
                  year) and then order on that basis?<o:p></o:p></p>
                <p class="MsoNormal"> <o:p></o:p></p>
                <p class="MsoNormal">I can do this in QGIS one at a time
                  but that is a little clumsy and rather time consuming.
                  <o:p></o:p></p>
                <p class="MsoNormal"> <o:p></o:p></p>
                <p class="MsoNormal">If someone can just point me in the
                  right direction I am sure I can figure out the rest
                  for myself.<o:p></o:p></p>
                <p class="MsoNormal"> <o:p></o:p></p>
                <p class="MsoNormal">Apologies once more for asking what
                  is probably a rather trivial question and yet again
                  demonstrating my ignorance.<o:p></o:p></p>
                <p class="MsoNormal"> <o:p></o:p></p>
                <p class="MsoNormal">Many thanks<o:p></o:p></p>
                <p class="MsoNormal"> <o:p></o:p></p>
                <p class="MsoNormal">Darrel<o:p></o:p></p>
              </div>
            </div>
            <p class="MsoNormal"><span
                style="font-size:12.0pt;font-family:"Times New
                Roman ,serif",serif"><br>
                <br>
                <br>
                <br>
              </span><o:p></o:p></p>
            <pre>_______________________________________________<o:p></o:p></pre>
            <pre>postgis-users mailing list<o:p></o:p></pre>
            <pre><a moz-do-not-send="true" href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><o:p></o:p></pre>
            <pre><a moz-do-not-send="true" href="http://lists.osgeo.org/mailman/listinfo/postgis-users">http://lists.osgeo.org/mailman/listinfo/postgis-users</a><o:p></o:p></pre>
          </blockquote>
          <p class="MsoNormal"><span
              style="font-size:12.0pt;font-family:"Times New Roman
              ,serif",serif"><br>
              <br>
              <br>
              <br>
            </span><o:p></o:p></p>
          <pre>-- <o:p></o:p></pre>
          <pre>[At other schools] I think the most common fault in general is to teach students how to pass exams instead of teaching them the science.<o:p></o:p></pre>
          <pre>Donald Knuth<o:p></o:p></pre>
          <p class="MsoNormal"><span
              style="font-size:12.0pt;font-family:"Times New
              Roman",serif"><br>
              <br>
              <br>
              <o:p></o:p></span></p>
          <pre>_______________________________________________<o:p></o:p></pre>
          <pre>postgis-users mailing list<o:p></o:p></pre>
          <pre><a moz-do-not-send="true" href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><o:p></o:p></pre>
          <pre><a moz-do-not-send="true" href="http://lists.osgeo.org/mailman/listinfo/postgis-users">http://lists.osgeo.org/mailman/listinfo/postgis-users</a><o:p></o:p></pre>
        </blockquote>
        <p class="MsoNormal"><span
            style="font-size:12.0pt;font-family:"Times New
            Roman",serif"><o:p> </o:p></span></p>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
postgis-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/postgis-users">http://lists.osgeo.org/mailman/listinfo/postgis-users</a></pre>
    </blockquote>
    <br>
  </body>
</html>