Why are dogs so selective about choosing a spot to defecate?
Marking territory with faeces

Despite urine being the most common way for dogs to mark territory, they also can use faeces to do so. Not only the faeces have a unique scent for the dogs, but, most importantly, it contains secretions from the anal glands, which are very important in dog communication. In fact, when you see two dogs sniffing each other "behinds", they are smelling the other dog's anal glands secretion.

So, being selective about the place to defecate is indeed an expected behaviour in dogs. 

Magnetic sensitivity in dogs

However, if you are specifically talking about the dog spinning around after it &mdash; more or less &mdash; decided where to defecate (which makes the dog seem like it had not yet decided if it is going to defecate or not) one factor that plays an important role is that dogs like to eliminate with their bodies aligned to the North-South axis.

According to Hart et al. (2013):


  Dogs preferred to excrete (sic) with the body being aligned along the North–South axis under calm Earth's Magnetic Field (MF) conditions. This directional behavior was abolished under unstable MF. The best predictor of the behavioral switch was the rate of change in declination, i.e., polar orientation of the MF.


So, the dog has to spin some times until it finds the desirable orientation, which explains the behaviour.

It's worth mentioning that the interesting aspect of this research is not the fact that it explains why dogs spin around before eliminating, but the fact that it shows that dogs have magnetoreception! 

Still according to Hart et al. (2013):


  It is for the first time that (a) magnetic sensitivity was proved in dogs, (b) a measurable, predictable behavioral reaction upon natural MF fluctuations could be unambiguously proven in a mammal, and (c) high sensitivity to small changes in polarity, rather than in intensity, of MF was identified as biologically meaningful. 




Source: Hart, V., Nováková, P., Malkemper, E., Begall, S., Hanzal, V., Ježek, M., Kušta, T., Němcová, V., Adámková, J., Benediktová, K., Červený, J. and Burda, H. (2013). Dogs are sensitive to small variations of the Earth’s magnetic field. Frontiers in Zoology, 10(1), p.80.