<div class="gmail_quote">On Fri, Oct 8, 2010 at 10:27 AM, Susana Iraiis Delgado Rodriguez <span dir="ltr">&lt;<a href="mailto:susana.delgado_s@utzmg.edu.mx">susana.delgado_s@utzmg.edu.mx</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>Hi Alan:</div>
<div> </div>
<div>The ouput is coming from a cicle and some functions that I vae to do to execute an ogr2ogr command, in this output I ask the user for the name of a file and then make a module to get to the subprocess part:</div>
<div></div></blockquote><div><br></div><div>&lt;snip /&gt;</div><div>  </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>##Eliminate duplicate lines from the txt into a new txt, status:100%<br>
      a = open (&quot;capas.txt&quot;,&quot;r&quot;)<br>      catalogo = open (&quot;unico.txt&quot;,&quot;w&quot;)<br>      unique = set(a.read().split(&quot;\n&quot;))<br>
      catalogo.write(&quot;&quot;.join([line + &quot;\n&quot; for line in unique]))<br>      catalogo.close()<br>      a.close()<br></div></blockquote><div><br></div><div>I don&#39;t see how this is eliminating duplicate lines. To me it looks like it&#39;s just copying the contents of capas.txt into unico.txt and adding extra \n (line breaks), which might be what&#39;s breaking your next line.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div> <br>##Execute ogr2ogr command, status:75%<br>     for line in open(&quot;unico.txt&quot;, &quot;r&quot;):<br>

        p = subprocess.Popen([&#39;C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr&#39;, line+&#39;.shp&#39;, &#39;-where&#39;, &quot;\&quot;LAYER=&#39;&quot;+line+&quot;&#39;\&quot;&quot; , b+&#39;.shp&#39;])<br>  </div>


<div>But when I executed it shows me an error in the layer&#39;s name:</div>
<div><br>&gt;&gt;&gt; ERROR 1: Failed to identify field:LAYER=<br>ERROR 1: Failed to create file .shp file.<br>ERROR 4: Failed to open Shapefile `0<br>.shp&#39;.</div>
<div> </div>
<div>I think the erros showed up because some of the layer&#39;s values are 0 and &#39; &#39;, and obsviously you can&#39;t create a file from nothing on it. But I don`t know how to validate if a layer&#39;s value is equals to 0 or &#39; &#39;, any idea what I&#39;m doing wrong or how to fix it?</div>
</blockquote><div><br></div><div>Also, in your next e-mail, I noticed you&#39;re getting carriage returns (line breaks in your output). Since you&#39;re adding those line breaks above, you want to remove them before using them somewhere else. </div>
<div><br></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div class="gmail_quote"><div>p = subprocess.Popen([&#39;C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr&#39;, line.replace(&quot;\n&quot;, &quot;&quot;) +&#39;.shp&#39;, &#39;-where&#39;, &quot;\&quot;LAYER=&#39;&quot;+ line.replace(&quot;\n&quot;, &quot;&quot;) +&quot;&#39;\&quot;&quot; , b+&#39;.shp&#39;])</div>
</div></blockquote><div class="gmail_quote"><div><br></div><div>In the code above, I&#39;ve changed the references to the variable <i>line</i> so that the \n&#39;s are replaced by 0-length strings. That should remove them from the Popen arguments.</div>
<div><br></div><div>Antonio Rodriguez</div></div>