Identifying spin and parity of charmonia in flight with lattice QCD