QLever recently started exposing information about the topological relationships between nodes, ways, and relations, improving the reliability and comprehensiveness of some spatial queries that used to require a different analysis tool such as the Overpass API. To demonstrate this new capability, I’ve added some spatio-topological examples to the wiki’s growing library of QLever examples.
All the intersections
One frequently asked GIS question is how to get all the street intersections in a city. The OverpassQL query can time out if you run it over an urban area larger than a neighborhood, but this SPARQL query takes just a few moments on a large, gridded city such as Chicago:
This query can even scale up to the entire United States without any modifications, producing this most insightful heat map:
Weird boundaries
We can combine this new functionality with some existing features, such as precomputed length and area measurements (in degrees and square degrees of arc, respectively). Previously, I demonstrated that QLever can find the most poorly drawn windmills and circles, using a well-known formula for measuring a shape’s compactness. This formula requires knowing the shape’s area and perimeter. Now that we can obtain the perimeter of a boundary relation, we can use the formula for its usual purpose: measuring the compactness of a boundary.
In most of the U.S., the most local level of administrative boundary represents an incorporated municipality (city, town, village, etc.), and is supposed to roughly correspond to a populated place represented by a place=city
/town
/village
/hamlet
point. Many states give their cities wide discretion to unilaterally annex surrounding unincorporated land. This has led to some dramatic land grabs. Sometimes people from elsewhere in the world see these boundaries and assume the U.S. mapping community hasn’t gotten its act together, but the map is not to blame:
Now we can quickly discover the most convoluted boundaries among the 600 or so town and city limits in Oklahoma. I’ve screenshotted a few of the most convoluted boundaries, with the boundary’s territory shaded in, so you can see how little is actually filled in in a place like Vera. Its core settlement is dwarfed by the unincorporated enclaves that lie within its “fenceline”:
Empire City has yet to build out its empire by filling in the Mondrian honeycomb surrounding its various properties:
Continuing down the list, Ada starts to resemble a normal boundary again, but there’s still a bit of tomfoolery on the outskirts of town:
On the other end of the spectrum is the town of Hoot Owl, which has quite a reasonable boundary… for an official recorded population of zero.
Straightaways
QLever supports a GeoSPARQL function for calculating the distance between any two arbitrary point geometries (even unmapped points). Using this function, we can find out the longest straight segments along highway=trunk
roads in California. Those familiar with the state’s topography won’t be surprised to learn that nine of the ten longest straightaways are in desolate corners of the Mojave Desert.
And yes, it is pretty straight and flat!
These examples are from the U.S. because it’s what I’m familiar with, but you can adapt any of them to your country to find out something interesting about it. Some topological queries may still be more intuitive or performant in Overpass, but it’s good to have multiple tools in the toolchest, each with their unique strengths. Hopefully these examples get you all thinking about more questions we can get answered more routinely than before.