There has been a very interesting question on the OSM US Slack lately.
“Does anyone have a method to search through the OSM database for a building of a particular shape? I need assistance finding OSM buildings with this specific shape. They should be located in NJ, DE, northeastern MD, eastern PA, or southern NY.”
The question quickly exploded into a huge discussion. At the time of writing, there are already 71 replies.
Someone suggested :
“You could load OSM buildings into PostGIS and then use ST_HausdorffDistance to compare the geometries.”
From there, the discussion veered into how to solve that specific puzzle and find the exact OSM building in question.
One person added, “So the strategy is: create the shape of the building you want to search for, scale it to, say, fill a 100x100 m bounding box or something. Ask Postgres to, within a search-area bounding box, take each building and scale it to a 100x100 m bounding box, compute the Hausdorff distance with the scaled input shape, and return all OSM element IDs and their Hausdorff distances, sorted in ascending order.”
Another said, “What I’m currently doing is combining several shape exports into a single file with around 20,000 objects that have concavity. Concavity plus more than 10 nodes eliminates most buildings.”
At that point, instead of hunting that elusive specific OSM building, I became more interested in the generalized version of the problem.
So I added my two cents to the discussion:
“The generalized version of this problem would be : Can we represent a shape in some kind of data type that allows us to computationally check whether two objects have the same shape, regardless of rotation and scaling?
I haven’t studied the Hausdorff distance yet, but I’m wondering whether it can solve this problem, or if there’s a better alternative—Hu moments, Procrustes analysis, Fourier descriptors for contours…”
Someone replied :



