Created
January 6, 2012 04:49
-
-
Save derickson/1569041 to your computer and use it in GitHub Desktop.
GeoReverseQuery
This file contains hidden or 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
| xquery version "1.0-ml"; | |
| (: a whole bunch of random circles to make the reverse-query harder :) | |
| let $n := 10000 | |
| for $count in (1 to $n) | |
| let $lat := xdmp:random(180) - 90 | |
| let $lon := xdmp:random(360) - 180 | |
| let $query-doc := | |
| let $a := cts:point( $lat,$lon) | |
| let $b := cts:point( $lat + 0.0001, $lon) | |
| let $circle := cts:circle( cts:distance($a, $b), $a) | |
| return | |
| <query> | |
| {cts:element-geospatial-query( xs:QName("point"), $circle , ("coordinate-system=wgs84"))} | |
| <a>{$a}</a> | |
| <b>{$b}</b> | |
| </query> | |
| return | |
| xdmp:document-insert( fn:concat("/circle-",$count,".xml"), $query-doc ); | |
| (: the actual matching circle :) | |
| let $query-doc := | |
| let $a := cts:point( 10.0005,36) | |
| let $b := cts:point( 10.00051,36) | |
| let $circle := cts:circle( cts:distance($a, $b), $a) | |
| return | |
| <query> | |
| {cts:element-geospatial-query( xs:QName("point"), $circle , ("coordinate-system=wgs84"))} | |
| <a>{$a}</a> | |
| <b>{$b}</b> | |
| </query> | |
| return | |
| xdmp:document-insert( fn:concat("/matching-cicle.xml"), $query-doc ) |
This file contains hidden or 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
| xquery version "1.0-ml"; | |
| (: the line of points which will become a reverse query to match circles:) | |
| let $a := cts:point( 10.0005, 36) | |
| let $b := cts:point( 10.00052, 36) | |
| let $distance := cts:distance($a, $b) | |
| let $bearing := cts:bearing($a, $b) | |
| let $steps := 100 | |
| let $step-distance := $distance div $steps | |
| let $points := | |
| for $i in (0 to $steps) | |
| return | |
| cts:destination($a, $bearing, $step-distance * $i) | |
| let $doc := | |
| <document>{ | |
| for $point in $points | |
| return | |
| <point>{$point}</point> | |
| }</document> | |
| return | |
| ( | |
| cts:search( /, cts:reverse-query( $doc ) ) , | |
| xdmp:elapsed-time() | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment