<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Grazie mille, preziosissimi.</p>
    <p>Aramis<br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 30/03/2017 09:33, G. Allegri wrote:<br>
    </div>
    <blockquote
cite="mid:CAB4g1=w+W7g1iS4fXG-TamS+GBGO1Qp6Tg44tF_pvRpxQi7-Ug@mail.gmail.com"
      type="cite">
      <div dir="ltr">Nella query che ho proposto ho usato ST_Union() e
        poi però sotto parlo di collect(). Come ho aggiunto in coda alla
        risposta le due funzioni vanno entrambe bene ma fanno cose
        diverse: st_union fa il dissolve, collect semplicemente
        raggruppa (multipart).
        <div><br>
        </div>
        <div>Giovanni</div>
        <div><br>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">Il giorno 30 marzo 2017 09:26, Stefano
          Campus <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:skampus@gmail.com" target="_blank">skampus@gmail.com</a>></span>
          ha scritto:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">ovviamente la risposta di giovanni è
              ineccepibile, corretta ed elegante; la soluzione che ho
              segnalato è proprio da "praticone".
              <div>:-)</div>
              <span class="HOEnZb"><font color="#888888">
                  <div><br>
                  </div>
                  <div>s.</div>
                </font></span></div>
            <div class="HOEnZb">
              <div class="h5">
                <div class="gmail_extra"><br>
                  <div class="gmail_quote">Il giorno 30 marzo 2017
                    09:22, G. Allegri <span dir="ltr"><<a
                        moz-do-not-send="true"
                        href="mailto:giohappy@gmail.com" target="_blank">giohappy@gmail.com</a>></span>
                    ha scritto:<br>
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <div dir="ltr">Buongiorno,
                        <div>la funzione Processing ->Strumenti
                          geometria vettore -> Dissolve permette di
                          eseguirlo in base ad un campo di
                          raggruppamento. Se vedi, nella finestra dello
                          strumento, c'è un "Campo ID univoco". Se
                          deselezioni "Dissolvi tutto" (flag) e
                          selezioni il campo di raggruppamento, il
                          dissolve sarà fatto in base al valore di quel
                          campo. Tuttavia lo strumento non ti permette
                          di ottenere aggregazioni (somme, medie, ecc.)
                          sugli altri campi.</div>
                        <div><br>
                        </div>
                        <div>La strada più versatile è sicuramente l'uso
                          di una query SQL. Per poterla visualizzare
                          puoi aggiungere un campo geometrico e
                          applicarci una funzione di aggregazione:</div>
                        <div><br>
                        </div>
                        <div><span style="font-size:12.8px">SELECT</span></div>
                        <div><span style="font-size:12.8px"> 
                             "COD_ISTAT",</span></div>
                        <div><span style="font-size:12.8px"> 
                             sum(R03_indicatori_2</span><span
                            style="font-size:12.8px">011_sezio<wbr>ni_P1)
                            AS somma_p1,</span></div>
                        <div><span style="font-size:12.8px">   </span><b>ST_Union</b><span
                            style="font-size:12.8px"><b>(geom</b></span><span
                            style="font-size:12.8px"><b>) AS geom</b>,</span></div>
                        <div><span style="font-size:12.8px">FROM
                            "R03_11_WGS84" GROUP BY "COD_ISTAT"</span><br>
                        </div>
                        <div><span style="font-size:12.8px"><br>
                          </span></div>
                        <div><span style="font-size:12.8px">La funzioni
                            collect() crea un multipolygon di tutte le
                            sezioni censuarie di ogni gruppo
                            "COD_ISTAT".</span></div>
                        <div><span style="font-size:12.8px"><br>
                          </span></div>
                        <div><span style="font-size:12.8px">A quel punto
                            in fondo alla finestra SQL del DB Manager </span></div>
                        <div><span style="font-size:12.8px"><br>
                          </span></div>
                        <div><span style="font-size:12.8px">1) clicca su
                            "Carica come nuovo layer"</span></div>
                        <div><span style="font-size:12.8px">2) Scegli il
                            campo id univoco (es. COD_ISTAT)</span></div>
                        <div><span style="font-size:12.8px">3) Scegli la
                            colonna geometrica (in questo esempio
                            sarebbe geom per come ho definito l'alias
                            del campo (AS geom)</span></div>
                        <div><span style="font-size:12.8px">4) Clicca su
                            "Carica ora!"</span></div>
                        <div><span style="font-size:12.8px"><br>
                          </span></div>
                        <div><span style="font-size:12.8px">Ti si
                            caricherà un layer (Querylayer) che conterrà
                            le tue geometrie aggregate (dalla collect)
                            e, nella tabella attributi, le somme.</span></div>
                        <div><span style="font-size:12.8px"><br>
                          </span></div>
                        <div><span style="font-size:12.8px">Ovviamente
                            potrai aggiungere altri campi (somma di p2,
                            ecc.) e potrai anche aggregare per più campi
                            (GROUP BY campo1,campo2,ecc.)</span></div>
                        <div><span style="font-size:12.8px"><br>
                          </span></div>
                        <div><span style="font-size:12.8px">Nella
                            documentazione delle funzioni di Spatialite
                            le funzioni di aggregazione sono segnate con
                            la scritta in rosso "aggregate_function"
                            [1]. Tra queste c'è anche le "collect()"
                            che, a differenza della st_unioni,
                            semplicemente ti crea una multigeometria
                            invece che l'unione, e quindi è molto più
                            veloce.</span></div>
                        <div><span style="font-size:12.8px"><br>
                          </span></div>
                        <div><span style="font-size:12.8px">Giovanni</span></div>
                        <div><span style="font-size:12.8px"><br>
                          </span></div>
                        <div><span style="font-size:12.8px">[1] <a
                              moz-do-not-send="true"
                              href="http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.2.0.html"
                              target="_blank">http://www.gaia-gis.it/gai<wbr>a-sins/spatialite-sql-4.2.0.<wbr>html</a></span></div>
                      </div>
                      <div class="gmail_extra"><br>
                        <div class="gmail_quote"><span>Il giorno 30
                            marzo 2017 08:56, Aramis <span dir="ltr"><<a
                                moz-do-not-send="true"
                                href="mailto:sleeping.aramis@gmail.com"
                                target="_blank">sleeping.aramis@gmail.com</a>></span>
                            ha scritto:<br>
                          </span>
                          <div>
                            <div class="m_4276210109925136158h5">
                              <blockquote class="gmail_quote"
                                style="margin:0 0 0 .8ex;border-left:1px
                                #ccc solid;padding-left:1ex">Ciao e buon
                                giovedì, forza che la settimana sta
                                finendo.<br>
                                Stavo provando a lavorare con i dati del
                                censimento istat, scarico i file dal
                                sito carico lo shape delle zone
                                censuarie gli faccio un join con la
                                tabella contenente i dati tramite i
                                campi che mi indicano le sezioni. tutto
                                regolare.<br>
                                Vorrei visualizzare i dati raggruppati
                                per comuni, campo cod_istat, ma il
                                dissolve group by in qgis non mi pare
                                sia presente. Trovo che è necessario
                                passare per il DB manager e fare una
                                query sql. Provo la seguente:<br>
                                select COD_ISTAT,sum(R03_indicatori_2<wbr>011_sezioni_P1)from
                                "R03_11_WGS84"group by COD_ISTAT<br>
                                Per fargli sommare i valori P1 per ogni
                                comune.<br>
                                La query sembra venire ma:<br>
                                1- come visualizzo i risultati
                                graficamente?<br>
                                2- dovendo considerare più campi oltre a
                                P1 ho provato a modificare il nome del
                                campo "R03_indicatori_2011_sezioni_P<wbr>1
                                in semplicemente P1 e così via per fare
                                delle query un po' più comodamente. Non
                                mi accetta il cambio di nome...
                                possibile perchè essendo il campo
                                risultante da un join fa riferimento a
                                una tabella altra e i nomi devono
                                restare invariati?<br>
                                Alla fine si tratterebbe di un dissolve
                                rispetto a un campo, caoistat, e che
                                sommi gli altri campi, i vari p1 p2 etc<br>
                                Qualcuno sa dirmi come potrei procedere?<br>
                                Grazie<span
                                  class="m_4276210109925136158m_-7484827451195297434HOEnZb"><font
                                    color="#888888"><br>
                                    Aramis<br>
                                    ______________________________<wbr>_________________<br>
                                    QGIS-it-user mailing list<br>
                                    <a moz-do-not-send="true"
                                      href="mailto:QGIS-it-user@lists.osgeo.org"
                                      target="_blank">QGIS-it-user@lists.osgeo.org</a><br>
                                    <a moz-do-not-send="true"
                                      href="https://lists.osgeo.org/mailman/listinfo/qgis-it-user"
                                      rel="noreferrer" target="_blank">https://lists.osgeo.org/mailma<wbr>n/listinfo/qgis-it-user</a><br>
                                  </font></span></blockquote>
                            </div>
                          </div>
                        </div>
                        <br>
                      </div>
                      <br>
                      ______________________________<wbr>_________________<br>
                      QGIS-it-user mailing list<br>
                      <a moz-do-not-send="true"
                        href="mailto:QGIS-it-user@lists.osgeo.org"
                        target="_blank">QGIS-it-user@lists.osgeo.org</a><br>
                      <a moz-do-not-send="true"
                        href="https://lists.osgeo.org/mailman/listinfo/qgis-it-user"
                        rel="noreferrer" target="_blank">https://lists.osgeo.org/mailma<wbr>n/listinfo/qgis-it-user</a><br>
                      <br>
                    </blockquote>
                  </div>
                  <br>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>