How can I obtain all of the street names under a polygon in Overpass? - overpass-api

I am new to overpass (after only discovering it last night). I have a polygon I drew on QGIS and I plan to obtain its coordinates (long, lat). I'd then like to use these coordinates in overpass to obtain all of the road names in that area. I found a query online that obtains all road names in a city:
[out:csv ("name")][timeout:2500];
{{geocodeArea:Roma}}->.searchArea;
(
way["highway"]["name"](area.searchArea);
);
for (t["name"])
{
make street name=_.val;
out;
}
How can I adjust the following query so that I can specify a polygon function instead of city/area name?. I'm mindful of the syntax:
(poly:"latitude_1 longitude_1 latitude_2 longitude_2 latitude_3 longitude_3 …");
I'm just not sure where it would go in the query. I tried a few times but I was receiving errors or just blank results. Hopefully if I see an example I should be able to carry out my task effectively.

After doing some research I found the answer. This would give me a list of road names:
[out:csv ("name")][timeout:2500];
way["highway"]["name"]
(poly:"51.5566 0.0763 51.5734 0.0724 51.5203 0.0293");
out tags;
And this would give me a map view:
way["highway"]["name"]
(poly:"51.5566 0.0763 51.5734 0.0724 51.5203 0.0293");
out geom;

Related

Open Street Map tag to grab all emerged land

I'm looking to download the geometries of all emerged land (everything within the coastal line) in Python using OSMNX, but can't seem to find a general tag that would do it.
Right now, I'm using:
t = {'landuse':['commercial', 'industrial', 'residential', 'farmland', 'construction', 'education', 'retail', 'cemetery', 'grass', 'garages', 'depot', 'port', 'railway', 'recreation_ground', 'religious', 'yes', '*'], 'leisure':['park']}
land = ox.geometries_from_polygon(bbox, tags=t)
But I still have many holes...
So, in short, is there an OSM tag to grab all emerged land?
The additive approach, i.e. combining all sorts of landuses, won't get you all the way to the result you want. As you've noticed, you'll end up with white spots. You could get closer by considering even more tags, such as some values of the natural=* key, but ultimately there simply is land that is not covered by any such polygon in OSM.
Instead, you should look at OSM coastline data. As this can be tricky to process, you might want to get pre-processed data from osmdata.openstreetmap.de, such as their land polygons.

osmnx boundaries and admin_level

I hope someone here can help me to retrieve the correct administration level(s) from OSM. I am using the following code, but admin_level seems to be ignored:
tags = {"boundary":"administrative","admin_level":"4" }
gdf =ox.geometries.geometries_from_bbox(51.5, 51.0, 11.7, 11.2, tags)
gdf.shape
The bounding box seems to be used as a polygon to create an intersection with all the boundaries in the OSM database, the first tag is working because only administrative boundaries are returned, but the filter on level is ignored (gdf["admin_level"].head() shows level 6).
I would like to understand what I am doing wrong, and how I can use this package better; it seems like a very useful library.
Thanks,
Gijs
Result using the bounding box:
OK, rereading the documentation again made me realize that osmnx is using [OR] statements and not [AND] statements as I was presuming; removing the boundary request from the query is indeed giving only admin_level:4 results.
tags (dict) – Dict of tags used for finding objects in the selected area. Results returned are the union, not the intersection of each individual tag.
Some additional code: https://i.stack.imgur.com/Fw840.png

PostGIS - Route matching solution

We are building an application where I am a driver and i travel from point A to point B.On my way i can find passengers who travel in the same route.
We are using PostgreSQL with PostGIS extension.
After googling a lot i have found out that we can use linestring to achieve this.I am not fully sure whether this approach will work out.
Suppose I have co-ordinates of my source and destination.
var RouteCoordinates = [
{lat: 37.772, lng: -122.214},
{lat: 21.291, lng: -157.821},
{lat: -18.142, lng: 178.431},
{lat: -27.467, lng: 153.027}
];
I need to store this as linestring in my DB.
After stroring if a passenger is also going in this route but as we know his source and destination wont be exactly in my line string but they will be near.
For example around 1km radius
As you can see my source and destination is that line. And as I am travelling I want to pick all those whose (source and destination) are near to my routes (within particular radius)
If I want to find particular location in my DB within particular radius I will be querying like this
SELECT id, name, address, geom
FROM Seattle_Starbucks
WHERE ST_DWithin(geom, ST_MakePoint(-122.325959,47.625138)::geography, 1000);
Now I can achieve my solution as I am new to postGIS its little bit confusing
How to store all all my source and destination point in DB
ANS: I need to convert in to linestring using this function ST_MakeLine and then store, right?
How to query that based on my requirement as I have mentioned above
Can you please give me the insight on how to achieve this. Your help is greatly appreciated. Thanks
A few thougths on your question:
I need to convert in to linestring using this function ST_MakeLine and
then store, right?
Yes, to merge multiple points into a LINESTRING you can use ST_MakeLine:
SELECT ST_AsText(
ST_MakeLine(ARRAY[ST_MakePoint(-122.21,37.77),
ST_MakePoint(-157.82,21.29),
ST_MakePoint(178.43,-18.14),
ST_MakePoint(153.02,-27.46)]));
st_astext
---------------------------------------------------------------------
LINESTRING(-122.21 37.77,-157.82 21.29,178.43 -18.14,153.02 -27.46)
(1 Zeile)
How to query that based on my requirement as I have mentioned above
Create a buffer on each point of your LINESTRING and check wether other geometries are inside of it.
First, you have to split your rout LINESTRING into POINTs using ST_DumpPoints ...
db=# SELECT ST_AsText((ST_DumpPoints('LINESTRING(-122.21 37.77,-157.82 21.29,178.43 -18.14,153.02 -27.46)'::GEOMETRY)).geom);
st_astext
----------------------
POINT(-122.21 37.77)
POINT(-157.82 21.29)
POINT(178.43 -18.14)
POINT(153.02 -27.46)
(4 Zeilen)
.. and then use ST_Buffer to create a buffer around each point. ST_Buffer returns a geometry with the area surrounding your point (or any other geometry type). For instance, taking the first point of your route (if I didn't switch x and y, it's somewhere in San Francisco) POINT(-122.21 37.76):
db=# SELECT ST_AsText(
ST_Buffer('POINT(-122.21 37.76)'::GEOMETRY,0.0001, 'quad_segs=16'));
Returns this geometry:
POLYGON((-122.2099 37.76,-122.209900481527 37.759990198286,-122.209901921472 37.7599804909678,-122.209904305966 37.7599709715323,-122.209907612047 37.7599617316568,-122.209911807874 37.7599528603263,-122.209916853039 37.7599444429767,-122.209922698955 37.7599365606716,-122.209929289322 37.7599292893219,-122.209936560672 37.7599226989547,-122.209944442977 37.7599168530388,-122.209952860326 37.7599118078736,-122.209961731657 37.7599076120467,-122.209970971532 37.7599043059664,-122.209980490968 37.759901921472,-122.209990198286 37.7599004815273,-122.21 37.7599,-122.210009801714 37.7599004815273,-122.210019509032 37.759901921472,-122.210029028468 37.7599043059664,-122.210038268343 37.7599076120467,-122.210047139674 37.7599118078736,-122.210055557023 37.7599168530388,-122.210063439328 37.7599226989547,-122.210070710678 37.7599292893219,-122.210077301045 37.7599365606716,-122.210083146961 37.7599444429767,-122.210088192126 37.7599528603263,-122.210092387953 37.7599617316568,-122.210095694034 37.7599709715323,-122.210098078528 37.7599804909678,-122.210099518473 37.759990198286,-122.2101 37.76,-122.210099518473 37.760009801714,-122.210098078528 37.7600195090322,-122.210095694034 37.7600290284677,-122.210092387953 37.7600382683432,-122.210088192126 37.7600471396737,-122.210083146961 37.7600555570233,-122.210077301045 37.7600634393284,-122.210070710678 37.7600707106781,-122.210063439328 37.7600773010453,-122.210055557023 37.7600831469612,-122.210047139674 37.7600881921264,-122.210038268343 37.7600923879533,-122.210029028468 37.7600956940336,-122.210019509032 37.760098078528,-122.210009801714 37.7600995184727,-122.21 37.7601,-122.209990198286 37.7600995184727,-122.209980490968 37.760098078528,-122.209970971532 37.7600956940336,-122.209961731657 37.7600923879533,-122.209952860326 37.7600881921264,-122.209944442977 37.7600831469612,-122.209936560672 37.7600773010453,-122.209929289322 37.7600707106781,-122.209922698955 37.7600634393284,-122.209916853039 37.7600555570233,-122.209911807874 37.7600471396737,-122.209907612047 37.7600382683432,-122.209904305966 37.7600290284677,-122.209901921472 37.7600195090322,-122.209900481527 37.760009801714,-122.2099 37.76))
If you're wondering about the shape of this buffer, please read this answer.
And using this query you can check if another geometry is inside of this buffer (ST_Within):
db=# SELECT
ST_Within('POINT(-122.21 37.76)'::GEOMETRY,
ST_Buffer('POINT(-122.21 37.76)'::GEOMETRY,0.0001, 'quad_segs=16'));
st_within
-----------
t
(1 Zeile)
To put it all together, you can use a CTE (aka WITH clause) and write something like this:
WITH j AS (
SELECT
(ST_DumpPoints('LINESTRING(-122.21 37.77,-157.82 21.29,178.43 -18.14,153.02 -27.46)'::GEOMETRY)).geom AS g)
SELECT id, name, address, geom
FROM Seattle_Starbucks
WHERE ST_Within(geom,ST_Buffer(j.g,0.0001, 'quad_segs=16'))

How can I search for elements within a polygon with Overpass?

I am new to Overpass API and GIS in general.
Is there an easy way to export all buildings in a specific region using coordinates to specify the polygon? I couldn't find a solution using the wiki and google so far.
I have large sets of coordinates which are determining some medium-voltage grids.
Or is there another tool I could use?
I want to use the polygon- coordinates of the exported buildings in matlab.
Thanks for your help!
Overpass API provides the (poly: ) filter to query objects inside a given polygon. See the documentation in the wiki for details.
Buildings in a given polygon can be queried as follows:
way[building](poly:"50.7 7.1 50.7 7.12 50.71 7.11");
(._;>;);
out meta;
Due to a recent memory limitation, you might have to either add a [maxsize: xxx] setting:
[maxsize:2073741824];
way[building](poly:"50.7 7.1 50.7 7.12 50.71 7.11");
(._;>;);
out;
or resort to the following workaround to force another evaluation sequence:
way(poly: "50.7 7.1 50.7 7.12 50.71 7.11");
way._[building];
(._;>;);
out meta;

Prevent Overpass API from returning nodes and show ways only

I'm trying to get all roads around a certain point. I'm using the following query:
(
way
(around:300,50.7913547,-1.0944082)
["highway"~"^(primary|secondary|tertiary|residential)$"]
["crossing"!~"."]
["name"];
>;
);
out;
I added the crossing exclusion because it kept including "markers" for crossings, and I'm only interested in roads.
However it seems to be ignoring the crossing and still plotting markers on the map, rather than just showing road outlines. This can be seen here.
These "nodes" that I don't want have the tags:
crossing=zebra
highway=crossing
which should fail my regex query, but it doesn't.
How do I get it to just return road plot lines, and none of these nodes/markers?
Sorry if my terminology is all wrong, I'm very new to this
The filter criterion you tried to use would only apply to the way itself rather than the nodes. Usually, a way wouldn't have a crossing tag, so this filter didn't have much of an effect on the final result. By using >; all of the nodes tags would shown up in the final result again.
I removed >; in your query and replaced out; by out geom; to only output the node lat/lon position without any tags.
You can try this out using the following link (currently pointing to overpass turbo beta)
Link