[GRASS-user] SQL query in Python script
Anna Petrášová
kratochanna at gmail.com
Sun Nov 30 14:12:04 PST 2014
On Sun, Nov 30, 2014 at 4:33 PM, Charlie Shobe <Charles.Shobe at colorado.edu>
wrote:
> I have managed to figure it out, and I'm sharing the solution to hopefully
> clear up confusion for other beginners like myself. When specifying an SQL
> query for GRASS in Python, correct syntax in this case is:
>
> where=""""dir"<0"""
>
> Meaning, the entire expression should be enclosed in 3 quotation marks,
> and the names of any columns or attributes should be enclosed in a set of
> quotes as well. A number such as 0 requires to quotation marks.
>
> I hope this helps someone avoid my confusion.
>
> Charlie
>
> On Sun, Nov 30, 2014 at 12:21 PM, Charlie Shobe <
> Charles.Shobe at colorado.edu> wrote:
>
>> Hi all,
>>
>> I am attempting to extract a subset of points from a points vector based
>> on the values in the column "dir". I am running GRASS 6.4.4 on Mac OS
>> 10.9.5.
>>
>> In the GRASS command line, I can successfully make my selection with the
>> following command:
>> --------------------------------------------------------------
>> GRASS 6.4.4 (Yellowstone):~ > *v.extract input=streams_points
>> output=outlets_vect type=point where="dir<0"*
>>
>
I can run similar command in GRASS 7 with sqlite backend without problems:
grass.run_command('v.extract', input='bridges at PERMANENT',
where="width>150", output='bridges_extract')
perhaps try with sqlite if you don't use it already? Is it possible that
the column name "dir" contains the quotes?
Anna
>>
>> 92 categories loaded from table <streams_points>
>>
>> Extracting features...
>>
>> Building topology for vector map <outlets_vect>...
>>
>> Registering primitives...
>>
>> 92 primitives registered
>>
>> 92 vertices registered
>>
>> Building areas...
>>
>> 100%
>>
>> 0 areas built
>>
>> 0 isles built
>>
>> Attaching islands...
>>
>> Attaching centroids...
>>
>> 100%
>>
>> Number of nodes: 92
>>
>> Number of primitives: 92
>>
>> Number of points: 92
>>
>> Number of lines: 0
>>
>> Number of boundaries: 0
>>
>> Number of centroids: 0
>>
>> Number of areas: 0
>>
>> Number of isles: 0
>>
>> Writing attributes...
>>
>> v.extract complete.
>>
>> -------------------------------------------------------
>> However, due to my incomplete knowledge of how Python and SQL interact, I
>> am having trouble executing the same command in a Python script. Here is
>> what I am trying:
>>
>> *g.run_command("v.extract", input="streams_points",
>> output="outlets_vect", type="point", where="dir<0")*
>>
>> When I run this command, it fails to extract any points. I know that this
>> must be due to some problem with the syntax of my SQL statement.
>>
>> Can anyone clear this up for me?
>>
>> Thanks,
>>
>> Charlie
>>
>
>
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20141130/33e308a1/attachment.html>
More information about the grass-user
mailing list