Applications for Schengen visas must be made at the embassy or consulate of the country the applicant intends to visit or, if they intend to visit more than one country in the Schengen area, the embassy or consulate of the country where they will spend the longest time.
If you intend to visit several countries in the Schengen area for equal lengths of time, you should apply at the embassy or consulate of the country through which you will first enter the Schengen area.
If Spain is the only, the main, or the first country you will visit in the Schengen area, as explained above, you must apply for your visa at the Spanish embassy or consulate in or responsible for the country in which you are legally resident. A full list of Spanish embassies and consulates can be found at: http://www.exteriores.gob.es/Portal/en/ServiciosAlCiudadano/Paginas/EmbajadasConsulados.aspx
In exceptional cases, visas may be applied for at border crossing points provided that:
the applicant is in possession of valid and genuine travel document (passport or ID card);
the applicant can certify the purpose and conditions of the stay, including place of residence;
the applicant has sufficient means of subsistence, both for the duration of the intended stay
and for the return to their country of origin/residence or transit to a third country to which
they are certain to be admitted;
the applicant does not pose a danger to public order or public safety;
the applicant was not in a position to apply for a visa in advance and submits, if required,
supporting documents demonstrating unforeseeable and imperative reasons for entry; and
the applicant’s return to their country of origin/residence or transit through states other
than EU member states fully implementing the Schengen Agreement is assessed as being certain.
Visas issued at border crossing points are standard visas entitling the holder to stay for a maximum of 15 days, depending on the purpose of the intended visit. It is recommended to apply for visas in advance to ensure you obtain your visa in time and for the length of stay you require.