Hi Martin,<br><br>Thank you very much, this is exactly what i needed...<br>However, you were right...the truncation seems to be a limitation of the OGR driver/Mapinfo Format.<br><br>Thanks again,<br><br clear="all">Romain,<div>
<i><br></i></div><br>
<br><br><div class="gmail_quote">2011/7/19 Martin Dobias <span dir="ltr">&lt;<a href="http://wonder.sk">wonder.sk</a>@<a href="http://gmail.com">gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Romain<br>
<br>
On Sun, Jul 17, 2011 at 11:23 PM, romain &lt;<a href="mailto:romain.riviere.974@gmail.com">romain.riviere.974@gmail.com</a>&gt; wrote:<br>
&gt; Sorry, I think i haven&#39;t explained well what I want.<br>
&gt;<br>
&gt; I know how to get my fields&#39; lengths from SpatiaLite.<br>
&gt;<br>
&gt; Here is what I&#39;ve already done:<br>
&gt; 1/ create QgsvectorLayer from spatiaLite table : vlayer<br>
&gt; 2/ strore field&#39;s length in a python list: lengths<br>
&gt;<br>
&gt; One of my text fields (FIELD1) have 300 characters....<br>
&gt;<br>
&gt;<br>
&gt; What my problem is when i want to save the layer as mapinfo file with :<br>
&gt;<br>
&gt; QgsVectorFileWritter.writteAsFromat(vlayer,........,mapinfo)<br>
&gt;<br>
&gt; -&gt; The mapinfo File is created but all the fields are truncated at 254<br>
&gt; char.... So, I lost informations on FIELD1...<br>
<br>
There is one more way how to use QgsVectorFileWriter:<br>
1. construct QgsVectorFileWriter object<br>
2. call addFeature() for each feature you want add<br>
3. delete the writer object (in order to save changes)<br>
<br>
This is essentially what writeAsFormat() function does. But using the<br>
above approach has more flexibility: in the constructor you pass a map<br>
of fields - so instead of using input layer&#39;s field definitions you<br>
could change them and set higher (or lower) length, rename some fields<br>
etc.<br>
<br>
<br>
&gt; I&#39;ve tried to set fields lengths for my layer, in order to avoid truncature,<br>
&gt; but, it doesn&#39;t change anything:<br>
&gt;<br>
&gt; fields=vlayer.dataProvider().fields()<br>
&gt; for field in fields:<br>
&gt;      fields[field].setLength(301)<br>
<br>
This will not work because you are changing the length only of the<br>
local object: this change will not get back to the provider.<br>
<br>
<br>
&gt; The only thing I need is to pass an option to Qgsvectorfilewritter to change<br>
&gt; fields maximum characters...<br>
&gt; Does anybody know how to do this directly with OGR ? (within python, of<br>
&gt; course)<br>
<br>
Another problem could be that the truncation is a limitation of the<br>
format or OGR driver...<br>
<br>
Regards<br>
<font color="#888888">Martin<br>
</font></blockquote></div><br>