Pinning of vortices by defects plays an important role in various physical (superconductivity, superfluidity, ...) or biological (propagation in cardiac muscle) situations. Which defects act as pinning centers? We propose a way to study this general problem by using an advection field to quantify the attraction between an obstacle and a vortex. A full solution is obtained for the real Ginzburg-Landau equation (RGLE). Two pinning mechanisms are found in excitable media. Our results suggest strong analogies with the RGLE when the heterogeneity is excitable. Unpinning from an unexcitable obstacle is qualitatively harder, resulting in a stronger pinning force. We discuss the implications of our results to control vortices and propose experiments in a chemical active medium and in cardiac tissue.