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
INSTALL spatial; | |
LOAD spatial; | |
.mode tabs | |
SELECT | |
postcode, | |
ST_AsGeoJSON(CASE WHEN ST_Area(hull) > 0 THEN hull ELSE ST_Centroid(hull) END) AS geometry | |
FROM ( | |
SELECT |
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
import got from 'got' | |
import fs from 'node:fs' | |
import path from 'node:path' | |
const API_BASE = 'https://data.europa.eu/api/hub/search' | |
await fs.promises.mkdir('data', { recursive: true }) | |
const catalogues: string[] = await got.get(`${API_BASE}/catalogues`).json() | |
for (const catalogue of catalogues) { |
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
/** | |
* download the ccmap file (updated every time the data updates): | |
* | |
* curl -OL https://data.geocode.earth/wof/dist/meta/whosonfirst-data-admin.ccmap.gz | |
* | |
* | |
* convert ccmap file to typescript (save stdout to `whosonfirst-data-admin.ccmap.ts`): | |
* | |
* import fs from 'node:fs' | |
* const data = fs.readFileSync('whosonfirst-data-admin.ccmap.gz', 'base64') |
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
/** Computes the IEEE 754 floating-point remainder of x / y. */ | |
export const remainder = (x: number, y: number): number => { | |
if (isNaN(x) || isNaN(y) || !isFinite(x) || y === 0) return NaN | |
const quotient = x / y | |
let n = Math.round(quotient) | |
// When quotient is exactly halfway between two integers, round to the nearest even integer | |
if (Math.abs(quotient - n) === 0.5) n = 2 * Math.round(quotient / 2) |
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
/** Returns a random hex string of length chars. */ | |
const randomHexString = (length: number): string => { | |
return Array.from({ length }, () => Math.round(Math.random() * 0xf).toString(16)).join('') | |
} | |
/** Returns a random BigInt of n bits in length. */ | |
export const randomBigIntN = (n: number): bigint => { | |
return BigInt.asUintN(n, BigInt(`0x${randomHexString(Math.ceil(n / 4))}`)) | |
} |
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
// decorator | |
function replacerWithPath (fn) { | |
let paths = new Map() | |
return function (key, value) { | |
let path = paths.get(this) || '$' | |
if (key) path += Array.isArray(this) ? `[${key}]` : `.${key}` | |
let v = fn(key, value, path) | |
if (v === Object(v)) paths.set(v, path) | |
return v | |
} |
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
const geojson = { | |
'id': -99, | |
'type': -6, | |
'properties': -5, | |
'geometry': -4, | |
'coordinates': -3, | |
'bbox': -2 | |
} | |
// GeoJSON Feature/Geometry |
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
// copy->paste into the browser console and wait | |
// note: sorted with the highest points last | |
const csv = (text) => | |
text | |
.trim() | |
.split('\n') | |
.map((r) => { | |
const c = r.split(',').map((c) => c.trim()) | |
return { |
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
package spatial | |
import ( | |
"fmt" | |
"strconv" | |
"github.com/golang/geo/s2" | |
"github.com/peterstace/simplefeatures/geom" | |
) |
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
sudo tcpdump -X -v 'udp[8:4] = 0x03050b11' |
NewerOlder