.TH v.to.db 1grass "" "GRASS 6.4.2" "Grass User's Manual" .SH NAME \fI\fBv.to.db\fR\fR - Populates database values from vector features. .SH KEYWORDS vector, database, attribute table .SH SYNOPSIS \fBv.to.db\fR .br \fBv.to.db help\fR .br \fBv.to.db\fR [-\fBpsc\fR] \fBmap\fR=\fIname\fR [\fBtype\fR=\fIstring\fR[,\fIstring\fR,...]] [\fBlayer\fR=\fIinteger\fR] [\fBqlayer\fR=\fIinteger\fR] \fBoption\fR=\fIstring\fR [\fBunits\fR=\fIstring\fR] [\fBcolumns\fR=\fIname\fR[,\fIname\fR,...]] [\fBqcolumn\fR=\fIname\fR] [--\fBverbose\fR] [--\fBquiet\fR] .SS Flags: .IP "\fB-p\fR" 4m .br Print only .IP "\fB-s\fR" 4m .br Only print SQL statements .IP "\fB-c\fR" 4m .br In print mode prints totals for options: length,area,count .IP "\fB--verbose\fR" 4m .br Verbose module output .IP "\fB--quiet\fR" 4m .br Quiet module output .PP .SS Parameters: .IP "\fBmap\fR=\fIname\fR" 4m .br Name of input vector map .IP "\fBtype\fR=\fIstring[,\fIstring\fR,...]\fR" 4m .br Feature type .br For coor valid point/centroid, for length valid line/boundary .br Options: \fIpoint,line,boundary,centroid\fR .br Default: \fIpoint,line,boundary,centroid\fR .IP "\fBlayer\fR=\fIinteger\fR" 4m .br Layer number (write to) .br A single vector map can be connected to multiple database tables. This number determines which table to use. .br Default: \fI1\fR .IP "\fBqlayer\fR=\fIinteger\fR" 4m .br Query layer number (read from) .br A single vector map can be connected to multiple database tables. This number determines which table to use. .br Default: \fI1\fR .IP "\fBoption\fR=\fIstring\fR" 4m .br Value to upload .br Options: \fIcat,area,compact,fd,perimeter,length,count,coor,start,end,sides,query,slope,sinuous,azimuth\fR .br \fBcat\fR: insert new row for each category if doesn't exist yet .br \fBarea\fR: area size .br \fBcompact\fR: compactness of an area, calculated as compactness = perimeter / (2 * sqrt(PI * area)) .br \fBfd\fR: fractal dimension of boundary defining a polygon, calculated as fd = 2 * (log(perimeter) / log(area)) .br \fBperimeter\fR: perimeter length of an area .br \fBlength\fR: line length .br \fBcount\fR: number of features for each category .br \fBcoor\fR: point coordinates, X,Y or X,Y,Z .br \fBstart\fR: line/boundary starting point coordinates, X,Y or X,Y,Z .br \fBend\fR: line/boundary end point coordinates, X,Y or X,Y,Z .br \fBsides\fR: categories of areas on the left and right side of the boundary, 'qlayer' is used for area category .br \fBquery\fR: result of a database query for all records of the geometry(or geometries) from table specified by 'qlayer' option .br \fBslope\fR: slope steepness of vector line or boundary .br \fBsinuous\fR: line sinuousity, calculated as line length / distance between end points .br \fBazimuth\fR: line azimuth, calculated as angle between North direction and endnode direction at startnode .IP "\fBunits\fR=\fIstring\fR" 4m .br Units .br mi(les),f(eet),me(ters),k(ilometers),a(cres),h(ectares),r(adians),d(egrees) .br Options: \fImi,miles,f,feet,me,meters,k,kilometers,a,acres,h,hectares,r,radians,d,degrees\fR .IP "\fBcolumns\fR=\fIname[,\fIname\fR,...]\fR" 4m .br Name of attribute column(s) .IP "\fBqcolumn\fR=\fIname\fR" 4m .br Name of attribute column used for 'query' option .br E.g. 'cat', 'count(*)', 'sum(val)' .PP .SH DESCRIPTION \fIv.to.db\fR loads vector map features or metrics into a database table, or prints them (or the SQL queries used to obtain them) in a form of a human-readable report. For uploaded/printed category values \(cq-1' is used for 'no category' and 'null'/'-' if category cannot be found or multiple categories were found. For line azimuths '-1' is used for closed lines (start equals end). .SH NOTES The units \fImiles\fR, \fIfeet\fR, \fImeters\fR and \fIkilometers\fR are square for \fIoption=area\fR. .PP Feet and acre units are always reported in their common versions (i.e. the International Foot, exactly 5280 feet in a mile), even when the location's standard map unit is the US Survey foot. .PP When calculating perimeters in Latitude-Longitude locations, the geodesic distance between the vertices is used. .PP When using \fIoption=coor\fR on a vector area map, only coordinates of centroids with unique category will be reported. .PP Line azimuth is calculated as angle from the North direction to the line endnode direction at the line statnode. By default it's reported in decimal degrees (0-360, CW) but it also may be repored in radians with \fIunit=radians\fR. Azimuth value \fB-1\fR is used to report closed line with it's startnode and endnode being in same place. Azimuth values make sense only if every vector line has only one entry in database (unique CAT value). .PP If the module is apparently slow \fIand\fR the map attributes are stored in an external DBMS such as PostgreSQL, it is highly recommended to create an index on the key (category) column. .PP Uploading the vector map attributes to a database requires a table attached to a given input vector \fIlayer\fR. The \fBprint only\fR (\fB-p\fR) mode doesn't require a table. Use \fIdb.execute\fR or \fIv.db.addtable\fR to create a table if needed. .PP Updating the table has to be done column-wise. The \fIcolumn\fR must be present in the table, except when using the \fBprint only\fR (\fB-p\fR) mode. Use \fIdb.execute\fR or \fIv.db.addcol\fR to add new columns if needed. .SH EXAMPLES .SS Updating attribute tables Upload category numbers to attribute table (used for new map): .br \fC .DS .br v.to.db map=soils type=centroid option=cat .br .DE \fR .PP Upload polygon areas to corresponding centroid record in the attribute table: .br \fC .DS .br v.to.db map=soils type=centroid option=area col=area_size unit=h .br .DE \fR .PP Upload line lengths (in meters) of each vector line to attribute table (use \fIv.category\fR in case of missing categories): .br \fC .DS .br v.to.db map=roads option=length type=line col=linelength units=me .br .DE \fR .PP Upload x and y coordinates from vector geometry to attribute table: .br \fC .DS .br v.to.db map=pointsmap option=coor col=x,y .br .DE \fR .PP Upload x, y and z coordinates from vector geometry to attribute table: .br \fC .DS .br v.to.db map=pointsmap option=coor col=x,y,z .br .DE \fR .PP Transfer attributes from a character column (with numeric contents) to a new integer column: .br \fC .DS .br v.db.addcol usa_income_employment2002 col="FIPS_NUM integer" .br v.to.db usa_income_employment2002 option=query col=FIPS_NUM qcol=STATE_FIPS .br .DE \fR .PP Upload category numbers of left and right area, to an attribute table of boundaries common for the areas: .br \fC .DS .br # add categories for boundaries of the input vector map, in layer 2: .br v.category soils out=mysoils layer=2 type=boundary option=add .br # add a table with columns named "left" and "right" to layer 2 of the input .br # vector map: .br v.db.addtable mysoils layer=2 col="left integer,right integer" .br # upload categories of left and right areas: .br v.to.db mysoils option=sides col=left,right layer=2 .br # display the result: .br v.db.select mysoils layer=2 .br .DE \fR .PP Compute DL, the Fractal Dimension (Mandelbrot, 1982), of the boundary defining a polygon based on the formula: .br D = 2 * (log perimeter) / (log area): .br \fC .DS .br g.copy vect=soils,mysoils .br v.db.addcol mysoils col="d double precision" .br v.to.db mysoils option=fd column="d" .br .br g.region vect=mysoils res=50 .br v.to.rast in=mysoils out=soils_fd type=area use=attr column=d .br r.colors map=soils_fd color=gyr .br .br d.mon x0 .br d.rast.leg soils_fd .br d.vect mysoils type=boundary .br .DE \fR .SS Printing reports Report x,y,z coordinates of points in the input vector map: .br \fC .DS .br v.to.db -p bugsites option=coor type=point .br .DE \fR Report all area sizes of the input vector map: .br \fC .DS .br v.to.db -p soils option=area type=boundary units=h .br .DE \fR .PP Report all area sizes of the input vector map, in hectares, sorted by category number (requires GNU \fIsort\fR utility installed): .br \fC .DS .br v.to.db -p soils option=area type=boundary units=h | sort -n .br .DE \fR .PP Report all line lengths of the input vector map, in kilometers: .br \fC .DS .br v.to.db -p roads option=length type=line units=k .br .DE \fR .PP Report number of features for each category in the input vector map: .br \fC .DS .br v.to.db -p roads option=count type=line .br .DE \fR .SH SEE ALSO \fI d.what.vect, db.execute, v.category, v.db.addtable, v.db.addcol, v.db.connect, v.distance, v.report, v.univar, v.what \fR .SH REFERENCES .RE Mandelbrot, B. B. (1982). The fractal geometry of nature. New York: W. H. Freeman. Xu, Y. F. & Sun, D. A. (2005). Geotechnique 55, No. 9, 691-695 .RE .SH AUTHOR Radim Blazek, ITC-irst, Trento, Italy .br Line sinuousity implemented by Wolf Bergenheim .PP \fILast changed: $Date: 2011-11-08 12:29:50 +0100 (Tue, 08 Nov 2011) $\fR .PP Full index .PP © 2003-2011 GRASS Development Team