Officer almost hit by train