<html style="direction: ltr;">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body bidimailui-charset-is-forced="true" style="direction: ltr;"
text="#000000" bgcolor="#FFFFFF">
<p>Here's a correction to the format of the "where" clause that
should work:</p>
<p><font size="+1"><tt><br>
</tt></font></p>
<div>
<div><font size="+1"><tt><b>i</b></tt><tt>mport grass.script as
gscript</tt></font></div>
<div><font size="+1"><tt>types = ("primary" , "secondary" ,
"tertiary" , "service" , "pedestrian" , "footway" ,
"residential" , "path")</tt></font></div>
<div><font size="+1"><tt>for typ in types:</tt></font></div>
</div>
<font size="+1"><tt> </tt></font>
<p><font size="+1"><tt> where_str = ("type = '%s'" % typ) <font
color="#3333ff"># Added single quotes around the %s</font></tt><tt><br>
</tt></font></p>
<font size="+1"><tt> </tt></font>
<p><font size="+1"><tt> outrast = "_".join(["type", typ])</tt><tt><br>
</tt></font> </p>
<font size="+1"><tt> </tt></font>
<div><font size="+1"><tt> </tt></font>
<div><font size="+1"><tt><b> </b></tt><tt> gscript.run_command
("v.to.rast",</tt></font></div>
<div><font size="+1"><tt> input = "road_clip", <br>
</tt></font></div>
<div><font size="+1"><tt> type = "line",</tt></font></div>
<div><font size="+1"><tt> where = where_str,</tt></font></div>
<div><font size="+1"><tt> output = outrast,</tt></font></div>
<div><font size="+1"><tt> use = "attr" ,
attribute_column = "cat")</tt></font></div>
</div>
<p><br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 11/11/18 12:02 PM, Alessandro
Sebastiani wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CA+4DhS_BvbfFaV1uCHBcje1EuStN1PqAxDWKbHCJigSkkFzFQA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Hello to everybody ,
<div>i<b> tried with this piece of code, following
suggestios by both:</b></div>
<div># note that for the moment i reduced the street types
to 3</div>
<div>>>>types = ("primary" , "secondary" ,
"tertiary") </div>
<div>>>>for typ in types:</div>
<div>>>>> gscript.run_command ("v.to.rast" ,
input = "road_clip" , type = "line" , where = "type=%s" %
typ , output = ("r"+typ) , use = "attr" , attribute_column
= "cat") </div>
<div><br>
</div>
<div><b>nevertheless, i still get the following error
message</b></div>
<div>
<div>DBMI-SQLite driver error:</div>
<div>Error in sqlite3_prepare():</div>
<div>SELECT cat FROM road_clip WHERE type=primary</div>
<div>near "primary": syntax error</div>
<div>DBMI-SQLite errore del driver:</div>
<div>Error in sqlite3_prepare():</div>
<div>SELECT cat FROM road_clip WHERE type=primary</div>
<div>near "primary": syntax error</div>
<div>ERROR: Impossible to select recod from table
<road_clip></div>
<div>Traceback (most recent call last):</div>
<div> File
"/home/alessandro/Scrivania/script_grass/rast_quer_st</div>
<div>ats_exp.py", line 6, in <module></div>
<div> gscript.run_command ("v.to.rast" , input =
"road_clip" ,</div>
<div>type = "line" , where = "type=%s" % typ , output =
("r"+typ)</div>
<div>, use = "attr" , attribute_column = "cat")</div>
<div> File
"/usr/lib/grass74/etc/python/grass/script/core.py",</div>
<div>line 421, in run_command</div>
<div> return handle_errors(returncode, returncode,
args,</div>
<div>kwargs)</div>
<div> File
"/usr/lib/grass74/etc/python/grass/script/core.py",</div>
<div>line 332, in handle_errors</div>
<div> returncode=returncode)</div>
<div>grass.exceptions.CalledModuleError: L'esecuzione del
modulo</div>
<div>None ['v.to.rast', 'use=attr',
'attribute_column=cat',</div>
<div>'type=line', 'input=road_clip', 'output=rprimary',</div>
<div>'where=type=primary'] è terminata con errori</div>
<div>Processo terminato con codice di return diverso da
zero 1.</div>
<div><br>
</div>
<div><br>
</div>
<div>(Sun Nov 11 10:53:56 2018) Comando terminato (0 sec)</div>
<div> </div>
</div>
<div>I read both error message and my piece of code time
again and again, i was not able to detect what i am doing
wong!</div>
<div><br>
</div>
</div>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr">Il giorno ven 9 nov 2018 alle ore 13:15 Micha
Silver <<a href="mailto:tsvibar@gmail.com"
moz-do-not-send="true">tsvibar@gmail.com</a>> ha scritto:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="direction:ltr" text="#000000" bgcolor="#FFFFFF">
<p>I would do as follows:</p>
<p>(Notice that each street type will become a *separate*
raster)<br>
</p>
<p><br>
</p>
<div class="m_7921939090292762684moz-cite-prefix">On 11/9/18
1:49 PM, Alessandro Sebastiani wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Dear all
<div>i have a vector (downloaded from OpenStreetmap)
with all the streets in my study area. Streets are
divided in categories (there is a specific string
column in the db). now i want to convert to raster
each category separately. I now how to do that
separately, but i was not able to automate that in
a python script. here it is what i wrote:</div>
<div>
<div><b>>>></b>import grass.script as
gscript</div>
<div><b>>>></b>types = ("primary" ,
"secondary" , "tertiary" , "service" ,
"pedestrian" , "footway" , "residential" ,
"path")</div>
<div><b>>>></b>for typ in types:</div>
</div>
</div>
</div>
</div>
</blockquote>
<p> where_str = ("type = %s" % typ)</p>
<p> outrast = "_".join(["type", typ])<br>
</p>
<p> gscript.run_command("v.to.rast",</p>
<p> input = "road_clip", type = "line", where =
where_str,</p>
<p> output = outrast, use="attr",
attribute_column = "cat" )<br>
</p>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div>
<div><b>>>>> </b>
gscript.run_command ("v.to.rast" , input =
"road_clip" , type = "line" , where ="type"=typ
, output = types, use = "attr" ,
attribute_column = "cat").</div>
</div>
<div><b>I got the following traceback:</b> File</div>
<div>"/home/alessandro/GRASSDATA/5_citta_def/5_citt_def/.tmp</div>
<div>/alessandro-Lenovo-G50-70/<a
href="http://5500.6.py" target="_blank"
moz-do-not-send="true">5500.6.py</a>", line 6</div>
<div> gscript.run_command ("v.to.rast" , input =
"road_clip" ,</div>
<div>type = "line" , where ="type"=typ , output =
types, use =</div>
<div>"attr" , attribute_column = "cat")</div>
<div> ^</div>
<div>SyntaxError: invalid syntax</div>
<div><br>
</div>
<div>i guess the syntax error is in the way i set
the query, but i'm not sure. Thanks to everybody,</div>
</div>
</div>
</div>
<br>
<fieldset
class="m_7921939090292762684mimeAttachmentHeader"></fieldset>
<pre class="m_7921939090292762684moz-quote-pre">_______________________________________________
grass-user mailing list
<a class="m_7921939090292762684moz-txt-link-abbreviated" href="mailto:grass-user@lists.osgeo.org" target="_blank" moz-do-not-send="true">grass-user@lists.osgeo.org</a>
<a class="m_7921939090292762684moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/grass-user" target="_blank" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/grass-user</a></pre>
</blockquote>
<pre class="m_7921939090292762684moz-signature" cols="72">--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918</pre>
</div>
</blockquote>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
grass-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/grass-user">https://lists.osgeo.org/mailman/listinfo/grass-user</a></pre>
</blockquote>
<pre class="moz-signature" cols="72">--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918</pre>
</body>
</html>