Created
April 26, 2012 05:45
-
-
Save robinkraft/2496318 to your computer and use it in GitHub Desktop.
First shot at using Hadoop with CartoDB, courtesy of Tim Robertson of GBIF
This file contains hidden or 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
| (ns validation | |
| (:use cascalog.api)) | |
| (defn build-query | |
| [lat lon] | |
| (let [lat-f (float lat) | |
| lon-f (float lon) | |
| ;;url_head "http://timrobertson100.cartodb.com/api/v2/sql?q=" | |
| ;;query_stub "select%20iso_a2%20from%20countries%20WHERE%20ST_DWithin(the_geom,%20ST_SetSRID(ST_Point(" | |
| url_head "http://viz2.cartodb.com/api/v2/sql?q=" | |
| query_stub "select%20name%20from%20wdpa_2012%20WHERE%20ST_DWithin(the_geom,%20ST_SetSRID(ST_Point(" | |
| ] | |
| (prn (str url_head query_stub)) | |
| (str url_head query_stub (format "%f,%f" lon-f lat-f) "),4326),%200.001)"))) | |
| (defn query | |
| [lat lon] | |
| (let [sql (build-query lat lon)] | |
| (:iso_a2 (first (:rows (parse-string (fetch-url sql) true)))))) | |
| (defn run-me | |
| [] | |
| (let [src [[1 0 -60] [2 0 -61]] | |
| ;;src (vec (repeatedly n (rand ) )) | |
| ] | |
| (<- [?id ?iso] | |
| (src ?id ?lat ?lon) | |
| (query ?lat ?lon :> ?iso)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment