Extract building geometry with overpass - overpass-api

I need to extract building geometry by coordinates
I have this, but as I use around it selects the nearest buildings too.
Is there a way to select only one? the building that includes the coordinates
[out:json][timeout:25];
// adjust the search radius (in meters) here
// gather results
(
// query part for: “building=*”
way["building"](around:5,37.780495290046375,-122.47132010628351);
);
// print results
out body;
>;
out skel qt;

I cannot find anything about selecting only one building (or more generally: the best match only) in the Overpass API documentation, although I do surmise it should be possible.
A workaround would be to compare the coordinates of your matches with the desired coordinates, and only retain the match with smallest distance in radial coordinates.

Related

Geopoints: From Single Coordinate to Bounds on map

I try to figure out how to come from a single given coordinate (lat/lon) to the nearest bounds which enclose this coordinate on a map e.g. streets or sea.
Here two examples to give you a better understanding of what I mean:
What i tried already or thought about:
Setting up a Nominatim server and search for the given coordinate via the reverse-function to get the bbox and/or the geojson polygon of this coordinate. -> this only works when the given coordinate is within a POI or for example directly on a street.
Writing an algorithm to walk in all 4 or 8 directions (n/e/s/w) and 'stop' when the map layer/surface changes (change = stop for this direction and mark a bounding-point)
Building up an image-recognition system using TensorFlow to detect the different colors and 'draw' the polygon. Worked with TensorFlow a couple of times but this seems to be the most tricky solution to implement (but at my current understanding the most precise one)
Does someone of you have any other ideas to get a solution for this problem? Would appreciate any kind of approaches
Cheers!
If I got your question right, you might wanna first select all polygons in which the given point is inside of using ST_Contains, and then compute the distance to this point using ST_Distance. If you ORDER BY distance and LIMIT to 1 result you'll get the nearest polygon, e.g.
Data Sample
CREATE TABLE t (gid int, geom geometry);
INSERT INTO t VALUES
(1,'POLYGON((-4.47 54.26,-4.44 54.28,-4.41 54.24,-4.46 54.23,-4.47 54.26))'),
(2,'POLYGON((-4.48 54.25,-4.40 54.25,-4.41 54.23,-4.48 54.23,-4.48 54.25))'),
(3,'POLYGON((-4.53 54.23,-4.44 54.29,-4.38 54.22,-4.53 54.23))');
Query
SELECT gid,ST_AsText(geom) FROM t
WHERE ST_Contains(geom,ST_MakePoint(-4.45, 54.25))
ORDER BY ST_Distance(geom,ST_MakePoint(-4.45, 54.25))
LIMIT 1;
gid | st_astext
-----+------------------------------------------------------------------------
1 | POLYGON((-4.47 54.26,-4.44 54.28,-4.41 54.24,-4.46 54.23,-4.47 54.26))
(1 Zeile)

Get Node from Coordinates (long, lat) in Open street maps

Using OSRM API, I found the coordinates of the intersections along a route.
I want to know what are the corresponding node IDs.
Is there any API to find the node IDS from the coordinate points?
Is there any API to find the node IDS from the coordinate points?
Yes. You need to pass annotations=nodes as additional query parameter. routes[i].legs[j].annotations.nodes will be an array of OSM IDs that you can use to link the data with OSM.
Linking this to the coordinates in the step is a little bit complicated: You would need to concatenate all RouteStep.geometry and remove the duplicated coordinates (steps[i].geometry[-1] == steps[i+1].geometry[0]).

Overpass API get nearby building boundaries from a coordinate(lat/lang)

How can i get the building boundaries with single coordinate using overpass API? Right now i have a coordinate(lat/lang) but with this i would like to get the building boundaries for that perticular coordinates.
Even is it possible to get the building boundaries near by my cordinates(lat/lang) ?
One way to achive this is to search buildings within certain radius from your point using around: function.
[out:json][timeout:25];
( // radius, lat, lon
node["building"](around:7.0, 52.2283207, 21.0133141);
way["building"](around:7.0, 52.2283207, 21.0133141);
relation["building"](around:7.0, 52.2283207, 21.0133141);
);
out body;
>;
out skel qt;

Get metric distance between two points via a PostgreSQL/PostGIS request

I have a question about the use of postgreSQL/postGIS.
I would like to display markers on a map (stored in a database) which are some distance away from the user (coordinates given to the request).
The type of the field of the markers is POINT (I store lat/long).
The user position is detetermined by the Google Map API.
Here is the actual request :
SELECT * FROM geo_points WHERE ST_distance(ST_SetSRID(geo_points.coords::geometry,4326),ST_GeomFromEWKT('SRID=4326;POINT(45.0653944 4.859764599999996)')) > 65
I know (after some research on internet) that the function ST_distance gives me the distance in degree between markers and the user position and that I test the distance in km.
I think I have to use the function ST_tranform to transform the points in metric coordinates.
So my questions are :
- what is the SRID for France
- how can I make this dynamically for the entire world according to the user position ?
I also kow that the function ST_within exists and that could do this. But I anticipate the fact that later, I could need the distance.
Any help would be greatly appreciated
ps: there are maybe solutions in other post, but all the answers I have found during my researches were not really meeting my needs.
Firstly, pay attention to the axis order of coordinates used by PostGIS, it should be long/lat. Currently you are searching in Somalia. Swapping to the coordinates, you would be searching in France.
You can use a geodesic calculation with the geography type, or use geodesic functions like ST_Distance_Spheroid. With the geography type, you may want to use ST_DWithin for higher performance.
Here are geo_points 65 m away or less from the point of interest in France (not Somalia):
SELECT * FROM geo_points
WHERE ST_Distance_Spheroid(
ST_Transform(geo_points.coords::geometry, 4326),
ST_SetSRID(ST_MakePoint(4.859764599999996, 45.0653944), 4326),
'SPHEROID["WGS 84",6378137,298.257223563]') < 65.0;
However, it will be very slow, since it needs to find the distance to every geo_points, so only do this if you don't care about performance and have less than a few thousand points.
If you change and transform geo_points.coords to store lon/lat (WGS84) as a geography type:
SELECT * FROM geo_points
WHERE ST_DWithin(
geo_points::geography,
ST_SetSRID(ST_MakePoint(4.859764599999996, 45.0653944), 4326)::geography,
65.0);

Mongodb GeoSpatial querying within shapes in collection

I have a collection that has a 2d geospatial index on a field (center) which is an array of long/lat, the collection also has a radius field. So each item can represent a circle. I know that mongodb has a operator $within, and I want to get a list of all items that contain a specific point [long,lat], but it seems that I can only check which points are within a specific shape.
You are correct, right now, you can't do what you want. Please file a feature request at http://jira.mongodb.org as I can't find one already existing for this.
This is how I solved it (i.e. get a shape that covers a given point) in my situation, using a basic grid. It has a limited accuracy, depending on the grid resolution:
create a collection "grid" with points that covers the common bounding box of all your shapes (use a nested for loop in javascript)
create a 2d index on the grid
for each shape, search for all the grid points that lie within the shape; label each grid point with the id of the shape (use an array attribute on the grid point)
To see in what shape(s) a point lies, search for the closest grid point, and return its assigned shape(s) property. First check for the common bounding box, because points outside it should always return 'not in any shape', and not use the closest grid point.
Depending on the precision you need, this might or might not be a usable solution. The accuracy depends on how many points you put in your grid, and you may be able to do something smart with local densities of your grid.