Created
May 2, 2013 12:21
-
-
Save derickson/5501852 to your computer and use it in GitHub Desktop.
geo code for guest blog post
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
xquery version "1.0-ml"; | |
declare namespace ns = "http://www.marklogic.com/MLU/logbook"; | |
declare variable $bbox as xs:string? := xdmp:get-request-field("BBOX", ()); | |
xdmp:set-response-content-type("text/kml; charset=utf-8"), | |
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2"> | |
<Document> | |
{ | |
(: If the bounding box was provided by Google Earth, use it for a geo query :) | |
let $pointQuery := | |
if ($bbox) then | |
let $lon1 := fn:number(fn:tokenize($bbox, ",")[1]) | |
let $lon2 := fn:number(fn:tokenize($bbox, ",")[3]) | |
let $lat1 := fn:number(fn:tokenize($bbox, ",")[2]) | |
let $lat2 := fn:number(fn:tokenize($bbox, ",")[4]) | |
let $west := fn:min(($lon1, $lon2)) | |
let $east := fn:max(($lon1, $lon2)) | |
let $north := fn:max(($lat1, $lat2)) | |
let $south := fn:min(($lat1, $lat2)) | |
let $boundingBox := cts:box($south, $west, $north, $east) | |
return cts:element-pair-geospatial-query( xs:QName("ns:Place"), | |
xs:QName("ns:Lat"), | |
xs:QName("ns:Lon"), | |
$boundingBox) | |
else | |
() | |
(: Perform the search - only geo search for simplicity :) | |
let $docs := cts:search(fn:doc(), $pointQuery, "unfiltered") | |
(: KML is Lon, Lat, Alt :) | |
for $doc in $docs | |
return | |
<Placemark> | |
<name>{$doc//ns:Site/text()}</name> | |
<description> | |
{$doc//ns:DiverLName/text()}, {$doc//ns:DiverFName/text()}: | |
{$doc//ns:Divedate/text()}<p>{$doc//ns:Comments/text()} | |
</description> | |
<Point> | |
<coordinates>{$doc//ns:Lon/text()}, {$doc//ns:Lat/text()}</coordinates> | |
</Point> | |
</Placemark> | |
} | |
</Document> | |
</kml> |
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
<doc xmlns="http://www.marklogic.com/MLU/logbook"> | |
<uniqueID>xyz123</uniqueID> | |
<Place> | |
<Lat>37.111</Lat> | |
<Lon> -77.123</Lon> | |
</Place> | |
... | |
</doc> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<results> | |
<doc ns="http://www.marklogic.com/MLU/logbook"> | |
<uniqueID>xyz123</uniqueID> | |
<Place> | |
<Lat>37.111</Lat> | |
<Lon>-77.123</Lon> | |
</Place> | |
</doc> | |
</results> |
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
xquery version "1.0-ml"; | |
declare namespace ns = "http://www.marklogic.com/MLU/logbook"; | |
let $center := cts:point(37.112, -77.121) | |
let $circle := cts:circle(0.2, $center) | |
let $pointQuery := | |
cts:element-pair-geospatial-query( | |
xs:QName("ns:Place"), | |
xs:QName(“ns:Lat”), | |
xs:QName(“ns:Lon”), | |
$circle) | |
return | |
cts:search(fn:doc(), $pointQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment