RethinkDB 1.15: Geospatial queries
rethinkdb.com
rethinkdb.com
It's great and fun to build apps with and all of the guys at Rethink are incredibly helpful (even with my sometimes naive questions).
I feel bad to bring this up because it is not the rethinkdb authors' fault (as this is a third-party client) but from this user's perspective it took me some debugging before I realized that rethinkdb wasn't necessarily slow.
That being said this update brings a couple of great new features and I look forward to see what else comes.
I am now looking to do this whole process in a much simpler way in the next release which will solve the issue mentioned by evmar. I think its also worth mentioning that both RethinkDB and my driver are not yet production ready but both projects are getting there.
We'll be doing a live webcast[1] today at 1:30pm PT showcasing geo features and some example apps you can build with them, would love for you to join us!
[1] http://www.meetup.com/RethinkDB-Bay-Area-Meetup-Group/events...
How many dimensions are supported?
Also, does this support many projections, or just a few. I see "geoSystem: 'WGS84'" which isn't an EPGS identifier. Along those lines, are distance calculations done on a geodesic, a plane, or is that configurable (some projections are a planer, others aren't).
Also, what does this mean? geometry.distance(geometry[, {geoSystem: 'WGS84', unit: 'm'}]) Does this do a correct interpolation of degrees to meters along the path (again based on the projection) or is there a fixed constant?
EDIT: Are there commands to export WKT or WKB?
Thanks, will fix momentarily! EDIT: fixed, thanks!
> How many dimensions are supported?
Two dimensions. The commands are designed primarily with Earth geometry in mind to help people build location-aware apps.
> Also, does this support many projections, or just a few.
It supports WGS84 (a commonly used ellipsoid model) or a unit sphere. Currently you can't use a plane. Check out http://rethinkdb.com/api/javascript/get_nearest/ for an example.
> Does this do a correct interpolation of degrees to meters along the path
The implementation is based on the S2 library (https://code.google.com/p/s2-geometry-library/) also used by PostGIS, which AFAIK does spherical linear interpolation.
> Are there commands to export WKT or WKB?
No, currently only GeoJSON (which you could later post-process and export to other formats with existing tools). This is a great idea, though, if there is more demand for it we'll definitely add other exporters.
EDIT: all great questions, I opened an issue in the doc repo (https://github.com/rethinkdb/docs/issues/521) -- we'll address all of these in the docs.
> Commands to create points, lines, polygons and circles
All of the links in that sentence 404.
Note that RethinkDB actually doesn't use S2 for computing distances. S2 is used for computing intersections and for indexing though. (also as another poster already pointed out, S2 is not used by PostGIS)
Earth has elevations:)
I don't mean to sound disparaging, for it's use-case it's a great addition:)
RethinkDB doesn't do any planar projections of spherical coordinates (if that's what you are asking for). There are many independent tools available to perform such projections if you need to draw a map or convert to a Euclidean coordinate system. As coffemug noted, WGS84 is not a projection but just a reference ellipsoid used for distance calculations along earth's surface. (Edit: Ok, I guess that can be considered a projection as in projection from earth's actual geometry onto an ellispoid. It's not a projection with respect to latitude and longitude though, if that makes sense.)
> Along those lines, are distance calculations done on a geodesic
Yes, along the geodesic between the two points on an oblate ellipsoid. We use the algorithm from Karney 2013, see http://charles.karney.info/biblio/papers/karney13-geod.pdf
> geometry.distance(geometry[, {geoSystem: 'WGS84', unit: 'm'}]) Does this do a correct interpolation of degrees to meters along the path (again based on the projection)
Yes, again using Karney's algorithm (but not by doing a projection first).
Fair enough, it only handles a single GCS and no PCSs.
WGS84 is more than just a datum, it is a GCS. It's also used for more than just distances; it defines a mean sea level used for elevation as well.
WGS84 is also used to mean EPSG 4326, hence why I asked like I did.
> There are many independent tools available to perform such projections if you need to draw a map or convert to a Euclidean coordinate system
Sure there are, but if I can't import EPGS 4269 (NAD83, used by the census), EPGS 3857 (Spherical Mercator), a state plane, or a UTM data source without first converting it, then I need to know that.
If you have data in other projections you will definitely have to convert it first.
On a side-note, in case it's of any help: There is a currently undocumented feature that allows you to specify an oblate reference ellispoid other than the one from WGS 84 in ReQL. The way you do that is by passing an object `{a: ..., f: ...}` to the `geo_system` optional argument. The value of 'a' must be the major radius of the ellipsoid in meters, and 'f' must be the flattening of the ellipsoid. This feature is not heavily tested though and should be used with caution.
deb http://download.rethinkdb.com/apt lucid main
Is there a better wheezy package source? The following NEW packages will be installed:
rethinkdb{b}
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 14.3 MB of archives. After unpacking 39.1 MB will be used.
The following packages have unmet dependencies:
rethinkdb : Depends: libssl0.9.8 (>= 0.9.8k-1) which is a virtual package.
The following actions will resolve these dependencies:
Keep the following packages at their current version:
1) rethinkdb [Not Installed]It looks like the lucid package is no longer compatible with wheezy.
You may have better luck using precise, trusty or saucy instead of lucid in your sources.list
I will run some tests and update the docs on rethinkdb.com.
There's a bunch of open source databases that have fancy features like this now, is there much sharing of code or implementation ideas between the projects? Did you look at the source of for example Mongo or PostGIS, or is it mainly implementing algorithms from papers?
- Runs in browser, for client-side indexing.
- Based off of tiles, instead of s2's 6-faced-cube thing. This allows it to be used with a lot of well established tools and mathematical formulas. Also much easier to reason about IMHO.
- Indexes points about twice as fast at the moment.
I also use s2, and it really is terrific. There are many cases where s2 is the superior choice (mostly due to its hilburt curve indexing scheme).
Proj4 is for working with projections. It comes with a handy command line tool that lets you easily perform chores like converting between coordinate systems/projects.
GEOS is a C++ library (with a C API on top) that's actually a port of a Java library called JTS. It's used for expressing structured geometry/geography primitives and performing calculations on them, as well as encoding/decoding them in the WKT/WKB (text and binary respectively) formats (the PostGIS "geometry" data type). All the geometry testing and manipulation functions, eg. ST_Intersects(), use GEOS.
GEOS actually comes with support for a spatial index called STR, or STRtree, but I believe it's not used by PostGIS. Instead, PostGIS uses Postgres' own GiST, which is a generalization of R-trees that perform better in a relational environment.
[1]http://blog.notdot.net/2009/11/Damn-Cool-Algorithms-Spatial-...
We looked into some other data structures before settling for our current approach. Using a space-filling curve turned out to be the least error-prone to implement given that we already have a highly optimized and well tested btree implementation in RethinkDB.
Sorry to be so curt, but I've spent over 15 minutes researching and by now I feel like I should have an high level understanding of the advantage of this database.
- It has changfeed, so you can push notifications to client when something changes on the database. You can build real time application. For example if your http server is NodeJS, plug SockJS for the browser, and RethinkDB for your database, and your whole stack is reactive.
- The query language is way nicer to use (it's embedded in the host language).
That's the 3 main differences for a web developer I can think of on top of my head.
r.table("users").changes().filter(function(change) { return change("new_val")("location").distance( r.point(<someLongitude>, <someLatitude>).lt(<someDistance>) })
I think the real killer mix is geo + sync (because then you can trivially share civic data). Maybe someday we'll see sync from Rethink?