Skip to content

Instantly share code, notes, and snippets.

@sterkenburgsara-zz
Last active February 17, 2016 17:25
Show Gist options
  • Save sterkenburgsara-zz/9716e7e8f5623425b521 to your computer and use it in GitHub Desktop.
Save sterkenburgsara-zz/9716e7e8f5623425b521 to your computer and use it in GitHub Desktop.
Calling GBIF API for data points & editing into GeoJSON using Feature Collection. Validation with GeoJSONLint.
xquery version "3.1";
declare option output:method 'json';
let $doc := fetch:text("http://api.gbif.org/v1/occurrence/search?limit=50&offset=0scientificName=Quercus%20macrocarpa&decimalLatitude=35.81,36.45&decimalLongitude=-87.21,-86.27
") => json:parse()
let $data :=
for $record in $doc//results/_
let $lat := xs:decimal($record/decimalLatitude/text())
let $long := xs:decimal($record/decimalLongitude/text())
let $id := $record/gbifID/text()
let $geom := [$lat, $long, $id]
let $objects :=
map {
"type": "Feature",
"geometry": map {
"type": "Point",
"coordinates": [$geom?2, $geom?1]
},
"properties": map{
"name": $geom?3
}
}
return $objects
return
map {
"type": "FeatureCollection",
"features": array {$data}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment