Was man sieht ist – nicht unbedingt – was man kauft.
There has been a lot of construction in Spain over the past decade or two and I would not count on all of it to be completely legal. Coastal properties, for example, are especially appealing for their views and vicinity to beaches. However, the “ley the costas” prohibits construction in coastal areas to protect the environment and public access. Be careful your object of interest has not been illegally built and will be torn down anytime. Friends returned to the UK after their miserable experience of having forcefully removed their new beach-view house.
Even houses legally constructed may have been changed or expanded – without a license. Make sure what the national register has approved as legal is actually what is built on the property. Check constructed square-meters, location of the construction within the land, window-location, walls, their height and materials used. Granted, there are also legal structures which remain unregistered. Simply by passing time, some buildings “become legal”.
When buying land to build a new building or demolish and rebuild a house, be sure you know where on the property you can build, how much you can build, how many stories are allowed and check for restrictions in style and materials. Rules change depending of the specific location and its land-categorization. Do not assume you can do something just because someone down the road has done so! Rules change over time, location and, well, people who get by ignoring some of the rules 😉