Hi,
I need to extract, from a vector points file, a subset of points, according to the IDs listed (after a sort) in another ASCII files, "indexes".
I thought it was a good idea to create a proper ASCII file containing
ID east north
of the entire data set (using v.out.ascii, awk and sort) and then use the coreutils "join" to find the matches.
Unfortunately, join works in a weird ways when the join field is numerically and the numbers, even if sorted (!), have different lengths.
What I mean is this:
if all the IDs have the same length (example: 2 digits), then join works perfectly; while if I have the following indexes list:
1
2
8
10
12
then join passes to analyze 10 and 12 only after having analyzed 8!
I tried a different sorting, for example
1
10
12
2
8
and so things improve, but still some mistakes are obtained.
How can I fulfill my purpose?
Maybe I could use an SQL query, if Grass DBF driver support the clause "IN", meaning
select * from dataset where "cat IN {1,2,8,10,12}" ??
Thanks for your help,
Damiano
Damiano Triglione wrote:
Hi,
I need to extract, from a vector points file, a subset of points, according to the IDs listed (after a sort) in another ASCII files, "indexes".
v.extract can take a file of ids to extract like this:
v.extract input=map output=extracted file=file_with_ids new=-1
from this new vector extracted, you should be able to get what info you want.
--Wolf
--
<:3 )---- Wolf Bergenheim ----( 8:>
--
<:3 )---- Wolf Bergenheim ----( 8:>
Damiano Triglione wrote:
Hi,
I need to extract, from a vector points file, a subset of points,
according to the IDs listed (after a sort) in another ASCII files,
"indexes". I thought it was a good idea to create a proper ASCII file
containing ID east north
of the entire data set (using v.out.ascii, awk and sort) and then use
the coreutils "join" to find the matches.
Did you try "sort -n"?
Unfortunately, join works in a weird ways when the join field is
numerically and the numbers, even if sorted (!), have different
lengths. What I mean is this:
if all the IDs have the same length (example: 2 digits), then join
works perfectly; while if I have the following indexes list:
1
2
8
10
12
then join passes to analyze 10 and 12 only after having analyzed 8!
I tried a different sorting, for example
1
10
12
2
8
Hamish
OK, I'll have a look at v.out.ascii.db: it will be, also, a good occasion to refresh my knowledge about unix shell scripts!
Thank you very much,
Damiano
----- Original Message ----- From: "Hamish" <hamish_nospam@yahoo.com>
To: "Damiano Triglione" <damiano.triglione@polimi.it>
Sent: Friday, January 26, 2007 12:25 AM
Subject: Re: [GRASS-dev] Extracting a subset from a set of (vector) points
Damiano Triglione wrote:
Yes, I tried -n, and other options (-d and -g) available in sort, but
none of them gives the optimal result!
It's strange: it's like join can work properly only for numerical
fields that are sorted in "two ways simultanously" (numerical and
lexicographical) but... this is impossible (if the field can change
dimension), so it never works perfectly in the cases I am interested
in! I succeded in solving my problem using the Grass command
"v.extract", but I have still the intellectual interest in finding
out how to exploit "join". I thought it was a bug of an old version,
but also in recent version join works in the same weird way... Maybe
I should try the latest version.maybe have a look at the v.out.ascii.db shell script (wiki add-ons)
I used "join" there, and it works.
Hamish