[GRASS-user] [vector attribute query]

Moritz Lennert mlennert at club.worldonline.be
Thu Mar 16 05:37:03 PDT 2017


On 16/03/17 12:36, Ang Sherpa wrote:
> Hello users,
>
> Is it possible to query according to coordinates and return the value of
> desired column from attribute table as result.
>
> v.what allows to query the map, however, could not figure out how to
> choose the column in attribute table.
>
> Eg. In a world shape file  having "population" as one of its column in
> attribute table.
> when 25.36258,85.236554 is entered in coordinates then it should return
> the population of that country in which the given coordinates belongs to.
>
> Any help will be much appreciated.

It depends on the language in which you are working.

In a bash shell, using the NC demo dataset, here's how you can get the 
name of a specific county which is in the NAME column of the attribute 
table:

eval $(v.what -ga boundary_county coordinates=498364.930178,229163.426556)
echo $NAME

In python, you can use parse_command to get a dictionary of results:

result = gscript.parse_command('v.what', flags='ga', 
map='boundary_county', coordinates=[498364.930178,229163.426556])
result['NAME']

Moritz


More information about the grass-user mailing list