How to extract only polygons from Overpass Turbo? - overpass-api

The query below extracts Polygons and Points:
[out:json];
area["name:fr"="Bruxelles-Capitale"]["admin_level"=4]->.a;
rel["admin_level"=8](area.a);
out geom;
How do I filter out Points?

Option 1: Simply hide it:
[out:json];
area["name:fr"="Bruxelles-Capitale"]["admin_level"=4]->.a;
rel["admin_level"=8](area.a);
out geom;
{{style:
node {
width: 0;
opacity:0;
fill-opacity:0;
}
}}
http://overpass-turbo.eu/s/98F
Option 2: Only extract ways from relation:
Don't forget to enable the flag "Don't display small features as POIs." in Settings -> Map.
[out:json];
area["name:fr"="Bruxelles-Capitale"]["admin_level"=4]->.a;
rel["admin_level"=8](area.a);
out meta;
way(r);
out geom;
http://overpass-turbo.eu/s/98H

Related

How can I find a tag/way in another way/area with Overpass?

I want all industries in "Chemnitz" with a "hot_water_tank".
This query gives me all objects with tags "landuse"="industrial" and "man_made"="hot_water_tank". I need only the "landuse"="industrial" containing a "hot_water_tank".
area
["name"="Chemnitz"]->.a;
out body qt;
(
way
(area.a)
["landuse"="industrial"];
way(area.a)
["man_made"="hot_water_tank"];
);
out body qt;
>;
out skel qt;
i tried this
area
["name"="Chemnitz"]->.a;
(
way
(area.a)
["landuse"="industrial"]->.c;
way(area.a)
["man_made"="hot_water_tank"]->.s;
(.c; .s;)->.all;
(.c; - .s;)->.I_without_T;
(.s; - .c;)->.T_wihtout_I;
((.all; - .I_without_T;) - .T_without_I;);
);
out body qt;
>;
out skel qt;
Screenshots of the results:
The key here was to use two little known statements from Overpass QL.
First is_in gives us areas in which features are located, second we need to extract relations and/or ways from said areas using pivot.
Here is a sample code:
(area["name"="Chemnitz"]) -> .chemnitz; //Chemnitz
(
way(area.chemnitz)["man_made"="hot_water_tank"];
(._;>;)
)->.hotwatertank; // all tanks in Chemnitz
(.hotwatertank is_in;) -> .areas; // areas in which tanks are located
(
way(pivot.areas)["landuse"="industrial"];
relation(pivot.areas)["landuse"="industrial"];
)->._; // convert areas to ways and relations with "landuse"="industrial" pair
(._;._ >;); // get geometry
out body qt; //print

Using coordinate and radius instead of a bounding box

My current queries look like this:
[out:json]
[timeout:60]
;
(
relation
["type"="multipolygon"]
["landuse"~"brownfield|railway"]
(50.757310,6.054754,50.786730,6.111574);
way
["landuse"~"brownfield|railway"]
(50.757310,6.054754,50.786730,6.111574);
);
out body;
>;
out skel qt;
I would like to replace the bounding box by one coordinate and a radius, similiar to querying nodes around another node.
node["name"="Bonn"];
node
(around:1000)
["name"="Gielgen"];
out body;
Is this possible?
I was able to accomplish that using (around:radius,lat,lon). The radius appears to be given in meters.
A simple example:
node(around:1000.0,50.75,6.05)["historic"="wayside_cross"];
out;
Applied to your query:
[out:json]
[timeout:60]
;
(
relation
(around:1000,50.77675,6.07456)
["type"="multipolygon"]
["landuse"~"brownfield|railway"];
way
(around:1000,50.77675,6.07456)
["landuse"~"brownfield|railway"];
);
out body;
>;
out skel qt;

Finding geometry of an area with overpass API

I am trying to find the geometry of a building from a particular latitude longitude. So my idea was to use a coord-query to get all areas in which the lat,lng. Using http://overpass.osm.rambler.ru/cgi/interpreter, I get all the areas and I can filter to get only the nodes that are buildings.
Now I have an area, for example:
{ id: '2542062474',
'addr:city': 'Nice',
amenity: 'place_of_worship',
building: 'yes',
denomination: 'protestant',
name: 'Église Protestante Unie de Nice Saint-Esprit',
religion: 'christian',
source: 'cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre. Mise à jour : 2011' }
I thought it would be easy to get the geometry of this area but I can't find any way of doing that ? I must be missing something.
In http://overpass-turbo.eu, I enter the script:
[out:json][timeout:25];
// gather results
(
// query part for: “area”
area(2542062474);
);
// print results
out body;
>;
out skel qt;
but the result does not include the geometry. How do I get the geometry of an area ?
Thanks !
Here is my script, for the moment: https://gist.github.com/ptbrowne/60d7338502de1d16ac46
Areas are an internal data type of Overpass. You can use pivot to get the geometry:
[out:json][timeout:25];
area(2542062474);
way(pivot);
out body;
>;
out skel qt;
Finally, what I did was to read a bit more the doc and to find out that to get the way associated with an area, I needed to substract 2400000000 from the area id.
Then I could only query for the way. From area id 2542062474, I substract 2400000000, I get 142062474.
[out:json][timeout:25];
way(142062474);
out body;
>;
out skel qt;
It works, but I think the pivot answer by #Alex Morega is better since the 2400000000 might change one day. I do not know about performance.

How to display polygons that are within a specific range (circle) using Leaflet

I am trying find a solution on how to display polygons that are only within a specific range, a circle with radius using leaflet.
Polygons screenshots
Before, I have ask for help regarding on the display of points within a specific range but this time, since a polygon have many nodes/coordinates, i don't have any idea of how it can be done for polygons; a foreach statement?
Any solution? Thanks for the help!
Similar problem solved for displaying points within a specific range
Since you're using MongoDB, the best solution here is (if that's possible), to handle this in the database. Put 2dsphere indexes on your document's loc field and use a $geoWithin query in combination with $centerSphere:
The following example queries grid coordinates and returns all documents within a 10 mile radius of longitude 88 W and latitude 30 N. The query converts the distance to radians by dividing by the approximate radius of the earth, 3959 miles:
db.places.find( {
loc: { $geoWithin: { $centerSphere: [ [ -88, 30 ], 10/3959 ] } }
} )
2dsphere reference: http://docs.mongodb.org/manual/core/2dsphere/
$geoWithin reference: http://docs.mongodb.org/manual/reference/operator/query/geoWithin/
$centerSphere reference: http://docs.mongodb.org/manual/reference/operator/query/centerSphere/
If you really want to do this clientside (which i absolutely wouldn't recommend) and you don't want to build your on solution (which is possible) you could take a look at GeoScript.
GeoScript's geom.Geometry() class has a contains method:
Tests if this geometry contains the other geometry (without boundaries touching).
Geom.geometry reference: http://geoscript.org/js/api/geom/geometry.html
EDIT: Here's the pure JS/Leaflet solution as requested in the comments, this is quick-n-dirty, but it should work. Here the containsPolygon method returns true when all of the polygon's points are within the circle:
L.Circle.include({
'containsPoint': function (latLng) {
return this.getLatLng().distanceTo(latLng) < this.getRadius();
},
'containsPolygon': function (polygon) {
var results = [];
polygon.getLatLngs().forEach(function (latLng) {
results.push(this.containsPoint(latLng));
}, this);
return (results.indexOf(false) === -1);
}
});
Here's a working example: http://plnkr.co/edit/JlFToy?p=preview
If you want to return true if one or more of the polygon's points are within the circle than you must change the return statement to this:
return (results.indexOf(true) !== -1);

Appcelerator Titanium ACS Order place by nearest the user

I am trying to order at list by nearest place. This is working fine with this code:
Cloud.Places.query({
page: 1,
per_page: 20,
where: {
lnglat: { '$nearSphere': [latitudefast,longitudefast], }
},
order: {
lnglat: { '$nearSphere': [latitudefast,longitudefast], }
},
latitudefast and longitudefast is representing the actual position on the user. It has be defined before the query.
But it is "upside down", which means that the nearest place is in the bottom of the list, and the one farthest away is at the top of the list! How come? How do I order in reverse? Am i ordering wrong?
Thanks!
Have you tried not specifying the order? $nearSphere by default returns results sorted by distance.
From MongoDB's documentation (which ACS uses as its data store) describing $near:
The above query finds the closest points to (50,50) and returns them
sorted by distance (there is no need for an additional sort
parameter).
This applies to $nearSphere as well.
http://www.mongodb.org/display/DOCS/Geospatial+Indexing