<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hello Matthias,<br>
      <br>
      Just one question :<br>
      <div id="gt-src-tools">
        <div id="gt-src-tools-l">
          <div style="display: inline-block;" id="gt-input-tool">
            <div id="itamenu"><span class="ita-kd-inputtools-div"></span></div>
          </div>
        </div>
      </div>
      <div id="gt-res-content" class="almost_half_cell">
        <div dir="ltr" style="zoom:1">
          <div id="tts_button" style="" class=""><object
              type="application/x-shockwave-flash"
              data="//ssl.gstatic.com/translate/sound_player2.swf"
              id="tts" height="18" width="18"></object></div>
          <span id="result_box" class="short_text" lang="en"><span
              class="hps">How many meters</span> <span class="hps">high,</span>
            <span class="hps">the</span> <span class="hps">statue? :-)<br>
            </span></span><br>
          <div id="gt-src-tools">
            <div id="gt-src-tools-l">
              <div style="display: inline-block;" id="gt-input-tool">
                <div id="itamenu"><span class="ita-kd-inputtools-div"></span></div>
              </div>
            </div>
          </div>
          <div id="gt-res-content" class="almost_half_cell">
            <div dir="ltr" style="zoom:1">
              <div id="tts_button" style="" class=""><object
                  type="application/x-shockwave-flash"
                  data="//ssl.gstatic.com/translate/sound_player2.swf"
                  id="tts" height="18" width="18"></object></div>
              <span id="result_box" class="short_text" lang="en"><span
                  class="hps">I've stumbled</span> <span class="hps">on</span>
                <span class="hps">this problem for</span> <span
                  class="hps">three weeks!<br>
                  Indeed, this is the right code : <br>
                </span></span><br>
              <font color="#cc0000"><i>geom2=convert_geometries([</i><i><u>QgsGeometry</u></i><i>(feature.geometry())
                  for feature in
                  self.iface.activeLayer().selectedFeatures()],geom_output)</i></font><br>
              <br>
              Adding QgsGeometry() makes the plugin work perfectly with
              one or many features selected.<br>
              <br>
              Thanks a lot!!<br>
              Best regards.<br>
              <br>
              Vincent<br>
            </div>
          </div>
        </div>
      </div>
      <br>
      <div class="moz-signature">
        <style><!--
       .moz-txt-sig, .moz-signature {
         opacity: inherit !important;
       }
       --></style>
        <meta http-equiv="content-type" content="text/html;
          charset=UTF-8">
        <div class="moz-signature">
          <div class="moz-signature">
            <div class="moz-signature">
              <div class="moz-signature"><br>
              </div>
            </div>
          </div>
        </div>
      </div>
      Le 15/01/2014 15:35, Matthias Kuhn a écrit :<br>
    </div>
    <blockquote cite="mid:52D69C99.3080300@gmx.ch" type="cite">
      <pre wrap="">Hi Vincent,

Is it possible that you are hit by the bug in this report [1]

The workaround would by to keep a reference to the encapsulating 
feature as long as you need their geometries. (Or possibly to copy the 
geometry with g = QgsGeometry( feature.gemetry() ))

Best
Matthias

[1] <a class="moz-txt-link-freetext" href="http://hub.qgis.org/issues/777">http://hub.qgis.org/issues/777</a>

On Mit 15 Jan 2014 15:10:37 CET, Vincent Damoy wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">Hi to all,


I'm working with QGIS 2.0.1 on a python plugin to help users enter
data in a Postgis database.
Among others things, this plugin can convert selected features (from
points to polygons, from lines to points, etc...)

_The plugin :_
operation_dialog.py is my main module.
convert_geometries module is used to convert features

In this second module, convert_geometries function accepts 2 parameters :
geomlist (a list of geometries),
geomoutput, (output data type : Qgis.point, Qgis.polygon ou Qgis.line).

extract :
/def convert_geometries(geomlist, geomtype):
     ret = None
     if len(set([geom.type() for geom in geomlist])) <> 1:
         print [geom.type() for geom in geomlist]
         ret = None
     else :
         if geomlist[0].type() == QGis.Line and geomtype == QGis.Polygon:
             ret = linestrings_polygon(geomlist)
.../

If geometries in geomlist have different data types, then ret=None
(and the plugin manage this error).
Else, if features are lines and polygons are needed, corresponding
conversion function is started.

convert_geometries is started from my main module :

/geom2=convert_geometries([feature.geometry() for feature in
self.iface.activeLayer().selectedFeatures()],geom_output) /

Here, geomlist is a list of geometries from features selected by user
in the active layer).
geomtype=geom_output (selected by user in a combobox).

_The problem :_ Things go well if only one feature is selected.
However, if 2 or more features of the same type are selected, (3 lines
for example), geometries are systematically corrupted during passage
from one module to the other, except the last one.

In the main module, this line :
« /print [feature.geometry() for feature in
self.iface.activeLayer().selectedFeatures()]/ »
returns [1,1,1] (which means [line , line, line]).
However, in convert_geometries, «  /print [geom.type() for geom in
geomlist]/ » line returns [3,3,1]
(that is [unknowm geometry, unknowm geometry, line]).
If I try to display geometries in WKT format (/print
[geom.exportToWkt() for geom in geomlist]/), QGIS closes without an
error message.

_Question :_
Thus, if a list of several geometries is given in function parameter,
they seems to be corrupted (except the last, or if there is only one
geometry)

Do you have an idea of what happens ? Where is my mistake? Do you see
tests to perform in order to diagnose this issue ? (particularly, why
the last geometry of a list is not corrupted, unlike others ?)

Thanks for advance

Vincent Damoy


_______________________________________________
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>
      <pre wrap="">


</pre>
    </blockquote>
    <br>
  </body>
</html>