How to create geocoding service (find polygons that intersect a given point) - node.js

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).

Related

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.

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.

How to extract point coordinates from VTK Points

I use a library that gives me at the end the vtkpoints. Now I would like to extract points
from them. But all the method available from VTKPoints require point id, which i do not know.
Is there a way of doing it?
I can't offer a definitive answer, since the VTKPoints documentation doesn't discuss the values of the point ids and I don't have any experience with this. However, all of the examples I have seen just use integers in the range [0..NumberOfPoints-1] as the point ids, so it would seem that what you are doing is perfectly reasonable (note, however, that your comment I am using the indexes: 0..NumberOfPoints should be 0..NumberOfPoints-1).
The points are definitely just stored in a vector-like container with sequential indexing from 0 to GetNumberOfPoints()-1.

Fixing an incorrectly taken 3D head scan

The problem I am facing is following.
I have a number of 3D head scans, some of them are taken correctly (like attached example) but in many it is easy to see that the scanned person had his head not exactly aligned with the machine's front and thus one side of the texture (and depth map) seems to be "wider" (the exact reason is that one side was taken more from behind, it can be easily seen if you look at the ears).
Fortunately when I go from the cylindrical coordinates to carthesian ones and render the face with XNA, the face is symmetrical.
Now the thing is that I would like the texture and depth maps of all my heads by as nice and symmetrical as the correct one (because later i want to align them and perform PCA).
The idea I have at the moment is that I could interpolate the surfaces between all of the vertices and from those interpolations take new vertices that are equally distanced from each other.
This solutions seems a lot of work and maybe its an overkill.
Maybe there is some other way (like geting that interpolation data from DirectX/XNA that has to calculate it at some point anyway).
I will be most thankful for helpful answers.
The correct example:
http://i55.tinypic.com/332mio2.jpg
Incorrect example:
http://i54.tinypic.com/309ujvt.jpg
It's probably possible to salvage (some of) the bad scans to some degree using some coordinate transformations, but you would have to guess the "incorrectness" of the alignment and it's probably impossible to do automatically.
But, unless the original subject is dead (or otherwise unavailable); it's probably a lot easier to redo the scans.
Making another scan is very likely to be quicker, and you won't loose quality as transforming the bad scans probably will. The nose on the incorrect sample seems to be shadowing the side of the nose, and no fancy algorithm can ever fix the missing data.

Get the nearest node from a coordinate in openstreetmap database

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.

Resources