Tagging objects in OSM can sometimes be done as polygon or as point. For example ruins or museum
So far so good, but finding a specific object in a osm-dataset makes it necessary to look into the points AND into the polygons table.
For example: I want to display all museums in a city map. Some museums are tagged as points, some as polygon:
I could import the centroids of the polygons into the point table. That will sometimes result in duplicates. Is there also a better way to solve that?
I'm using GeoPackage (ogr2ogr) or PostGIS (osm2pgsql) with QGIS 3.6
Answer
One way of getting around this is to use the center function in an Overpass query. (Documentation here.)
Normally, a query for museums gives us what you picture above: nodes as well as ways, depending on how the object exists in OSM. By appending center
to your out
statement, you'll get the centroid for the object.
Here is an example query:
[out:json][timeout:25];
{{geocodeArea:stuttgart}}->.searchArea;
(
node["tourism"="museum"](area.searchArea);
way["tourism"="museum"](area.searchArea);
);
out center;
>;
And the output:
Even though the Linden Museum exists as a way, we get a node which represents its center. Upon converting to another GIS format, this will be included with the rest of the points.
A distinct advantage of this method is that the center function will also collapse relations to their centroids. It's possible that this could result in a centroid which is not located in any of the relation's parts, but does eliminate any potential duplicates.
You can try the query yourself right here.
No comments:
Post a Comment