A general approach for getting optimal speed of vehicles using spatial data