Hi all, recently I came across a use case wherein a colleague wanted to have the raw track log coordinates of a patrol (not the observations) as a CSV file. Presently, to my knowledge, there are two ways to export a patrol track log, which can only be as XML or Shapefiles (or GPX). This also relates to a question previously asked here: Extracting raw track data for patrols
There are two ways to export a patrol track log as Shapefiles:
- You can go to the Patrol perspective in SMART and navigate to the ‘Map’ tab at the bottom. Go to ‘Layers’ on the left-hand side and right-click ‘Track’ – you can ‘Export’ as a Shapefile.
- You can create a query for a specific patrol by creating a new Patrol query and then selecting the Patrol ID filter – set to ‘equals’ the specific patrol you are interested in and run the query. Now you can navigate up to the ‘Query’ drop-down menu at the top of the screen and select ‘Export Query Results’, where you can export as a Shapefile.
Now you have the track as a shapefile with minimal column info in the attribute table (fid, distance, day, leg, transport_, uid, geometry). I’ve written a basic R script to convert this to a csv showing the coordinates. Here below, the track file in question for the patrol is called “Track.shp”, so change accordingly. You’ll also want to change your working directory (“wd”) and the output file name itself (here called “Test_file.csv”).
Please note two things: 1) I’ve only tested with single-leg patrols, so multi-leg may not work (I’ll check); 2) the “patrol ID” here is actually the fid, which is not identical to your patrol ID in SMART, so please keep that in mind. This should offer the basic functionality to extract raw coordinates from a track log in csv format. Hope this is helpful to someone.
R Script available to download here: NCZ_Files/Shapefile_To_CSV_Coordinates.R at main · stormcrewsnczoo/NCZ_Files · GitHub
// CODE FOR SCRIPT STARTS HERE
// Load packages
library(sf)
library(dplyr)
// Read in file as sf
data ← read_sf(“C:/smart.7.5.10_Asheboro/workspace/Track.shp”)
// Extract geometry
geom ← st_geometry(data)
// Drop z dimension
geom ← st_zm(geom, drop = TRUE, what = “ZM”)
// Set working directory
wd ← “C:/Users/sacrews/Downloads/”
// Generate a data frame
df ← as.data.frame(st_coordinates(geom))
df ← df %>% select(c(X, Y))
df$patrolID ← data$fid
// Write out csv
write.csv(df, paste0(wd, “Test_file.csv”))