A migrant looks at the sea from the deck of the boat of the NGO Proactiva Open Arms on July 1. (Olmo Calvo/AFP/Getty Images)

During a meeting with Spain’s foreign minister recently, President Trump, hammer in hand, spotted another nail.

Trump and Foreign Minister Josep Borrell were talking about the surge of migrants into Europe in recent years, a problem for which Trump had already figured out a solution. Build a wall across the Sahara, the biggest subtropical desert in the world, Trump reportedly suggested. Done and done.

Now, you may be thinking, Hey, that sounds tricky. And we are here to tell you that your instincts are correct. It would be tricky.

Problem 1: Where does it go?

Trump’s intent distills neatly: Prevent migrants from reaching Europe. But that introduces a distinct frustration. What are we putting the wall between.

In Trump’s more familiar iteration of an anti-migration wall, the answer to that question is easy: The wall goes between them (Mexico) and us (U.S.). Here, though, it’s less clear.

We tend to associate the recent migration crisis with the Middle East. The civil war in Syria, coupled with instability in Iraq and the ongoing war in Afghanistan, have led to a surge in migration from that region. But U.N. data on refugee migration make clear that there is a significant migrant crisis in sub-Saharan Africa as well. Those data show that in 2017, 10 of the 20 countries that saw the largest exoduses were countries below the Sahara. South Sudan saw the largest number of fleeing refugees after Syria and Afghanistan.

Hence a wall across the Sahara, separating Mediterranean Africa from the migrants further south.

(Philip Bump/The Washington Post)

It’s just that this is a lot of wall. Trump was surprised when Borrell noted that the extent of wall might be prohibitive.

“The Sahara border can’t be bigger than our border with Mexico,” he reportedly said. It is. Even in the relatively modest proposal delineated above, the Saharan wall would be substantially longer, some 700 miles, than the U.S.-Mexico border.

But, as with the border with Mexico, not everywhere is actually passable. The United Nations has mapped the busiest migration routes in the world, providing an illustration of the common routes migrants have used to enter Europe. Often those routes, particularly for migrants originating in Africa, have necessitated dangerous voyages across the Mediterranean Sea. Those trips often relied on the prospect of being rescued en route by merchant or fishing vessels.

They also often resulted in scores of deaths.

(UN Migration Agency) (SZABO Daniel/(UN Migration Agency))

If Trump’s operating theory is simply that he wants to offer a practical suggestion for isolating Spain itself from African migrants, the map above shows that a less extensive wall might work. A wall from Rabat to Algiers, for example, would apparently cut off most of those common routes.

(Philip Bump/The Washington Post)

Even this doesn’t resolve all our problems.

Problem 2: That land doesn’t belong to Spain.

Spain does control land in Africa. Specifically, it controls two regions named Ceuta and Melilla. The former is on the peninsula just south of the Strait of Gibraltar, the latter on a spit of land adjacent to the sea in the northwest corner of Morocco. Neither, in other words, is on the route delineated for our wall above.

That land belongs to Morocco and Algeria, both of which would need to be persuaded to erect impenetrable walls through the middle of their countries in order to keep migrants out of Spain. A wall that would then keep migrants within their own countries.

In the case of Trump’s proposed wall on the southern U.S. border, the proposal is to mostly build on land that the United States owns, for obvious reasons. The interior secretary suggested last year that we might build it on Mexico’s side of the border so that we didn’t give up land, but that’s an only slightly trickier ask than requesting that Mexico also foot the bill for construction.

Perhaps Spain could persuade Algeria and Morocco to play ball. They would need a leader who was particularly adept at deal-making, to say the least.

Problem 3: This is not a cheap prospect.

The cost of Trump’s wall separating the United States from Mexico has been the subject of extensive debate. There are obvious reasons for this, including the mix of terrain it would need to cover and the components of the wall itself. (It went from a 50-foot-high concrete slab to a wall with windows and solar panels.)

In order to estimate the cost of the wall depending on various metrics, a group at the Warsaw University of Technology created an online calculator to estimate costs.

A 640-mile wall runs about $7 billion. A 2,600-mile wall? $30 billion.

But those figures are littered with asterisks. There is a big difference between building a concrete slab wall in the United States, using 6.5 million cubic yards of concrete (in the case of Option 2 above) that can be sourced relatively locally, than a wall in unpopulated regions of North Africa. A 40-foot-tall wall across the Sahara would use 26 million cubic yards of concrete, according to the design assumed by the Warsaw University of Technology.

That design, though, wouldn’t work in the desert. Which raises another question entirely: How do you build on sand?

There are a few answers.

(Philip Bump/The Washington Post)

One is that you use an “end-bearing pile,” in which a support is extended through the sand to a more compact, stable terrain. In some places, the sand in the Saharan ergs — the landscape we envision when we think of a sandy desert — is estimated to be hundreds of feet deep, requiring extensive excavation to use an end-bearing pile.

Another option is a “friction pile.” The site Understand Construction uses a good analogy to understand how it works. Stick a spoon into a carton of ice cream, and that spoon can bear a small amount of weight thanks to the friction of the ice cream around it.

But Ed McSwain, president and CEO of Terra Contracting in sand-familiar Las Vegas, offered another option when we spoke by phone on Wednesday: The helical pier.

In essence, a helical pier is a bit like an auger, a cylinder with a sort of spiraling metal ramp curling around it. A helical pier, McSwain said, distributes the weight in a cone around the support, allowing it to hold more weight with more stability.

“They’re truly a remarkable system for building a structure,” McSwain said. “If I were to build a custom home — and this is just me talking — I don’t care what the soil was like, I’d build them on helical piers.”

The more support you need, the deeper you go. McSwain said he knew of a contractor who’d run a support in the sand near Palm Springs to a depth of 116 feet. The deepest he’d gone, in a loose, rocky terrain, was about 32 feet.

He walked me through the math. He installs helical piers every six to eight feet, ensuring that they can support about 60,000 pounds of weight. If we assume a 40-foot concrete wall, one foot thick, a 6-foot section would weigh about 36,000 pounds (assuming a per-square-foot weight of 150 pounds). Helical piers run about $20 a foot, McSwain said, with an additional $500 for the spiraling five-foot tip of the pier (the “lead”). If each pier runs 40 feet in depth (a figure I just made up), each pier would cost about $1,200.

Over the span of 640 miles, that’s an additional $680 million in costs.

Not all the terrain is desert, of course, especially in the Option 2 scenario above. Even in the Sahara, much of the terrain is bare rock. Regardless, the cost of such a wall, even in places where we ignore McSwain’s advice and use some other anchor, would be astronomical.

The gross domestic product of Spain in 2017 was about $1.3 trillion. Assuming that the increased cost of materials in northern Africa is offset entirely by a reduced cost in labor (this is all very grim, isn’t it?), our $30 billion price tag for a 2,600-mile wall would eat up 2 percent of the country’s economic output for a year.

Put more succinctly, this is not a good suggestion for addressing migration increases, increases that might well subside well before the wall is complete.

The analysis above dutifully ignores the most obvious flaw in Trump’s plan: Those boats. The only way to build a barrier to keep anyone from getting into Spain would be to build a wall along the country’s entire maritime border. Spain’s coastline is about 7,000 kilometers in length. A wall of that length our Warsaw calculator puts at about $49 billion.

On the plus side, Spain at least owns the land.