[GRASSLIST:495] Re: measure lenght of vector
Radim Blazek
blazek at itc.it
Tue Jun 24 10:08:38 EDT 2003
On Tuesday 24 June 2003 10:18, # Sets domain part of From: and local addresses in outgoing mail. wrote:
> On Tue, 24 Jun 2003, Radim Blazek wrote:
>
> [I have a question: how can I measure the lenght of a segment of a
> vector?]
>
> > What do you mean by 'segment', one line, a part of the line (defined by 2
> > points or start/end offset) or something else?
> > Do you want to measure few segments interactively on monitor or
> > many segments noninteractively?
>
> Sorry if my wording was vague. By ``segment'' I meant the second, a
> fraction of ONE line in a vector map, defined between two points. And
> there is only need to measure a few of them, perhaps interactively. I
> thought of `cropping' the vector map (a shoreline from GMT) by setting the
> region and <vector utility similar to r.resample>, but then how can I
> measure the length of that vector?
5.0:
1) v.digit
Create cutting area for each segment.
In the loop for each segment {
2) v.extract
To get the area for one segment
3) v.cutter
Cut the segment by area.
4) v.report
To get the length.
}
5.1 (devel version):
1) v.digit -n map=pnt
- create new table with columns cat int, id int, along double
- digitize points and assign the same id to each pair defining the segment
2) v.distance from=pnt to=coast upload=to_along column=along
This uploads the distance from the beginning of the line to pnt attribute table.
3) db.select -c sql="select catar, min(along), max(along) from catar_hand_pnt group by catar" \
| gawk -F '|' '{ printf ("L 1 %d %f %f\n",$1,$2,$3) } ' \
| v.segment input=coast output=seg
This creates new vector containing segments.
4) echo "create table seg (cat int, l float)" | db.execute
5) v.db.connect map=seg driver=pg key=cat table=seg
6) v.to.db map=seg option=cat col1=cat
7) v.to.db map=seg option=length col1=l
Oh, its more complicated in 5.1! :-) OK, but it is less work if you have points already as a vector.
Anyway, digitize 2 points is less work than to digitize area with about 7 points.
Radim
More information about the grass-user
mailing list