Skip to content

Instantly share code, notes, and snippets.

@Ramona2020
Last active February 12, 2016 22:21
Show Gist options
  • Save Ramona2020/fa20f47742fc52a29464 to your computer and use it in GitHub Desktop.
Save Ramona2020/fa20f47742fc52a29464 to your computer and use it in GitHub Desktop.
FeatureCollection - Collection points from api and output geojson
xquery version "3.1";
declare option output:method 'json';
map { "type": "FeatureCollection",
"features": array {
(let $doc := fetch:text("http://api.gbif.org/v1/occurrence/search?limit=300&offset=0scientificName=Quercus%20macrocarpa&decimalLatitude=35.81,36.45&decimalLongitude=-87.21,-86.27") => json:parse()
for $record in $doc//results/_
let $lat := xs:decimal($record/decimalLatitude/text())
let $long := xs:decimal($record/decimalLongitude/text())
let $identifier := $record/gbifID/text()
let $geom := [$lat, $long, $identifier]
let $objs :=
map {
"type": "Feature",
"geometry": map {
"type": "Point",
"coordinates": [$geom?2, $geom?1]
},
"properties": map {
"name": $geom?3
}
}
return $objs) }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment