You do have to visit the consulate in person. For the best instructions on how to obtain an NIE number plus forms to download and information on consulates have a look at this page: https://www.spanishpropertyinsight.com/spanish_property_nie.htm
If you find that the link to Spanish consulates in the UK and worldwide on this page isn’t working let me know. It wasn’t working when I tried it just now, the reason being that the website of the government department responsible seems to be temporarily down.
I hope that helps.