[GRASS-user] Looping through features...
Moritz Lennert
mlennert at club.worldonline.be
Sun Jul 20 17:26:27 EDT 2008
On 20/07/08 20:48, Jonathan Greenberg wrote:
> Grass users:
>
> I was hoping to get a jump start on an analysis that requires that I
> perform a set of processes by looping through a set of poly features. My
> question is -- does anyone have an example of how to do this in GRASS
> (via bash scripting):
>
> for i = 1, number of features in coverage
> extract feature i to a temporary file
> do something to feature i
> end for loop
>
> Vague enough? My main issue is that I don't know how to query the
> number of features to begin the loop in a way that's usable to bash.
Example if the features you are looking for are centroids:
num_centroids=`v.info -t MapName | grep centroids | cut -d"=" -f2`
(note the backticks)
But I'm not sure if this is really what you need, as you cannot use the
i in your example to identify the features. What you probably need is
the list of category values, i.e. something like:
for cat in `v.category MapName option=print type=centroid`
do
v.extract ... list=$cat ...
do what you want with this feature
done
But this only deals with features which actually have category values
attached to them. If you need to reach all features in a map, you might
be able to do this with v.edit with something like this:
eval `v.info -g MapName`
v.edit MapName tool=select bbox=$west,$north,$east,$south
Hope that this is enough for a "jump start"...
Moritz
More information about the grass-user
mailing list