drolbr / Overpass-API

A database engine to query the OpenStreetMap data.
http://overpass-api.de
GNU Affero General Public License v3.0
727 stars 91 forks source link

Allow filtering by area size #526

Open tordans opened 5 years ago

tordans commented 5 years ago

UseCase: Query all parks||gardens but only those areas that are above a certain size. Like bigger than 10 square meters.

Example:

[out:json];area[name="Berlin"];
(
  way["leisure"="garden"]["access"!~"no|private"](area);
  way["leisure"="park"]["access"!~"no|private"](area);
);
out center;

I don't want results like https://www.openstreetmap.org/way/634006146

This might be related to https://github.com/drolbr/Overpass-API/issues/464

tordans commented 3 years ago

Workaround

There is a workaround for now: For simple area forms, the length of an area-way can be used to approximate the area size. I think this should be OK to use, at least for simple filters like I described above.

Before After
image image
(From the example above.) .
[out:json];
(
  way["leisure"="garden"]["access"!~"no|private"](if: length() > 10)({{bbox}});
  way["leisure"="park"]["access"!~"no|private"](if: length() > 10)({{bbox}});
);
out geom;
make stat total_length=sum(length()),section_lengths=set(length());
out;

The number 10 is picked by looking at the section_length list of a query without the if (or with if: … > 1), which, for the given example, would return:

{
  "type": "stat",
  "id": 1,
  "tags": {
    "total_length": "38.458",
    "section_lengths": "28.941;9.517"
  }
}
Binnette commented 2 years ago

Hi @tordans, I really hope this "area size" will be implemented. Thank you for the workaround :heart:

pcace commented 2 years ago

i´d also would love to see the "area size" feature :)! but thanks anyway for the workaround!

baditaflorin commented 1 year ago

This would be so useful to be able to get the data directly without pre processing

1ec5 commented 1 year ago

This functionality would be especially useful to OpenHistoricalMap. For example, you could query for the maximum extent of a city or an empire – a very basic fact in historiography – by filtering its boundary relations until you get a result set of only one. The perimeter is not necessarily very useful, because some boundaries have historically had very many enclaves and exclaves, not to mention scraggly borders.

1ec5 commented 9 months ago

For example, you could query for the maximum extent of a city or an empire – a very basic fact in historiography – by filtering its boundary relations until you get a result set of only one.

As a workaround, here’s a SPARQL query for the maximum extent of an empire in OpenHistoricalMap using QLever.