-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_geonames.xqy
29 lines (24 loc) · 1.07 KB
/
import_geonames.xqy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
xquery version "1.0-ml";
import module namespace info = "http://marklogic.com/appservices/infostudio" at "/MarkLogic/appservices/infostudio/info.xqy";
declare namespace geo = "http://marklogic.com/geospatial";
declare namespace gml = "http://www.opengis.net/gml";
let $path := "/Users/tarlij01/Desktop/MarkLogic-training/geospatial/london.xml"
let $doc := xdmp:document-get($path)
for $location in $doc//location
let $location-id := tokenize($location/id, ":")[last()]
let $lat-lon := concat($location/latitude/text(), " ", $location/longitude/text())
return
( xdmp:log(concat("Adding location:", $location-id)),
xdmp:document-insert(
concat("/locations/", $location-id, ".xml"),
<location xmlns:geo="http://marklogic.com/geospatial">
<id>{$location/id/text()}</id>
<name>{$location/name/text()}</name>
<latitude>{$location/latitude/text()}</latitude>
<longitude>{$location/longitude/text()}</longitude>
<gml:Point><gml:pos>{$lat-lon}</gml:pos></gml:Point>
</location>,
xdmp:default-permissions(),
xdmp:default-collections(),
10)
)