<html>
<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>
<style type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body bidimailui-charset-is-forced="true">
<br>
<div class="moz-cite-prefix">On 30/11/2019 16:11, Zoltan Szecsei
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:aeb5119e-c6f2-3ef6-8072-6a56a2b45b70@geograph.co.za">Hi,
<br>
I'm trying to write my first Grass python script to load Shape
files and delete all lines shorter than 50m <br>
I'm trying various permutations of the command below, but no
success (No error message and no lines deleted). <br>
Any guidance would be welcome. <br>
<br>
gscript.run_command('v.extract','r',input=gen,output=lin,
where="( $LENGTH > 50 )",overwrite=True) <br>
gscript.run_command('v.out.ogr', 'sce2', input=lin, type='line',
output=dir_rclout + rcl + '.shp', format='ESRI_Shapefile',
output_type='line',overwrite=True) <br>
<br>
</blockquote>
<p><br>
</p>
<p>The term $LENGTH looks wrong to me.</p>
<p>In python I usually would do something like:</p>
<p><br>
</p>
<p><tt>In [1]: import grass.script as gscript</tt><tt><br>
</tt><tt><br>
</tt><tt>In [4]: where_expr = "%s > %d" % ("'length'", 5000)</tt><tt><br>
</tt><tt><br>
</tt><tt>In [5]: where_expr</tt><tt><br>
</tt><tt>Out[5]: "'length' > 5000"</tt><tt><br>
</tt><tt><br>
</tt><tt>In [6]: gscript.run_command('v.extract', input="roads",
output="roads_long", where=where_expr)</tt><tt><br>
</tt><tt>Data element 'vector/roads' was found in more mapsets
(also found in</tt><tt><br>
</tt><tt><PERMANENT>)</tt><tt><br>
</tt><tt>Using <roads@Arava>...</tt><tt><br>
</tt><tt>Data element 'vector/roads' was found in more mapsets
(also found in</tt><tt><br>
</tt><tt><PERMANENT>)</tt><tt><br>
</tt><tt>Using <roads@Arava>...</tt><tt><br>
</tt><tt>Extracting features...</tt><tt><br>
</tt><tt> 100%</tt><tt><br>
</tt><tt>Building topology for vector map
<roads_long@Arava>...</tt><tt><br>
</tt><tt>Registering primitives...</tt><tt><br>
</tt><tt>Writing attributes...</tt><tt><br>
</tt><tt>Out[6]: 0</tt><br>
<br>
</p>
<p>Note the quoting around the column header "length": One double
quote and one single quote. The inner single quote is for the SQL
expression.</p>
<p><br>
</p>
<p>Cheers, Micha<br>
</p>
<blockquote type="cite"
cite="mid:aeb5119e-c6f2-3ef6-8072-6a56a2b45b70@geograph.co.za">Thanks
and regards, <br>
Zoltan <br>
PS: Should these type of questions go to grass-dev ?? <br>
<br>
</blockquote>
<pre class="moz-signature" cols="72">--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918
<a class="moz-txt-link-freetext" href="https://orcid.org/0000-0002-1128-1325">https://orcid.org/0000-0002-1128-1325</a></pre>
</body>
</html>