![]() |
![]()
| ![]() |
![]()
NAMEv.distance - Finds the nearest element in vector map ’to’ for elements in vector map ’from’. KEYWORDSvector, distance, database, attribute table SYNOPSISv.distance
Flags:
Parameters:
DESCRIPTIONv.distance finds the nearest element in vector map (to) for elements in vector map (from). Various information about the vectors’ relationships (distance, category, etc.) may be uploaded to the attribute table attached to the first vector map, or printed to ’stdout’. A new vector map may be created where lines connecting nearest points on features are written. dmin and/or dmax can be used to limit the search radius (in lat-long projects to be given in meters since they are calculated as geodesic distances on a sphere). For lines to lines, say line A to line B, v.distance calculates the shortest distance of each vertex in A with each segment (not vertex) in B. The module then calculates the shortest distance of each vertex in B to each segment in A. The overall shortest distance of A points to B segments and B points to A segments is used. Additionally, v.distance checks for intersections. In case of intersections, the first intersection found is used and the distance set to zero. For lines to areas, the distance is set to zero if a line is (partially) inside an area. The first point of the line that is inside the area is used as common point. The distance is also set to zero if the line intersects with the outer ring or any of the inner rings (isles), in which case the fist intersection is used as common point. For areas to areas, the module checks first for overlap or if one area is (partially) inside the other area. This is computationally quite intensive. If the outer rings of the two areas do not overlap, the distance is calculated as above for lines to lines, treating the outer rings as two lines. Again, the first point encountered falling into an area is used as common point, or the first intersection point. For anything else than points to lines, there can be several common locations with zero distance, and the common location would then be the result of an overlay consisting of several points, lines, or areas. v.distance selects in these cases a single point, and does not create an overlay like v.overlay. In this implementation, any shared point is as good as any other. Calculating an intersection is costlier than to check if a vertex is inside a polygon. For example, if a vertex of the boundary of the ’to’ area is inside the ’from’ area, it is a common location. For speed reasons, the distance is then set to zero and no further tests are done. NOTESIf a nearest feature does not have a category, the attribute column is updated to NULL. The upload column(s) must already exist. Create one with v.db.addcolumn. In lat-long projects v.distance gives distances (dist, from_along, and to_along) not in degrees but in meters calculated as geodesic distances on a sphere. If one or both of the input vector maps are 3D, the user is notified accordingly. The -p flag prints the results to standard output. By default the output is in form of a linear matrix. If only only variable is upploaded and a square matrix is desired, the user can set the -s flag. EXAMPLESFind nearest linesFind nearest lines in vector map "ln" for points
from vector map "pnt" within the given threshold and write related
line categories to column "linecat" in an attribute table attached
to vector map "pnt":
v.distance from=pnt to=ln upload=cat column=linecat Find nearest areaFor each point from vector map "pnt", find the
nearest area from map "ar" within the given threshold and
write the related area categories to column "areacat" in an
attribute table attached to vector map "pnt" (in the case that a
point falls into an area, the distance is zero):
v.distance from=pnt to=ar upload=cat column=areacat Create a new vector mapCreate a new vector map which contains lines connecting
nearest features of maps "pnt" and map "ln".
The resulting vector map can be used for example to connect points to a
network as needed for network analysis:
v.distance from=pnt to=ln out=connections upload=dist column=dist Create a new vector map with from and to categories in the attribute tableCreate a new vector map that contains lines connecting
nearest features of maps "pnt" and map "ln",
and a new attribute table that contains distances, from and to categories
from the input maps:
v.distance from=pnt to=ln out=connections upload=cat,dist column=to_cat,dist table=connections Query informationQuery information from selected point(s). v.distance takes points from a vector map as input instead of stdin. A new vector map with query points has to be created before the map can be analysed. Create query map (if not present):
echo "123456|654321|1" | v.in.ascii output=pntFind nearest features: v.distance -p from=pnt to=map_to_query upload=cat Point-in-polygonThe option dmax=0 is here important because otherwise for
points not falling into any area, the category of the nearest area is
recorded.
v.distance from=pnt to=ar dmax=0 upload=cat column=areacat Univariate statistics on resultsCreate a vector map containing connecting lines and investigate
mean distance to targets. An alternative solution is to use the v.distance
upload=dist option to upload distances into the bugs vector directly,
then run v.univar on that. Also note you can upload two columns at a time,
e.g. v.distance upload=cat,dist column=nearest_id,dist_to_nr.
# create working copy g.copy vect=bugsites,bugs # add new attribute column to hold nearest archsite category number v.db.addcolumn map=bugs column="nrst_arch INTEGER" v.distance from=bugs to=archsites to_type=point upload=to_attr \ Print distance between pointsExample for a Latitude-longitude project (EPSG 4326):
# points along the equator echo "0|-61|1" | v.in.ascii output=pnt1 input=- echo "0|-58|1" | v.in.ascii output=pnt2 input=- # here, distances are in degree units v.distance -p --q from=pnt1 to=pnt2 upload=dist from_cat|distance 1|3 Print distance matrixNorth Carolina sample data As linear matrix:
v.distance -pa from=hospitals to=hospitals upload=dist,to_attr to_column=NAME separator=tab from_cat to_cat dist to_attr 1 1 0 Cherry Hospital 1 2 7489.1043632983983 Wayne Memorial Hospital 1 3 339112.17046729225 Watauga Medical Center 1 4 70900.392145909267 Central Prison Hospital 1 5 70406.227393921712 Dorothea Dix Hospital As square matrix (only possible with single upload option):
v.distance -pas from=hospitals to=hospitals upload=dist separator=tab from_cat to_cat dist SEE ALSOr.distance, v.db.addcolumn, v.what.vect AUTHORSJanne Soimasuo 1994, University of Joensuu, Faculty of Forestry,
Finland
SOURCE CODEAvailable at: v.distance source code (history) Latest change: Tuesday Dec 17 20:17:20 2024 in commit: d962e90c026708a4815ea2b9f46c0e84c17de22d Main index | Vector index | Topics index | Keywords index | Graphical index | Full index © 2003-2025 GRASS Development Team, GRASS GIS 8.4.1 Reference Manual
|