[GRASS-user] Linear Reference System returns incorrect point locations - help?

Boris.Vasiliev at forces.gc.ca Boris.Vasiliev at forces.gc.ca
Fri Nov 13 12:30:20 EST 2009


Hi,

I am trying to estimate density of events along a road and I thought it
could be done via GRASS.  In particular, I would like to set-up an LRS
system using the road as the line and the end points as mile-posts.
Once LRS is set-up, I could query event positions for their relative
location with respect to the start point and then analyze the
distribution of events per kilometre of the road. 

I am able to create LRS; however, v.lrs.where returns incorrect point
locations.  In particular, suppose LRS is defined on a straight line
with two mile posts:

      -------------------
     ^        ^         ^
 start     mid     end

Here "start" is mile-post 1 and "end" is mile-post 2. When I query the
LRS for position of the "mid" point, v.lrs.where returns

pcat|lid|mpost|offset
 100%
1|1|2.000000+0.000000
[1] points read from input
[1] positions found

which suggests that the "mid" point is located 0 m away from the end
point.  Test code below describes the set-up of the line, nodes, and
LRS. Does any body have any suggestions on what I am doing wrong?

Regards,
Boris.

## create location and default region: centered on Ottawa, ON;
corresponds to UTM, zone 18
# - location
# g.proj -c test.utm.z18 proj4="+proj=utm +zone=18 +ellps=WGS84
+datum=WGS84"
#
# - find Ottawa's UTM coordinates
# echo "75d43'W 45d22'N" | \
#   cs2cs +proj=latlong +ellps=WGS84 +to +proj=utm +zone=18 +ellps=WGS84
# 443877.14	5023933.52 0.00
#
# - create default region: 2x2 km
# g.region -s n=5025000 s=5023000 e=45400 w=43400 nsres=10 ewres=10

# create line a 2km line segment from east to west;
echo -e "L 2 1\n 43400 5024000\n 45400 5024000\n 1 1" | \
  v.in.ascii -n out=mline format=standard --overwrite

# add table to the line; new columns are "cat" and "lid"
v.db.addtable map=mline col="cat integer, lid integer"
v.db.update map=mline col=lid val=1

# extract nodes; add node coordinates and line-id to the table of layer
2
v.to.points -n input=mline output=mline_nds
v.db.addcol map=mline_nds col="x double precision, y double precision,
lid integer" layer=2
v.to.db map=mline_nds option=coor column=x,y layer=2
v.db.update map=mline_nds col=lid val=1 layer=2

# add mile-post and offset columns to point map for LRS system
v.db.addcol map=mline_nds layer=2 \
            col="start_mp double precision, \
                 start_off double precision, \
                 end_mp double precision, \
                 end_off double precision"

# define node order
v.db.update map=mline_nds layer=2 col=start_mp val=1 where="cat=1"
v.db.update map=mline_nds layer=2 col=start_mp val=2 where="cat=2"
  
# create LRS
v.lrs.create in_lines=mline llayer=1 \
             points=mline_nds player=2 \
             out_lines=mline_lrs err=lrs_error \
             lidcol=lid pidcol=lid \
             rstable=mline_rstbl \
             thre=50 --overwrite

# create a point in the centre of the line and query LRS
echo "44400,5024000" | v.in.ascii out=pnt fs=, --overwrite
v.lrs.where line=mline_lrs point=pnt rstab=mline_rstbl

# output
# pcat|lid|mpost|offset
#  100%
# 1|1|2.000000+0.000000
# [1] points read from input
# [1] positions found



More information about the grass-user mailing list