|
I use a few GRASS procedures to snap points to a line (i.e. snap
gauges to a stream network) as follows: # Add columns to the stations vector for snapped_x and snapped_y and get coordinates echo -e "\n** Snapping stations to streams **" v.db.addcolumn --q map=$POINTS columns="snap_x double, snap_y double" # Temporatily change region stations input vector, and get snap coords # so that all stations get the correct snap coords - even those outside current domain v.distance --q --o from=stations to=streams output=connectors upload=to_x,to_y column=snap_x,snap_y # Create a new stations vector with the snap_x and snap_y columns g.remove -f vect name=frxst_pts # Use v.out.ascii with -r option to export only drainage point in current region (domain) # snap_x and snap_y columns become the X-Y coordinates for frxst_pts point vector v.out.ascii --q -r -c stations columns="id,station_name,station_num,longitude,latitude,snap_x,snap_y" separator=comma | v.in.ascii --q --o input=- output=frxst_pts x=8 y=9 cat=3 columns="east double,north double,id integer,station_name text,station_num integer,longitude double,latitude double,snap_x double,snap_y double" separator=comma skip=1 The crux of the above commands is the "v.distance" line. This command checks the distance from each point to the line, and uploads to the line vector the x-y coordinates of intersection. This distance is the length of the perpendicular from the point to the line. Then the last command "v.in.ascii ... | v.out.ascii ..." takes those point coordinates, and exports to a new point vector. The problem with the PostGIS function ST_ClosestPoint is that it finds the closest vertex that *already exists* on the line feature. So if one of the points is near to a straight line segment, the chosen vertex might be actually far from the point. HTH, On 06/30/2016 03:18 PM, Tyler Veinot
wrote:
|
_______________________________________________ Qgis-user mailing list [email protected] List info: http://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
