-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
51898: geo: order geospatial objects by Hilbert Curve index r=sumeerbhola a=otan This follows the [PostGIS way](https://info.crunchydata.com/blog/waiting-for-postgis-3-hilbert-geometry-sorting), but does not follow the same encoding. Visualisation for Geometry for 10000 random points: ![image](https://user-images.githubusercontent.com/3646147/88688829-9a4f5a00-d0ae-11ea-9618-0179fb7ac327.png) Visualisation for Geography 10000 random points: ![image](https://user-images.githubusercontent.com/3646147/88449411-93e58780-cdfb-11ea-9e85-eff8c5a94787.png) Release note (sql change): When ordering by geospatial columns, it will now order by the Hilbert Space Curve index so that points which are geographically similar are clustered together. 52168: sql: support synchronous_commit and enable_seqscan as dummy no-op r=rytaft a=otan These vars are set by `osm2pgsql` and `ogr2ogr` respectively. These default to the ON state, the OFF state affects performance but not correctness. Touches #51818. Release note (sql change): Support the setting and getting of the `synchronous_commit` and `enable_seqscan` variables, which do not affect any performance characteristics. These are no-ops enabled to allow certain tools to work. 52265: build: avoid errors when tar closes curl's pipe r=dt a=dt Release note: none. Co-authored-by: Oliver Tan <[email protected]> Co-authored-by: David Taylor <[email protected]>
- Loading branch information
Showing
19 changed files
with
597 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package geo | ||
|
||
// hilbertInverse converts (x,y) to d on a Hilbert Curve. | ||
// Adapted from `xy2d` from https://en.wikipedia.org/wiki/Hilbert_curve#Applications_and_mapping_algorithms. | ||
func hilbertInverse(n, x, y uint64) uint64 { | ||
var d uint64 | ||
for s := n / 2; s > 0; s /= 2 { | ||
var rx uint64 | ||
if (x & s) > 0 { | ||
rx = 1 | ||
} | ||
var ry uint64 | ||
if (y & s) > 0 { | ||
ry = 1 | ||
} | ||
d += s * s * ((3 * rx) ^ ry) | ||
x, y = hilbertRotate(n, x, y, rx, ry) | ||
} | ||
return d | ||
} | ||
|
||
// hilberRoate rotates/flips a quadrant appropriately. | ||
// Adapted from `rot` in https://en.wikipedia.org/wiki/Hilbert_curve#Applications_and_mapping_algorithms. | ||
func hilbertRotate(n, x, y, rx, ry uint64) (uint64, uint64) { | ||
if ry == 0 { | ||
if rx == 1 { | ||
x = n - 1 - x | ||
y = n - 1 - y | ||
} | ||
|
||
x, y = y, x | ||
} | ||
return x, y | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.