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
CREATE OR REPLACE FUNCTION geom2bin (geometry) | |
RETURNS text AS $$ | |
SELECT reverse(string_agg( | |
CASE WHEN i > 0 AND mod(i, 8) = 0 THEN ' ' ELSE '' END || | |
CASE | |
WHEN chr = '0' THEN '0000' | |
WHEN chr = '1' THEN '0001' | |
WHEN chr = '2' THEN '0010' | |
WHEN chr = '3' THEN '0011' | |
WHEN chr = '4' THEN '0100' |
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
xmlstarlet ed --inplace -P \ | |
-s "//web-app" -t elem -n TEMPNODE -v "" \ | |
-s "//TEMPNODE" -t elem -n "filter-name" -v "cross-origin" \ | |
-s "//TEMPNODE" -t elem -n "filter-class" -v "org.eclipse.jetty.servlets.CrossOriginFilter" \ | |
-r "//TEMPNODE" -v "filter" \ | |
-s "//web-app" -t elem -n TEMPNODE -v "" \ | |
-s "//TEMPNODE" -t elem -n "filter-mapping" \ | |
-s "//TEMPNODE" -t elem -n "filter-name" -v "cross-origin" \ | |
-s "//TEMPNODE" -t elem -n "url-pattern" -v "/*" \ | |
-r "//TEMPNODE" -v "filter-mapping" \ |
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
require(raster) | |
# round resolution to nearest arc second | |
snap_res <- function(r) { | |
round(res(r)*3600)/3600 | |
} | |
# make sure extent fits cleanly onto a grid | |
# having its origin at -180, -90 | |
snap_extent <- function(r) { |
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
#!/usr/bin/env bash | |
set -e | |
display_usage() { | |
echo "Extract a slice from a netCDF and remove the variable" | |
echo "extract.sh [in] [dimension] [value] [out]" | |
echo "" | |
echo "Example: extract.sh temperature.nc elevation 2 temperature_2.nc" | |
} |
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
<!DOCTYPE connections> | |
<qgsXYZTilesConnections version="1.0"> | |
<xyztiles url="https://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png" password="" zmin="0" zmax="19" name="CartoDB Positron" username="" referer="" authcfg=""/> | |
<xyztiles url="https://a.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}{r}.png" password="" zmin="0" zmax="19" name="CartoDB Positron Labels" username="" referer="" authcfg=""/> | |
<xyztiles url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}" password="" zmin="0" zmax="18" name="ESRI Topo" username="" referer="" authcfg=""/> | |
<xyztiles url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}" password="" zmin="0" zmax="18" name="ESRI World Imagery" username="" referer="" authcfg=""/> | |
<xyztiles url="https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}" password="" zmin="0" zmax="16" name="ESRI World Light Gray" username |
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
#!/usr/bin/env bash | |
set -e | |
YEARMON=$1 | |
# Computes the percent of land area and population of each country that is experiencing water anomalies (surplus or deficit) | |
# of return periods >= 10 or 30 years. Output as two CSVs (one for population percent and one for area percent) each with | |
# four coulums: (pct exposed to 10-yr deficit, pct exposed to 30-yr deficit, pct exposed to 10-yr surplus, pct exposed to 30-yr surplus) | |
# Uses exactextract to handle pixels that are partially covered by country polygons. | |
# Uses gdal_calc to make a set of four mask rasters that are passed as weights (0 or 1) to exactextract. |
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
> TRUE + TRUE | |
[1] 2 | |
> !FALSE + !FALSE | |
[1] FALSE | |
> !FALSE == TRUE | |
[1] TRUE | |
> (!FALSE) + !FALSE | |
[1] 2 |
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
library(exactextractr) | |
library(raster) | |
library(stars) | |
library(sf) | |
# define quad bounds using a GeoJSON string | |
quad_bounds <- st_read("{\n \"coordinates\": [\n [\n [\n [\n -98.97075, \n 46.7021\n ], \n [\n -98.6657, \n 47.44555\n ], \n [\n -97.48445, \n 47.27325\n ], \n [\n -97.7895, \n 46.5298\n ], \n [\n -98.97075, \n 46.7021\n ]\n ]\n ]\n ], \n \"type\": \"MultiPolygon\"\n}\n") | |
# create a stars proxy for the s3 object | |
scene <- read_stars('/vsis3/bucket-name-here/dataGlobal/landsat/8/031/027/LC08_L1TP_031027_20161107_20170219_01_T1/LC08_L1TP_031027_20161107_20170219_01_T1_TCT.tif', |
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
-- create point table using single-precision coordinates | |
CREATE TABLE pts ( | |
point_id serial, | |
x real, | |
y real | |
); | |
-- create a view that converts these into a PostGIS geometry | |
CREATE VIEW pts_view AS | |
SELECT point_id, ST_SetSRID(ST_MakePoint(x, y), 4326) AS geom FROM pts; |
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
select st_difference(st_expand(st_envelope(geom), 100), geom) from | |
(select st_unaryunion(st_transform(st_union(geom), 2163)::geometry(geometry, 2163)) as geom from ne_50m_land) sq; |