Get the nearest node from a coordinate in openstreetmap database - get

I have for example a coordinate:
41,791063, 12,6923072
and I want to find the nearest node in the OSM DB
in this example the node 906459460
http://www.openstreetmap.org/api/0.6/node/906459460
then I want to konw which ways is part of
in this example
http://www.openstreetmap.org/api/0.6/way/78456451
http://www.openstreetmap.org/api/0.6/way/76966153
http://www.openstreetmap.org/api/0.6/way/76965957
How can I do using the API? thanks

I don't think this is possible using the API directly, though I might be wrong.
http://en.wikipedia.org/wiki/Nearest_neighbor_search
is a general problem in computer science and I believe there are various ways to tackle it.

Related

How do I go about building this application?

So I have this application laid out but I am unsure on some aspects of how to go about it.
It's a website for dogs with cancer to supply a raw ketogenic diet for the user. There are other aspects of the website that I have figured out like where to hold state and such.
Where I'm a little confused on how to proceed is on the calculations for the ketogenic page shopping cart. The user can choose 1 fat source from the sources provided, one protein source and one green vegetable source. I want to make this as balanced and complete for the user for their dog- so obviously 1-protein 1 veg and 1 fat source is not balanced and complete. I need to factor in the amount of calories need per weight which I will have an input where the user can enter their dogs weight. I have done some of the math to make it complete and balanced on paper, factoring in amino acids, vitamins and minerals and the omega 6:3 ratio.
What I'm confused about is where am I going to hold all this data per se? It's a lot of data and it's based on many factors such as weight-activity, keto ratio like 1:1 or 2:1 depending what the user selects.
I obviously need a backend and need to build an API, but how would I return to the user the complete and balanced diet when so many other factors play in? Where would I store this other data? In objects? Variables? And then put it on the backend? I would greatly appreciate any help. Thanks in advance.
how are you? First of all, congrats on the great idea, I think it is great.
For starters, I think it's important for you, to lay down what technologies you'll be using.
1- Choose the technologies you are going to use. Will you use the MERN stack? React for front-end, mongo for the database, node.js for back-end with express.js as a framework?
2- Will you be the one providing all the data for the dog's diets? If not, find some website with an API for that data.
3- I am not any kind of expert on JS nor React.js, I'm just following the logic here. But does that data change? or is it always the same? I would advise you to use objects, so you can "play" with them, pass them around the classes (I would advise you to create a react class, where you store all of those objects, make sure you export that class)
4- Just lay everything out and START BUILDING!!! It sounds hella overwhelming to start such a big project, but once you get going some i's will be dotted, you will get a better understanding of what you actually are going to build.
5- Few tips, if you use an API you won't need to store the data, else store it on your database (JSON file, for example, there are great youtube tutorials on how to do so.)
Keeping this in mind, you asked where you'll be storing all that data, if you have an api, you won't store anything, if you don't, JSON is your best shot, it's really easy and intuitive to use and easy to read inside a react component.
I hope this gave you some extra clarification on what you'll need to do, in order to start.
PS: This answer is purely based on my limited React (and web dev) experience, I am no expert, let me know if there's anything else I can help you with.

Can a "points inside single geometry" query be sped up using a spatial index?

I am using SpatiaLite (or rather, its WebAssembly port SpatiaSQL.js) in a web application.
A use-case in this application is that the user wants to query point geometries (>500k of them, anywhere in the world) against a single (multi-)polygon geometry, filtering points which are not inside said geometry.
I don't know the (multi-)polygon in advance, because it is yielded by a dynamic mechanism. It could be e.g. a country, province, city, or a hand-drawn custom polygon.
Using a simple query with SpatiaLite's Within function works great. Performance is also great for small (multi-)polygons, such as a city. However, when querying against, say, Australia (a huge multi-polygon with many parts), performance suffers.
I am tied to SpatiaLite or a custom solution because most spatial database solutions cannot run in client-side JavaScript.
Sorry if this is an obvious question - I didn't find any similar questions so far.
Any thoughts on how to speed this up? Some loss of accuracy is acceptable.

How to create geocoding service (find polygons that intersect a given point)

SITUATION
I have a database with 2,000,000 cities. All of them have coordinates of the city center and mostly all - GeoJSON boundaries. I'm trying to implement a geocoding service that would find cities that intersect with a given point using node.js, mongodb, redis, memcached (and golang, if that is necessary, cause I'm just totally new to it )
PROBLEM
I know how to work with points (lat and lng) since both MongoDB and Redis support geoindexes but I've never seen anything about polygons.
I guess MongoDB won't really help cause of its speed (since it work on disks), but any memory database should deal with this problem. The thing is I can't even think of any way to implement it.
I'll be happy if someone point me how to make it. Thanks.
You may implement a point-in-polygon algorithm yourself. I've done something similar on https://api.3geonames.org
First do a bounding box to identify candidate polygons, then run a PIP. https://en.wikipedia.org/wiki/Point_in_polygon
geo.lua (https://github.com/RedisLabs/geo.lua) works with the requirements you have here but it's not very performant (not sure what has changed since last i checked).

Finding all geohashes within two bounding coordinates

I have coordinates, which are assigned a corresponding geohash in my database. Now I want to retrieve all of the coordinates within two bounding coordinates (top right and top left corner). How can I do that properly?
I tried getting the geohash that fits both of those bounding coordinates, but this solution does not work when they are in completely different regions of the world (so they are not sharing anything in common).
Is there a better way to do that?
Thanks for your help
Unfortunately, this isn't something you can do out-of-the-box with datastore / App engine. (There are no built in spatial queries.)
For early prototyping, etc., you can do it the hard way - retrieve all the rows, and discard the ones not meeting your query in code. Obviously, probably not viable with real production data.
See related question Query for Entities Nearby with Geopt for some possible production solutions.

Which are the best tools available for an online routing application?

So here's my question. Supposing that one is about to create an online web appliation that takes as user input a current location and a location for destination, and displays as a result one of the 5-6 available routes that are stored in a database that is most suitable in terms of distance,and Open Street Map data and Open Layers are used which would be the best way to make this happen?
What I am asking for is what would I need for:
1.Storing the data in database
2.Do the routing calculations. If I would like to change a bit the algorithms for academic reasons and have more control of my final result how would I do that? Do I need any programming language? Any good tutorials?
3.What is the difference between using pgRouting and using any custom solution(like mentioned above)? Doing the all the coding again by myself would be like reinventing the wheel?
4.What would be best for a commercial website, where fast calculations would be needed?
UPDATE: What I need is a way to connect 1.user input(as geometry points) 2.Routing algorithm I have written 3.Road Network and return a result in terms of best way to go to a point
Please see the list of online routers and offline routers for OSM as well as the general wiki page about routing with OSM.
If that still doesn't answer your questions, ask a more specific one.

Resources