<div>Besides, If I print the query, I have the next output:</div>
<div><font size="2">
<p align="left">C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr U3B-BARDA</p>
<p align="left">.shp -where "LAYER='U3B-BARDA</p>
<p align="left">'" tapalpa_05_plani_line.shp</p>
<p align="left">C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr N2H-TEMP</p>
<p align="left">.shp -where "LAYER='N2H-TEMP</p>
<p align="left">'" tapalpa_05_plani_line.shp</p>
<p align="left">C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr U3C-CERCA</p>
<p align="left">.shp -where "LAYER='U3C-CERCA</p>
<p align="left">'" tapalpa_05_plani_line.shp..........</p></font>I thought it was a console print issue, but when I run the module from Eclipse, it shows the same enter space, so I think it maybe that the line is not together as it is a statement!!<br>
</div>
<div class="gmail_quote">2010/10/8 Susana Iraiis Delgado Rodriguez <span dir="ltr"><<a href="mailto:susana.delgado_s@utzmg.edu.mx">susana.delgado_s@utzmg.edu.mx</a>></span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<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>
<div>import shlex, subprocess, sys</div>
<div>from dbf import *<br>def process():<br>#Read dbfile status 100%</div>
<div> a = open ("capas.txt","w+")<br> print 'Enter the shapefile name'<br> b = raw_input()<br> print '\n'<br> dbf = Dbf(b+".dbf",new=False)<br> <br> for rec in dbf:<br>
for fldName in dbf.fieldNames:<br> if fldName == 'LAYER':<br> l=()<br> l=rec[fldName]<br> a.write(l)<br> a.write("\n")<br> a.close()<br>
<br>##Eliminate duplicate lines from the txt into a new txt, status:100%<br> a = open ("capas.txt","r")<br> catalogo = open ("unico.txt","w")<br> unique = set(a.read().split("\n"))<br>
catalogo.write("".join([line + "\n" for line in unique]))<br> catalogo.close()<br> a.close()<br> <br>##Execute ogr2ogr command, status:75%<br> for line in open("unico.txt", "r"):
<div class="im"><br> p = subprocess.Popen(['C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where', "\"LAYER='"+line+"'\"" , b+'.shp'])<br>
</div></div>
<div>But when I executed it shows me an error in the layer's name:</div>
<div><br>>>> 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'.</div>
<div> </div>
<div>I think the erros showed up because some of the layer's values are 0 and ' ', and obsviously you can't create a file from nothing on it. But I don`t know how to validate if a layer's value is equals to 0 or ' ', any idea what I'm doing wrong or how to fix it?</div>
<div><br> </div>
<div class="gmail_quote">2010/10/7 Susana Iraiis Delgado Rodriguez <span dir="ltr"><<a href="mailto:susana.delgado_s@utzmg.edu.mx" target="_blank">susana.delgado_s@utzmg.edu.mx</a>></span>
<div>
<div></div>
<div class="h5"><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>Hello taserian and Antonio!</div>
<div> </div>
<div>Thank you both for taking the time to answer my question. With taserian's code it gives me the next output:</div>
<div><font face="courier new,monospace">C... ogr2ogr T21-PUENTESshp -where "LAYER=T21-PUENTES" tapalpa_05_plani_line.shp</font></div>
<div>but the output I need is:</div>
<div><font face="courier new,monospace">C... ogr2ogr T21-PUENTESshp -where "LAYER=' T21-PUENTES' " tapalpa_05_plani_line.shp</font></div>
<div> </div>
<div>I did the Antonio's suggested corrections, and I got the string I wanted, now the problem is that my subprocess doesn't work properly, I'll give a look and see whats wrong with it.</div>
<div> </div>
<div> </div>
<div class="gmail_quote">2010/10/7 taserian <span dir="ltr"><<a href="mailto:taserian@gmail.com" target="_blank">taserian@gmail.com</a>></span>
<div>
<div></div>
<div><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="gmail_quote">
<div>On Thu, Oct 7, 2010 at 12:48 PM, taserian <span dir="ltr"><<a href="mailto:taserian@gmail.com" target="_blank">taserian@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">I'm adding some line breaks to make your text a little more readable.<br><br>
<div class="gmail_quote">On Thu, Oct 7, 2010 at 9:55 AM, Susana Iraiis Delgado Rodriguez <span dir="ltr"><<a href="mailto:susana.delgado_s@utzmg.edu.mx" target="_blank">susana.delgado_s@utzmg.edu.mx</a>></span> wrote:
<div>
<div></div>
<div><br>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>Hello members:</div>
<div> </div>
<div>How can I write a statement to execute the following:</div>
<div></div></blockquote>
<div> </div>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr R1G-GEODESIA.shp -where "LAYER = 'R1G-GEODESIA'" tapalpa_05_plani_point.dbf</div></blockquote>
<div> </div>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>I want my uotput to look like this.</div>
<div>Instead I'm getting this</div></blockquote>
<div> </div>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr T21-PUENTES.shp -where LAYER=+line tapalpa_05_plani_line.shp</div>
<div></div></blockquote>
<div> </div>
<blockquote style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>In miy code line is a string given by the user:</div>
<div> </div>
<div>for line in open("unico.txt", "r").readlines():</div>
<div> p = subprocess.Popen(['C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where', "LAYER='line'", b+'.shp'])</div>
<div> </div>
<div>Any suggestions?</div></blockquote>
<div><br></div></div></div>
<div>Without knowing specifics about what the subprocess.Popen function is expecting as parameters, I can only speculate, but it seems that the following *might* work (for extremely generous values of "*might*"):</div>
<div>
<div><br></div>
<div>
<div>for line in open("unico.txt", "r").readlines():</div>
<div> p = subprocess.Popen(['C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where', "\"LAYER='" + line + "'\"", b+'.shp'])</div>
</div>
<div><br></div></div>
<div>Details about where the changes are:</div>
<div>"\"LAYER='" + line + "'\""</div></div></blockquote>
<div><br></div></div>
<div>Begin corrections (corrections start with a *) </div>
<div>
<div><br></div>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="gmail_quote">
<div></div>
<div>Quote to begin the literal: "</div>
<div>An escaped quote (1) so that there's a quote inside the literal: \"</div>
<div>Some of the text that's meant to be unchanging: LAYER=</div></div></blockquote></div>
<div>*Single Quote (2) to be included in the literal (which doesn't need to be escaped): '</div>
<div>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="gmail_quote">
<div>Close Quote: "</div></div></blockquote>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="gmail_quote">
<div>Add the content of the variable "line" from the unico.txt file: + line +</div></div></blockquote></div>
<div>*Add another literal, composed of the single quote that closes (2) above, then the closing escaped quote to close (1) : "'\"" </div>
<div>
<div> </div>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="gmail_quote">
<div><br></div>
<div>See if this works, and let us know how it turns out.</div>
<div><br></div>
<div>Antonio Rodriguez</div></div></blockquote></div></div>
<div><br></div>
<div>End of corrections.</div><br>
<div>Antonio Rodriguez</div></blockquote></div></div></div><br></blockquote></div></div></div><br></blockquote></div><br>