<div dir="ltr"><p style="margin:0px">Thank you for the fast repplies. Meanwhile I found out that spatialite does not like polygons writen in a multipolygon table... And have been trying to solve that.</p><p style="margin:0px">
<br></p><p style="margin:0px">Anyway, both None and <span style="font-family:arial,sans-serif;font-size:13px">QPyNullVariant(int) works</span><span style="font-family:arial,sans-serif;font-size:13px">, only if the splitted feature has only two parts.</span></p>
<p style="margin:0px"><span style="font-family:arial,sans-serif;font-size:13px"><br></span></p><p style="margin:0px">If  the result has two or more new features I get this error:<br></p><p style="margin:0px"><br></p><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Could not commit changes to layer poligonos<br>Errors: ERROR: 2 feature(s) not added.<br>  Provider errors:<br>      SQLite error: PRIMARY KEY must be unique<br>    SQL: INSERT INTO "poligonos"("geometria","pkuid","filed1","field2","filed3") VALUES (ST_Multi(GeomFromWKB(?, 4326)),?,?,?,?)</blockquote>
<p style="margin:0px"><br></p><p style="margin:0px">I fill function code is bellow.</p><p style="margin:0px"><br></p><p style="margin:0px">Regards,</p><p style="margin:0px"><br></p><p style="margin:0px">Alexandre</p><p style="margin:0px">
<br></p><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="courier new, monospace">    def run(self):<br>
        layer = self.canvas.currentLayer()<br>        provider = layer.dataProvider()<br>        n_of_splitted_features = 0<br>        n_of_new_features = 0<br>        layer.beginEditCommand(QCoreApplication.translate('Multipart split','Split feature(s) parts'))<br>
        # Iterate over all selected feature to find multipart features<br>        for feature in layer.selectedFeatures():<br>            geom = feature.geometry()<br>            # if feature geometry is multipart starts split processing<br>
            if geom != None:<br>                if geom.isMultipart():<br>                    new_features = []<br>                    n_of_splitted_features += 1<br>                    temp_feature = QgsFeature()<br>                    # Get attributes from original feature<br>
                    new_attributes = feature.attributes()<br>                    <br>                    # When attribute is a Primary Key, replace by default value<br>                    ### This is not working well with spatialite provider###<br>
                    for j in provider.pkAttributeIndexes():<br>                        if provider.defaultValue(j):<br>                            new_attributes[j] = provider.defaultValue(j)<br>                        else:<br>
                            new_attributes[j] = QPyNullVariant(int)<br>                            <br>                    temp_feature.setAttributes(new_attributes)<br>                        <br>                    # Get parts geometries from original feature<br>
                    parts = geom.asGeometryCollection ()<br>                            <br>                    # from 2nd to last part create a new features using their<br>                    # single geometry and the attributes of the original feature<br>
                    <br>                    # Convert part to multiType to prevent errors in Spatialite<br>                    for part in parts:<br>                        part.convertToMultiType()<br>                   <br>
                    for i in range(1,len(parts)):<br>                        n_of_new_features += 1<br>                        temp_feature.setGeometry(parts[i])<br>                        temp_feature.geometry().convertToMultiType()<br>
                        new_features.append(QgsFeature(temp_feature))<br>                    # update feature geometry to hold first part single geometry<br>                    # (this way one of the output features keeps the original Id)<br>
                    feature.setGeometry(parts[0])<br>                    layer.updateFeature(feature)<br>                    layer.addFeatures(new_features, False)</font></blockquote></div><div class="gmail_extra"><br><br>
<div class="gmail_quote">On Fri, Aug 30, 2013 at 10:48 AM, Nathan Woodrow <span dir="ltr"><<a href="mailto:madmanwoo@gmail.com" target="_blank">madmanwoo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Have you tried just setting it to None?<span class="HOEnZb"><font color="#888888"><div><br></div><div>- Nathan</div></font></span></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">
On Fri, Aug 30, 2013 at 7:38 PM, Alexandre Neto <span dir="ltr"><<a href="mailto:senhor.neto@gmail.com" target="_blank">senhor.neto@gmail.com</a>></span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">In the multipartsplit plugin [1] I'm trying to solve the primary key (pk) fields problem in postgis and spatialite like in it was done in the splitFeatures() [2]<div>


<br></div><div>I have no problems with Postgis provider, but in spatialite setting pk fields to NULL does not work as I expected, and spatialite does not choose a new non used id by it self. (Making it impossible to commit the changes without manually introduce some id)</div>




<div><br></div><div>In splitFeatures() [2] when a field is in <a href="http://www.qgis.org/api/classQgsVectorDataProvider.html#a6e19d018aa0b88da21fdb9d02c5e8a60" title="Return list of indexes of fields that make up the primary key." style="font-family:monospace,fixed;font-size:9pt;line-height:15px;color:rgb(70,101,162);text-decoration:none" target="_blank">provider.pkAttributeIndexes</a><span style="line-height:15px;font-size:9pt;background-color:rgb(251,252,253);font-family:monospace,fixed">(), </span>but has no default value, the filed is set to empty with this</div>



<div><br></div><div><pre style="line-height:15px;overflow:auto;font-size:9pt;background-color:rgb(251,252,253);margin:4px 8px 4px 2px;font-family:monospace,fixed;word-wrap:break-word;padding:4px 6px;border:1px solid rgb(196,207,229)">

newAttributes[ pkIdx ] = QVariant();</pre></div>
<div><br></div><div>But i'm not being able to use it in my code, since it's says QVariant() can not be instantiated. Actually this is said in here [3]. And it says that Null QVariant() are now converted in <span style="color:rgb(48,48,48);font-family:Verdana,Tahoma,Arial,sans-serif;font-size:12px">QPyNullVariant</span></div>



<div><br></div><div>Can I use <font color="#303030" face="Verdana, Tahoma, Arial, sans-serif"><span style="font-size:12px">QPyNullVariant to keep the pk field empty, so that spatialite automatically choose a adequate int value? How?</span></font></div>



<div><font color="#303030" face="Verdana, Tahoma, Arial, sans-serif"><span style="font-size:12px"><br></span></font></div><div><font color="#303030" face="Verdana, Tahoma, Arial, sans-serif"><span style="font-size:12px">I tried the code bellow but it did not work.</span></font></div>



<div><font face="courier new, monospace"><br></font></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<font face="courier new, monospace"># Get attributes from original feature<br>new_attributes = feature.attributes()<br></font></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<font face="courier new, monospace"># When attribute is a Primary Key, replace by provider default value</font></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">



<font face="courier new, monospace">for j in provider.pkAttributeIndexes():<br>    if provider.defaultValue(j):<br>        new_attributes[j] = provider.defaultValue(j)<br>    else:<br>        new_attributes[j] = QPyNullVariant('int')</font></blockquote>



</div><div><br></div><div><br></div><div>Thanks.</div><div><br></div><div>Alexandre Neto</div><div><br></div><div>[1] <a href="http://plugins.qgis.org/plugins/splitmultipart/" target="_blank">http://plugins.qgis.org/plugins/splitmultipart/</a></div>




<div>[2] <a href="http://www.qgis.org/api/qgsvectorlayereditutils_8cpp_source.html#l00247" target="_blank">http://www.qgis.org/api/qgsvectorlayereditutils_8cpp_source.html#l00247</a></div><div>[3] <a href="http://hub.qgis.org/wiki/quantum-gis/Python_plugin_API_changes_from_18_to_20" target="_blank">http://hub.qgis.org/wiki/quantum-gis/Python_plugin_API_changes_from_18_to_20</a></div>



<div><br></div><div><br></div>
</div>
<br></div></div><div class="im">_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br></div></blockquote></div><br></div>
</blockquote></div><br></div>