Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: support location queries (geospatial indexing) #19313

Closed
vivekmenezes opened this issue Oct 17, 2017 · 27 comments
Closed

sql: support location queries (geospatial indexing) #19313

vivekmenezes opened this issue Oct 17, 2017 · 27 comments
Labels
A-sql-datatypes SQL column types usable in table descriptors. A-sql-semantics C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community

Comments

@vivekmenezes
Copy link
Contributor

vivekmenezes commented Oct 17, 2017

http://postgis.net/ is an example of a Postgres extension that supports location queries.

If you would like cockroachdb to support geospatial indexes for your project please do vote for this feature. We would also appreciate specific details on how you might use this feature so we can support you within the scope we define for this feature.

Thanks!

@dianasaur323 dianasaur323 added the O-community Originated from the community label Oct 18, 2017
@awoods187
Copy link
Contributor

Community request: what are some use cases that you want to use geospatial indexing for?

@grantcarthew
Copy link

Quote:

A common query used with spatial data is the Nearest Neighbor query. Nearest Neighbor queries are used to find the closest spatial objects to a specific spatial object. For example a store locator for a Web site often must find the closest store locations to a customer location.

Source: https://docs.microsoft.com/en-us/sql/relational-databases/spatial/query-spatial-data-for-nearest-neighbor

I have a Postgres database using PostGIS which contains address details of multiple locations. The users can search for the nearest location.

@johanneswuerbach
Copy link

The SaaS provider I work for provides the following query capabilities currently backed by postgis: finding points within a bounding box, within a radius around a given point or to generally order points by distance to known point x

So far those seem to solve most of our customer use cases.

@andressrg
Copy link

Most of my use cases involve being able to calculate distance between 2 GPS points.

@SpatialJ
Copy link

SpatialJ commented Apr 5, 2018 via email

@orofarne
Copy link

PostGIS functionality is excellent!

@knz knz added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Apr 28, 2018
@knz knz added this to Triage in (DEPRECATED) SQL Front-end, Lang & Semantics via automation Apr 28, 2018
@knz knz moved this from Triage to Feature requests / nice-to-have in (DEPRECATED) SQL Front-end, Lang & Semantics Apr 28, 2018
@knz knz added C-wishlist A wishlist feature. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) and removed C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) C-wishlist A wishlist feature. labels May 2, 2018
@knz knz added A-sql-datatypes SQL column types usable in table descriptors. A-sql-semantics labels May 15, 2018
@kevinmartinjos
Copy link

kevinmartinjos commented May 16, 2018

Would love to see this in CRDB. Would make CRDB more appealing to small personal projects - get some geospatial data, put them in CRDB, run fancy queries (get me all users within 10km radius of this user) against it.

@gpiffault
Copy link

gpiffault commented Jun 1, 2018

One of my use cases is to find segments within a radius of a point (all in GPS coordinates). I think the most useful part would be efficiently finding geometries within a bounding box, everything else can be done relatively easily at the application level. Something along the lines of rbush for example.

@DeoLeung
Copy link

will be great to enable using postgis/pgrouting, the rest is up to people how to use the functions

@gsf
Copy link

gsf commented Dec 21, 2018

Most of our queries involve ST_Within to filter down to all points or geoms within a specified geom.

@jefferypalmer
Copy link

We are greatly interested in a database solution that scales out well (CRDB) and has geospatial support. We run queries that include: reverse geocoding, map tile generation, polygon/geofence search results, and analytics (combining geospatial data with other fields or cubes).

@lastzero
Copy link

lastzero commented Apr 4, 2019

If you just want to find results that are within a certain max distance / radius, you don't need "geospatial support", some math will do: https://developers.google.com/maps/solutions/store-locator/clothing-store-locator#findnearsql

@jefferypalmer
Copy link

Thanks for the suggestion, but this is a non indexable solution that requires a full table scan. This could work for some very limited use cases by converting the lat lon point to 2 decimal columns and index those for a quick 'am I in this box' type of searches but this doesn't get us very close in our application for polygon searches. Any insight you have is helpful so if you come across more solutions, send them over! Thanks.

@lastzero
Copy link

@darren1713 It doesn't require a full table scan if you index lat/long and only calculate the actual distance within a bounding box, see https://mariadb.com/kb/en/library/latitudelongitude-indexing/

More precise and polygon searches in very large data sets can be an issue though. Also coordinates near the poles from what I remember. In our case, it was fast enough (< 100ms) for searching the customer database of a large German cable internet provider.

@Samusername
Copy link

Samusername commented Apr 25, 2019

The requested featureset would be important,
"Simple features".

@jordanlewis jordanlewis moved this from Triage to Lower priority backlog in [DEPRECATED] Old SQLExec board. Don't move stuff here Apr 30, 2019
@moftak-dev
Copy link

any update on this?

@moftak-dev
Copy link

my requirement is to get all data nearest to a certain point (lat, long). i-e i have list of users with lat long and i want to get all those user nearest to my location (lat, long) any suggestion how we can achieve this in cockroach database?

@antoniomo
Copy link

On app logic side, you can use S2 to achieve this.

For example as explained here: https://blog.nobugware.com/post/2016/geo_db_s2_geohash_database/

Another worked out example in Go code: https://gist.github.com/antoniomo/3371e44cbe2f0cc75a525aac0d188cfb

Note that the actual SQL queries are not in those examples, but it's straightforward to represent those after you understand the idea.

@moftak-dev
Copy link

@antoniomo but i want to query on database level. do you think i need to look into other database for this ?

@lastzero
Copy link

@moftak-dev How fast do you think developers are with releasing this requested feature? Send a pull request, if you need it now 💎

You're welcome copy our evil hack, which uses an estimated bounding box instead of the exact distance:
https://github.com/photoprism/photoprism/blob/develop/internal/photoprism/search.go#L211

It's good enough for many applications, you can test it here: https://demo.photoprism.org/places?q=&lat=52.459677899999996&long=13.321888699999999&dist=20

@moftak-dev
Copy link

@lastzero but how can we integrate this with my nodejs app where i want to pull nearest location from database ?

@lastzero
Copy link

lastzero commented May 23, 2019

@lastzero but how can we integrate this with my nodejs app where i want to pull nearest location from database ?

Use this SQL where condition: (lat BETWEEN ? AND ?) AND (long BETWEEN ? AND ?)

Ranges must be estimated / calculated, see our Go source code or google it :)

If you need the distance in km, you need some additional calculations, see the link I posted here earlier. Doesn't take very long, if you use a bounding box to limit results upfront.

@zgalic
Copy link

zgalic commented Aug 11, 2019

All traditional DBMS (Oracle, MS SQL Server, PostgreSQL, MySQL, etc.) support spatial data types (and operations on them).
Without them CRDB will not be an option for systems/applications that manage spatial data.

@awoods187
Copy link
Contributor

awoods187 commented Oct 24, 2019

Hi all, I'm a product manager at Cockroach Labs. We are interesting in collecting some anonymized data about what kind of feature support you might need for geospatial indexing. We'd really appreciate it if you could fill out this short 3 minute survey. This information will be critical to promoting support for geospatial into the roadmap. https://www.surveymonkey.com/r/WQTL8BY

@awoods187
Copy link
Contributor

Thank you to everyone who filled out the last survey. We have started work to add support for geospatial indexing! You can follow along on this issue!

In the meantime, we have a quick follow-up survey aimed at understanding performance expectations as well as third-party tooling usage. We'd greatly appreciate any feedback you may have here!

@otan
Copy link
Contributor

otan commented May 15, 2020

Hello friends monitoring this thread.

We're on our way to building Geospatial features. We want to know which builtins are a priority for us to implement - so we're asking you for help!

Here are two labels which group together implemented PostGIS functions. If you see a function you use for your geospatial applications, let us know by reacting on the issue.

Note we are only focusing on 2D functions for now.

(If you feel like taking an issue on, feel free! We're happy to review and accept your contribution. The ones marked E-easy are the ones we think are good introductory ones.)

@otan
Copy link
Contributor

otan commented Nov 12, 2020

With v20.2 out with spatial support (https://www.cockroachlabs.com/blog/spatial-data), we'll be closing this issue. Missing features can be dealt with in subsequently filed issues!

@otan otan closed this as completed Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-datatypes SQL column types usable in table descriptors. A-sql-semantics C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community
Projects
No open projects
(DEPRECATED) SQL Front-end, Lang & Se...
  
Feature requests / pie-in-the-skie
Development

No branches or pull requests