geokml.geospatialQueryFromElements( regions as Node[], [options as String[]], [weight as Number?] ) as cts.query
Returns a cts:query matching points within given regions.
The point value is expressed in the content of the element as a pair of numbers, separated by whitespace and punctuation (excluding decimal points and sign characters).
Point values and boundary specifications of boxes are given in degrees relative to the WGS84 coordinate system. Southern latitudes and Western longitudes take negative values. Longitudes will be wrapped to the range (-180,+180) and latitudes will be clipped to the range (-90,+90).
If the northern boundary of a box is south of the southern boundary, no points will match. However, longitudes wrap around the globe, so that if the western boundary is east of the eastern boundary, then the box crosses the anti-meridian.
Special handling occurs at the poles, as all longitudes exist at latitudes +90 and -90.
This function will take into account interior polygons, if any, and properly construct the query to account for them.
xquery version "1.0-ml"; (: create a document with test data :) xdmp:document-insert("/points.xml", <root xmlns:kml="http://www.opengis.net/kml/2.2"> <item><kml:Point><kml:coordinates>30.0,10.5</kml:coordinates></kml:Point></item> <item><kml:Point><kml:coordinates>35.34,15.35</kml:coordinates></kml:Point></item> <item><kml:Point><kml:coordinates>40.55,5.11</kml:coordinates></kml:Point></item> </root> ); xquery version "1.0-ml"; import module namespace geokml = "http://marklogic.com/geospatial/kml" at "/MarkLogic/geospatial/kml.xqy"; declare namespace kml="http://www.opengis.net/kml/2.2"; cts:search(doc("/points.xml")//item, geokml:geospatial-query-from-elements( <kml:LatLongBox> <kml:north>20.0</kml:north> <kml:south>10.0</kml:south> <kml:east>40.0</kml:east> <kml:west>35.0</kml:west> </kml:LatLongBox>) ) (: returns the following node: <item> <kml:Point xmlns:kml="http://www.opengis.net/kml/2.2"> <kml:coordinates>35.34,15.35</kml:coordinates> </kml:Point> </item> :) , cts:search(doc("/points.xml")//item, geokml:geospatial-query-from-elements( <kml:LatLongBox> <kml:north>20.0</kml:north> <kml:south>10.0</kml:south> <kml:east>35.0</kml:east> <kml:west>40.0</kml:west> </kml:LatLongBox>) ) (: returns the following nodes (wrapping around the Earth): <item><kml:Point xmlns:kml="http://www.opengis.net/kml/2.2"> <kml:coordinates>30.0,10.5</kml:coordinates> </kml:Point></item> :)
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.