I’ve created a brainstorming document for geo spatial queries:
Anyone who is interested please take a look and provide suggestions on what we can implement in the first version.
Data Types
Supported GIS features are the 7 OpenGIS simple features:
- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- GeometryCollection
Types of supported columns
Geometry:
- Features are in a 2-D Euclidean space. All calculations done in 2-D.
Geography
Features are lat-long positions on Earth. Calculations are done using an ellipsoidal (round-earth) model. Polygons have a left-hand orientation. Default model for earth: WGS 84: EPSG Projection -- Spatial Reference (World Geodetic System - Wikipedia)
Format
Well Known Text (WKT) & Well Known Binary (WKB)
http://docs.opengeospatial.org/is/12-063r5/12-063r5.html
GeoJson
Input/output format can be WKT or GeoJson.
Storage format should be WKB (as expected by RocksDB spatial index)
Go implementation of all 3 formats: GitHub - twpayne/go-geom: Package geom implements efficient geometry types for geospatial applications.
Query Operators:
Possible query operators:
- within (mongo, sql, postgis, mysql): whether one geometry is completely within another E.g. Find me all restaurants whose location is within ‘polygon representing border of Menlo Park’
- intersect (mongo, sql, postgis, mysql): whether two geometries intersect each other E.g. find me all US states whose borders intersect ‘polygon for route 66’
- disjoint(sql, postgis, mysql): not intersect
- distance (sql, postgis, mysql): return minimum distance
Useful for nearest neighbor queries (MongoDB uses near and does not expose the distance)
E.g. find me all gas stations whose location is closest to my location, sort ascending by distance.
Storage
RocksDB Spatial indexing:
http://rocksdb.org/blog/2039/spatial-indexing-in-rocksdb/
Supports indexing bounding boxes. Index can be used to query all intersecting bounding boxes at a “level”. Supports multiple “levels” in the same index.
Note: This is not an actual R-tree index, but rather a single level index. Multiple levels are managed by the client by specifying the “level” for each feature.
Calculations are done in euclidean space. We will have to apply a geographic calculation on top of that.
Build our own index as described: Spatial Indexes Overview - SQL Server | Microsoft Learn
References
- PostGIS: PostGIS 2.2.8 Manual
- Mongo DB queries: https://docs.mongodb.com/manual/reference/operator/query-geospatial/
- SQL Server: Spatial Data (SQL Server) - SQL Server | Microsoft Learn
- MySQL: https://dev.mysql.com/doc/refman/5.7/en/spatial-extensions.html
- GeoSparQL: GeoSPARQL - A Geographic Query Language for RDF Data - Open Geospatial Consortium