# Changing tracks to vectors in a grid

This is a version of a question that I posted on the GRASS list, but I didn't get any suggestions there. I would like to overlay a grid (cell size about 500 m x 500m) over an animal track created from hourly locations. For each cell that contains a track segment I want to record a direction vector which represents the direction that the animal was traveling when it passed through that cell.

I tried using the GRASS command "v.to.rast use=dir", which should create a directional vector in every raster cell that the track passes through. It almost works, but the command does not seem to respect the order of the track. It seems just as likely to classify a particular segment as having a direction of NE as to classify the same segment as SW (180 degrees opposite) and I couldn't see any consistency to how the directions were chosen, although I may have missed something. Another challenge is that the animal often re-crossed its own track so that individual grid cells may contain more than one track segment--in those cases I want to sum the direction vectors using regular vector algebra.

I am new to GRASS and a bit overwhelmed, and I would be very grateful for any suggestions that would get me started in the right general direction.

• We can look at doing this with R easily enough if you can switch teams. But, what does sum mean for a direction, please expand on *why" you would do this? What is the goal? – mdsumner May 22 '14 at 13:33
• R would be fine. By summing, I mean (to quote from Wolfram): "For two vectors A and B, the vector sum A+B is obtained by placing them head to tail and drawing the vector from the free tail to the free head. In Cartesian coordinates, vector addition can be performed simply by adding the corresponding components of the vectors, so if A=(a_1,a_2,...,a_n) and B=(b_1,b_2,...,b_n), A+B=(a_1+b_1,a_2+b_2,...,a_n+b_n)." As to the why, it's a rather complicated story but in short I want to statistically analyze the direction of movements in relation to landscape features. – John May 23 '14 at 7:51
• For a valid statistical analysis, instead consider converting each hourly record into a location and a velocity vector (which can be computed by differentiating a spline that is fit to the track). Using the location, spatially join any other attributes (such as local relationships to the landscape). This will create a tabular array suitable for analysis, obviates any need to deal with the track crossings (summing the direction vectors was not likely to be a good procedure), and avoids the (incorrect) creation of many more data values than you actually collected. – whuber Dec 9 '14 at 19:41