Last active
February 17, 2016 17:25
-
-
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.
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 "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