Preprocess Track Data into Spatial Grid Summary
preprocess_track_data.Rd
This function processes GPS track data into a spatial grid summary, calculating time spent and other metrics for each grid cell. The grid size can be specified to analyze spatial patterns at different scales.
Arguments
- data
A data frame containing GPS track data with columns:
Trip: Unique trip identifier
Time: Timestamp of the GPS point
Lat: Latitude
Lng: Longitude
Speed (M/S): Speed in meters per second
Range (Meters): Range in meters
Heading: Heading in degrees
- grid_size
Numeric. Size of grid cells in meters. Must be one of:
100: ~100m grid cells
250: ~250m grid cells
500: ~500m grid cells (default)
1000: ~1km grid cells
Value
A tibble with the following columns:
Trip: Trip identifier
lat_grid: Latitude of grid cell center
lng_grid: Longitude of grid cell center
time_spent_mins: Total time spent in grid cell in minutes
mean_speed: Average speed in grid cell (M/S)
mean_range: Average range in grid cell (Meters)
first_seen: First timestamp in grid cell
last_seen: Last timestamp in grid cell
n_points: Number of GPS points in grid cell
Details
The function creates a grid by rounding coordinates based on the specified grid size. Grid sizes are approximate due to the conversion from meters to degrees, with calculations based on 1 degree ≈ 111km at the equator. Time spent is calculated using the time differences between consecutive points.
Examples
if (FALSE) { # \dontrun{
# Process tracks with 500m grid (default)
result_500m <- preprocess_track_data(tracks_data)
# Use 100m grid for finer resolution
result_100m <- preprocess_track_data(tracks_data, grid_size = 100)
# Use 1km grid for broader patterns
result_1km <- preprocess_track_data(tracks_data, grid_size = 1000)
} # }