Skip to content

Instantly share code, notes, and snippets.

@timrobertson100
Created August 9, 2017 18:29
Show Gist options
  • Save timrobertson100/c8af23f14023aa5000d311f0fe4b4864 to your computer and use it in GitHub Desktop.
Save timrobertson100/c8af23f14023aa5000d311f0fe4b4864 to your computer and use it in GitHub Desktop.
SQL for Exports for Tom A.

Please review SQL before using the data:

One degree

CREATE TABLE tim.one_deg ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' AS
SELECT 
  floor(decimalLatitude) AS lat,
  floor(decimalLongitude) AS lng,
  count(*) AS total
FROM 
  prod_a.occurrence_hdfs
WHERE
  hasGeospatialIssues = false AND 
  decimalLatitude is not null AND 
  decimalLongitude is not null AND
  year >= 2000
GROUP BY
  floor(decimalLatitude),
  floor(decimalLongitude)

0.5 degrees

CREATE TABLE tim.zero_five_deg ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' AS
SELECT 
  (floor(2 * decimalLatitude)) / 2 AS lat,
  (floor(2 * decimalLongitude)) / 2 AS lng,
  count(*) AS total
FROM 
  prod_a.occurrence_hdfs
WHERE
  hasGeospatialIssues = false AND 
  decimalLatitude is not null AND 
  decimalLongitude is not null AND
  year >= 2000
GROUP BY
  (floor(2 * decimalLatitude)) / 2,
  (floor(2 * decimalLongitude)) / 2

0.1 degrees

CREATE TABLE tim.zero_one_deg ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' AS
SELECT 
  round(decimalLatitude,1) AS lat,
  round(decimalLongitude,1) AS lng,
  count(*) AS total
FROM 
  prod_a.occurrence_hdfs
WHERE
  hasGeospatialIssues = false AND 
  decimalLatitude is not null AND 
  decimalLongitude is not null AND
  year >= 2000
GROUP BY
  round(decimalLatitude,1),
  round(decimalLongitude,1)

0.01 degrees

CREATE TABLE tim.zero_zero_one_deg ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' AS
SELECT 
  round(decimalLatitude,2) AS lat,
  round(decimalLongitude,2) AS lng,
  count(*) AS total
FROM 
  prod_a.occurrence_hdfs
WHERE
  hasGeospatialIssues = false AND 
  decimalLatitude is not null AND 
  decimalLongitude is not null AND
  year >= 2000
GROUP BY
  round(decimalLatitude,2),
  round(decimalLongitude,2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment