<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
ahh, now we're closing in on it.<br>
<blockquote><tt>"\"LAYER=' "+line+"\' " </tt><br>
</blockquote>
should be (spaces added for easier reading):<font face="courier
new,monospace"><br>
</font>
<blockquote><tt><font color="#cc0000">'</font> "LAYER=<font
color="#cc0000">'</font> + line + <font color="#cc0000">'</font>
" <font color="#cc0000">'</font></tt><br>
</blockquote>
however there is a way to write this which is not so hard to pick
apart in your head: using the % substition operator. In the
following <i>%s </i>is changed to value of <i>line </i>when
interpreted.<br>
<br>
<tt>>>> line = 'T21-PUENTES'<br>
>>> query = <font color="#cc0000">'</font>-where
"LAYER=\'<font color="#009900">%s</font>\' " <font
color="#cc0000">'</font> % (<font color="#009900">line</font>)<br>
>>> print query<br>
-where "LAYER='T21-PUENTES'"</tt><br>
<br>
Sometimes it helps to use the string replace method to temporarily
use a character other than a quote when building the expression
(produces identical results).<br>
<tt><br>
>>> query = <font color="#cc0000">"</font>-where
#LAYER='%s'#</tt><tt><font color="#cc0000">"</font></tt><tt> %
(line)<br>
>>> query = </tt><tt>query<font color="#009900">.replace</font>('<font
color="#009900">#</font>','<font color="#009900">"</font>')</tt><br>
<tt>>>> print query<br>
-where "LAYER='T21-PUENTES'"</tt><br>
<br>
So to wrap it up altogether:<br>
<br>
<small><font face="Courier New, Courier, monospace">ogr2ogr =
'C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe'<br>
line = 'T21-PUENTES'<br>
b = 'tapalpa_05_plani_line'<br>
inshape = line + '.shp'<br>
outshape = b + '.shp'<br>
query = "-where #LAYER='%s'#" % (line)<br>
query = query.replace('#','"')<br>
print ogr2ogr, inshape, query, outshape<br>
# p = subprocess.Popen([ogr2ogr, inshape, query, outshape])<br>
</font></small><br>
<br>
<br>
<pre class="moz-signature" cols="72">matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
<a class="moz-txt-link-freetext" href="http://environmentyukon.gov.yk.ca/geomatics/">http://environmentyukon.gov.yk.ca/geomatics/</a>
-------------------------------------------- </pre>
<br>
On 07/10/2010 11:05 AM, Susana Iraiis Delgado Rodriguez wrote:
<blockquote
cite="mid:AANLkTimnM5V0WYGicEY8UPLH=Mg2srK5wJVce7ifoRkN@mail.gmail.com"
type="cite">
<div>Hello Matt!</div>
<div>Thank you for your advice, but see the problem is that I
cannot read the value from the variable line, it shuold be
something like +line+. </div>
<div>The code you suggested is telling the subprocess to read line
as string "line" instead of execuitng the query, same will
happen with the other script. I almost got to the answer:</div>
<div> </div>
<div><font face="courier new,monospace">print 'C:/Archivos de
programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', '-where',
"\"LAYER=' "+line+"\' ", b+'.shp'</font></div>
<div> </div>
<div>I'm doing a print to see the ouput before it executes the
command, now mi output sentence is: <font face="courier
new,monospace">C:/Archivos de
programa/FWTools2.4.7/bin/ogr2ogr T21-PUENTES<br>
.shp -where "LAYER='T21-PUENTES' tapalpa_05_plani_line.shp</font></div>
<div> </div>
<div><font face="arial,helvetica,sans-serif">I`m missing a (")
after it gets the value of line. I don't know how to close the
statement</font></div>
<div> </div>
<div>Regards</div>
<div> <br>
</div>
<div class="gmail_quote">2010/10/7 Matt Wilkie <span dir="ltr"><<a
moz-do-not-send="true" href="mailto:matt.wilkie@gov.yk.ca">matt.wilkie@gov.yk.ca</a>></span><br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204);
margin: 0px 0px 0px 0.8ex; padding-left: 1ex;"
class="gmail_quote">
<div text="#000000" bgcolor="#ffffff">Hi Susana,<br>
<br>
You're missing the beginning single quote (') before
C:/Archivos.... and I don't think you need to escape the
inner double quote ("), so instead of<br>
<blockquote><tt>'\"LAYER= \'line\'\"'</tt><br>
</blockquote>
try<font face="courier new,monospace"><br>
</font>
<blockquote><tt>'"LAYER=\'line\'"'</tt><br>
</blockquote>
Also it would be easier to read the code if you did
something like:<br>
<br>
<tt>ogr2ogr = 'C:/Archivos de
programa/FWTools2.4.7/bin/ogr2ogr'<br>
inshape = line + '.shp'<br>
outshape = b + '.shp'<br>
query = '-where "LAYER=\'line\'" '<br>
<br>
p = subprocess.Popen([ogr2ogr, inshape, query, outshape])</tt><br>
<br>
hope that helps,<br>
<pre cols="72">matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
<a moz-do-not-send="true" href="http://environmentyukon.gov.yk.ca/geomatics/" target="_blank">http://environmentyukon.gov.yk.ca/geomatics/</a>
-------------------------------------------- </pre>
<div>
<div class="h5"><br>
On 07/10/2010 9:19 AM, Susana Iraiis Delgado Rodriguez
wrote:
<blockquote type="cite">
<div>Hello members!</div>
<div> </div>
<div>I'm running a python script to execute an ogr2ogr
command. The process has been sucessful, but now I
want to create a shp for each layer a shp has. I
now I must use the command :</div>
<div><font face="Courier New" size="2">ogr2ogr
newX.shp -where "LAYER = 'layerValueX'"
original.shp</font></div>
<div><font face="arial,helvetica,sans-serif">The code
for the subprocess is as follows:</font></div>
<div><font face="courier new,monospace">for line in
open("unico.txt", "r").readlines():<br>
p = subprocess.Popen([C:/Archivos de
programa/FWTools2.4.7/bin/ogr2ogr', line+'.shp', </font></div>
<div><font face="courier new,monospace">' -where',
'\"LAYER= \'line\'\"', b+'.shp'])</font><font
face="arial,helvetica,sans-serif">unfortuanely
wtih this code the module reads the variable line,
which as the value of the layer has a string
"line": The problem is located after the word
LAYER, I don't have idea about the properly way to
write the quotes.</font></div>
<div> </div>
<div>Hope you can help, regards!</div>
<p style="color: rgb(0, 0, 0);"><br>
</p>
</blockquote>
</div>
</div>
</div>
<br>
_______________________________________________<br>
FWTools mailing list<br>
<a moz-do-not-send="true"
href="mailto:FWTools@lists.maptools.org">FWTools@lists.maptools.org</a><br>
<a moz-do-not-send="true"
href="http://lists.maptools.org/mailman/listinfo/fwtools"
target="_blank">http://lists.maptools.org/mailman/listinfo/fwtools</a><br>
<a moz-do-not-send="true" href="http://fwtools.maptools.org/"
target="_blank">http://fwtools.maptools.org/</a><br>
<br>
</blockquote>
</div>
<br>
</blockquote>
</body>
</html>