NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I am trying to search all of the highway residential ways, and then get the nodes from those ways, all within an area, and then of those nodes return the ones that are not within a specified distance to other node types. For example, find nodes on a way that are at least 5000m from the nearest freeway, or gas station, or food place, etc. Is this possible to implement only with Overpass QL?

This is what I have so far, which only returns me within an area (currently debugging with bbox) those roads that are marked residential.

/*area
  ["leisure"="nature_reserve"]
  ["name"="Daniel Boone National Forest"]->.a;*/          // Redirect result to ".a"*/
out body qt;
(
  way
    ({{bbox}})['highway'='residential'];
  // area.a Use again result from ".a"
);
out body qt;
>;
out skel qt;
out;

asked 23 Jun '19, 23:11

sreed101's gravatar image

sreed101
26112
accept rate: 0%

1

I don't know what your use case is or how to solve the issue with Overpass but if you're open to solving it with osm2pgsql+PostGIS on a local computer then I could suggest something.

(23 Jun '19, 23:53) Frederik Ramm ♦

@Frederik - that would work! I have a PostGIS setup on my local computer already with an OSM dataset imported.

(24 Jun '19, 01:14) sreed101

Here's a PostGIS based solution:

I assume that your use case is something like "I want to find out the bits of road in this area where, if someone gets stranded, they are more than 5km away from the nearest X", would that about fit? In that case, I'd assume that while your question talks about nodes in highways, you are not really interested in nodes - if there's a super long straight road in OSM with no nodes for 10km then you'd still be interested in the fact that somewhere in the middle there's a stretch far away from any X.

So there's a ton of ways to solve this in PostGIS and which of them makes most sense depends very much on the total data volume. If I am making the right guesses here then a sensible way could be to first calculate one huge (multi)polygon for what I would call the "safe area", everything that is within 5km of an X. Assuming you have an osm2pgsql import with a suitable projection (standard EPSG:3857 will somewhat work but you'd have to convert the 5000m to Mercator meters to get a precise result), your process would be something like this.

Initially create a 5km circle around every X point (in this example: filling stations) and add that to a new table:

select st_buffer(way,5000) as geom into safe_area_building_blocks from planet_osm_point where amenity='fuel';

Now since filling stations can also be polygons in OSM, add these too:

insert into safe_area_building_blocks select st_buffer(way,5000) from planet_osm_polygon where amenity='fuel';

You could now add as many such "insert" statements as you want for different kinds of objects; if you would consider everything within 5km of a motorway safe, you'd do a "... from planet_osm_line where highway='motorway'" and so on.

Now, combine all into one single huge polygon. Note this will take ages if your queries above should yield thousands of polygons; my assumption is that the set is not that huge.

select st_union(geom) as geom into safe_area from safe_area_building_blocks;

Finally, find all stretches of highway that are outside of the "safe area" (this finds ways fully outside, and for ways partly outside will give only the part that lies outside):

select st_difference(way, geom) from planet_osm_line, safe_area where highway is not null and not st_contains(geom, way);

permanent link

answered 24 Jun '19, 07:37

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

edited 24 Jun '19, 07:39

Sorry for not being more descriptive in my initial post. My exact use-case is to find locations within national forest areas that are the most remote for dispersed camping, while still remaining close to roadways/dirt roads. Your answer sounds like a really good way to go about doing this. I'll work on this some and post more after. Cheers!

(24 Jun '19, 14:24) sreed101

I'm not sure it is the best way to solve it, but one approach is to bounce from your residential nodes to the nearby nodes and then back to residential nodes and take the difference between the two sets of residential nodes.

Start by saving the residential nodes into a named set, then search for the nodes that meet your other criteria using the residential nodes and an around: restriction, then search for residential nodes around the other nodes, then use a set difference to find the nodes in the first set of residential nodes that are not in the second set.

Here's a simplified example:

http://overpass-turbo.eu/s/KaO

[bbox:{{bbox}}];
way[highway=residential];
node(w)->.residential_all;
// union of other features
(node(around.residential_all:100)[amenity]->.other;);
way(around.other:100)[highway=residential];
node(w)->.residential_nearby;
(.residential_all; - .residential_nearby;);
out;
permanent link

answered 24 Jun '19, 03:28

maxerickson's gravatar image

maxerickson
12.7k1083176
accept rate: 32%

I'll have to spend some time soon unpacking and understanding this. The initial example still seems to return nodes that are within cities. Thank you for the reply!

(24 Jun '19, 14:28) sreed101

Yes, it's restricted to the bounding box, move the map to an area you are interested in to try it there.

You'd also have to flesh out the queries for the features you want to avoid.

(24 Jun '19, 16:44) maxerickson

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×483
×205
×167
×3
×3

question asked: 23 Jun '19, 23:11

question was seen: 2,743 times

last updated: 24 Jun '19, 16:44

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum