[GRASS-user] NEWBIE: Help with simple network analysis
andrew.haywood at poyry.com
andrew.haywood at poyry.com
Wed Aug 2 03:23:10 EDT 2006
Dear all,
I am a new person to grass and am having some problems with running a
simple network analysis. If anybody can help me it would be greatly
appreciated. I am running grass 6.0 on debian.
I have imported a shapefile representing 5km grid polygons across a large
area. I have also imported a road shapefile within this grid. And have
imported a point shapefile with town locations close to this road
(network).
What I would like to do for each centroid of my 5km grid polygon layer is
to calculate the nearest straight line distance to the road feature. Once
having calculated this distance - calculate the distance along the road
network to each town. Below is my attempt at doing this. Any
help/suggestions on improvement would be greatly appreciated.
I am having problems making sure that my town locations are on my road
network and that the road network is complete. I think that the road
network is made up of line segments that are not quite connected so I have
tried v.clean to "buffer the roads toegther". Any suggestions on how to
ensure that the lines are connected would be greatly appreciated. The
following are a list of commands that I am currently using. My problem is
that my network is not connected.
#v.in.ogr dsn=/home/andrew/rast.shp output=rast min_area=0.0001 snap=-1
#v.in.ogr dsn=/home/andrew/road_seg.shp output=road_seg min_area=0.0001
snap=-1
#v.in.ogr dsn=/home/andrew/towns.shp output=towns min_area=0.0001 snap=-1
I then try and convert the road segments into connected lines
v.build.polylines input=road_seg output=road
I then try and intersect the towns and the roads together
v.patch in=road,towns out=road_towns
I then connect the towns and the roads
v.distance -p from=towns to=road output=road_towns_connect upload=dist
column=dist
#patch connecting line with roads and towns
v.patch in=road_towns_connect,road_towns out=pre_network_road_towns
v.db.connect road_towns dr=dbf
data='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/' table=road layer=1 key=cat
v.db.connect road_towns dr=dbf
data='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/' table=towns layer=2 key=cat
v.clean in=pre_network_road_towns out=network_road_towns tool=break,snap
#add columns to rast polygon
echo "ALTER TABLE rast ADD COLUMN from_cat integer" | db.execute
echo "ALTER TABLE rast ADD COLUMN dist double" | db.execute
echo "ALTER TABLE rast ADD COLUMN to_x double" | db.execute
echo "ALTER TABLE rast ADD COLUMN to_y double" | db.execute
#need to run distance command
v.distance from=rast to=network_road_towns from_type=centroid to_type=line
from_layer=1 to_layer=1 dmax=-1 upload=cat,dist,to_x,to_y
column=from_cat,dist,to_x,to_y
#spit out to_x to_y coordinates of intersection with network_towns_points
v.db.select map=rast layer=1 fs="|" -c > xy_info_on_network
#spit x and y corrdinates of intersection to a flatfile
awk < xy_info_on_network -F"|" '{ print $9,$10}' > xy_on_network
#remove duplicates in file (I think there are ??? points in the
intersection)
sort xy_on_network > xy_on_network_sort
uniq xy_on_network_sort > xy_on_network_uniq
v.out.ascii input=towns output=xy_towns format=point
I then sucked the points of intersection with the road network
(xy_on_network_uniw) and the town locations (xy_towns) into a perl script
and spat out a big file that looked like this to loop through each raster
centroid intersection with the network and the location of the town.
echo "1 574705.304072 9192756.736556 574705.30421218 9192756.73643771 " |
v.net.path network_road_points out=mypath nlayer=1
v.db.select map=mypath layer=1 fs='|' >>fun
g.remove vect=mypath
echo "2 574705.304212 9192756.736438 574705.30421218 9192756.73643771 " |
v.net.path network_road_points out=mypath nlayer=1
v.db.select map=mypath layer=1 fs='|' >>fun
g.remove vect=mypath
...
...
...
when I run this i get errors (on some but not all v.net.path calls)
basically saying that the node cannot be found and reports a very big
distance as a default. I have started to look at the network and i think
it is because I havent closed it properly. Any help with regard to this.
Also im thinking that it may be the accuracy of the xy locations in ascii
dumps. Im not sure if I could use node id's and that would be better.
Again any suggestions would be appreciated.
cheers
Andy
This email and any files transmitted with it are confidential, may be legally privileged and are intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient, you are hereby notified that any use, distribution, or reproduction of the contents of this email is strictly prohibited and may be unlawful. If you are not the intended recipient, please notify the sender by return email and destroy all copies of the original message including any attachments thereto.
Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20060802/d53256c0/attachment.html
More information about the grass-user
mailing list