<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hi Stephan,<br>
      <br>
      We modified the postgis-workshop tutorial for qgis plugin
      development to use the new python api of qgis 1.9, there are
      examples of feature access in there:<br>
      <br>
      <a class="moz-txt-link-freetext"
        href="https://github.com/Oslandia/postgis-workshop">https://github.com/Oslandia/postgis-workshop</a><br>
      <br>
      Cheers,<br>
      <br>
      Vincent.<br>
      <br>
      On 17/07/2013 21:13, Stéphane Henriod wrote:<br>
    </div>
    <blockquote
cite="mid:CAK6pVBUhynefjv2b4xfxDiAe37=ZGSrjqw6a8d4BQExNz5DRhA@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>Dear all<br>
                  <br>
                </div>
                I am trying to get into the new 2.0 API and am still
                facing issues for very basic stuff: getting the values
                of the attributes out of a PostGIS layer.<br>
                <br>
              </div>
              Basically, it works (with the almost same code) in the
              Qgis python console, but I don't manage to get it to work
              in a stand-alone script.<br>
              <br>
            </div>
            What I have so far is a PostGIS layer, that I load with:<br>
            <br>
            <blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px
              solid rgb(204,204,204);padding-left:1ex"
              class="gmail_quote">
              <i>uri = QgsDataSourceURI()<br>
                uri.setConnection('localhost', '5432', 'db_name',
                'user_name', 'password')<br>
                uri.setDataSource('my_schema', 'my_table', 'the_geom')<br>
                    <br>
                my_layer =
                QgsVectorLayer(uri.uri(),'myhospitals','postgres')<br>
              </i></blockquote>
            <br>
          </div>
          A quick test shows me that the layer has been successfully
          loaded:<br>
          <br>
          <blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px
            solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
            <i>if not my_layer.isValid():<br>
                  print "Layer failed to load!"<br>
              else:<br>
                  print "Layer loaded successfully"<br>
            </i></blockquote>
          <br>
        </div>
        I would assume that<br>
        <br>
        <blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px
          solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
          <i>for elem in my_layer.getFeatures():</i><br>
          <i>    print elem.attributes()</i><br>
        </blockquote>
        <div>
          <div>
            <div><br>
            </div>
            <div>should return the attributes in a usable format but,
              instead, I get:<br>
              <i><br>
              </i>
              <blockquote style="margin:0px 0px 0px
                0.8ex;border-left:1px solid
                rgb(204,204,204);padding-left:1ex" class="gmail_quote">
                <i>[<PyQt4.QtCore.QVariant object at 0xad37aca4>,
                  <PyQt4.QtCore.QVariant object at 0xad37acdc>,
                  None, <PyQt4.QtCore.QVariant object at
                  0xad37ad14>]</i><br>
                <i>[<PyQt4.QtCore.QVariant object at 0xad37aca4>,
                  <PyQt4.QtCore.QVariant object at 0xad37acdc>,
                  <PyQt4.QtCore.QVariant object at 0xad37ad14>,
                  <PyQt4.QtCore.QVariant object at 0xad37ad4c>]</i><br>
                <i>[<PyQt4.QtCore.QVariant object at 0xad37aca4>,
                  <PyQt4.QtCore.QVariant object at 0xad37acdc>,
                  <PyQt4.QtCore.QVariant object at 0xad37ad14>,
                  <PyQt4.QtCore.QVariant object at 0xad37ad4c>]</i><br>
                <i>[<PyQt4.QtCore.QVariant object at 0xad37aca4>,
                  <PyQt4.QtCore.QVariant object at 0xad37acdc>,
                  <PyQt4.QtCore.QVariant object at 0xad37ad14>,
                  <PyQt4.QtCore.QVariant object at 0xad37ad4c>]</i><br>
              </blockquote>
            </div>
            <div><br>
            </div>
            <div>Does anyone have an idea where the problem could lie?<br>
              <br>
            </div>
            <div>For those who speak French, the question is posted here
              as well: <a moz-do-not-send="true"
href="http://www.forumsig.org/showthread.php/37178-Nouvelle-API-r%C3%A9cup%C3%A9rer-les-valeurs-attributaires">http://www.forumsig.org/showthread.php/37178-Nouvelle-API-r%C3%A9cup%C3%A9rer-les-valeurs-attributaires</a><br>
            </div>
            <div><br>
            </div>
            <div>I am using Qgis 1.9.0 with Python 2.7 on Ubuntu 13.04<br>
              <br>
            </div>
            <div>Thanks in advance for ideas and comments...<br>
              <br>
              Cheers<br>
              <br>
              Stéphane<br clear="all">
            </div>
            <div>
              <div>
                <div>
                  <div>
                    <div>
                      <div>
                        --<br>
                        "Le mot progrès n'aura aucun sens tant qu'il y
                        aura des enfants malheureux" -- Albert Einstein<br>
                        <br>
                        "A journey does not need reasons. Before long,
                        it proves to be reason enough in itself. One
                        thinks that one is going to make a journey, yet
                        soon it is the journey that makes or unmakes
                        you." -- Nicolas Bouvier<br>
                        <br>
                        Photos de voyages, photos de montagne: <a
                          moz-do-not-send="true"
                          href="http://www.henriod.info/"
                          target="_blank">http://www.henriod.info</a><span
                          dir="ltr"><span dir="ltr" title="Appeler ce
                            numéro de téléphone en/au(x) Tadjikistan
                            avec Skype : +992934624662"><span>  </span></span>
                          <br>
                        </span></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Qgis-developer mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/qgis-developer">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>