[GRASS-user] v.in.ogr where-clause not working

gisfisch at t-online.de gisfisch at t-online.de
Mon Jan 23 07:21:51 PST 2023


Hello Micha and list,

thank you for the answer.
The double quotes did not work. But when I tried, it suddenly became clear what could be the problem. You could not see that in my example. I use a directory as input, containing one shapefile with boundaries and one with centroids (goal: create area vector map). Only the boundaries have the attribute LENGTH. So it cannot be found in the centroids, and that is the reason for that message.
I wonder why it worked in the old GRASS/PYTHON? There was a message that the 'where' clause is only applied to the first input layer which is the boundary shapefile named 'arc.shp' (starts with a, so probably it is the first). This must have changed in GRASS78.

I used this and was happy with it because I need to import those shapes and create a vector map out of them. Now, I think I will have to import them in two steps (only one with 'where')  and put them together in GRASS. Is 'v.patch' followed by 'v.build' a good way or is there a better straightforward way?

Thank you and best regards,

Uwe


-----Ursprüngliche Nachricht-----
Von: Micha Silver <tsvibar at gmail.com> 
Gesendet: Sonntag, 22. Januar 2023 21:40
An: gisfisch at t-online.de; grass-user at lists.osgeo.org
Betreff: Re: [GRASS-user] v.in.ogr where-clause not working

Hi


On 22/01/2023 14:42, gisfisch at t-online.de wrote:
>
> Hello list,
>
> I have problems with v.in.ogr in a python script; I use:
>
> /grass.run_command('v.in.ogr',input='d:/my_input',output='my_output',t
> ype='boundary,centroid',where='LENGTH
> != 1',snap=0.01,min_area=0.01,flags="o",overwrite=True)/
>
> This has been working fine for years in GRASS 7.0.3 with Python 2.
>
> Now, I tried in GRASS 7.8 on Python 3 and I get the following error:
>
> ERROR 1: "LENGTH" not recognised as an available field.
>
> FEHLER: Error setting attribute filter 'LENGTH != 1'
>
> The field called LENGTH is present and there is no typing error. What 
> I absolutely not understand is that the command is working fine inside 
> GRASS itself! Just the Python script does not.
>

Can you try to create the where clause with double quotes before calling grass.run_command? Like so:


expr = '"LENGTH != 1"'

grass.run_command('v.in.ogr', input='...', output='...', where=expr, 
type='...', .....)


> „LENGTH“ is not a Python reserved keyword, and no SQL reserved 
> keyword. I also tried it with another name for that column. That also 
> did not work.
>
> Any ideas what could be wrong? Thank you very much.
>
> Uwe
>
>
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user

-- 
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918



More information about the grass-user mailing list