Skip to content

Instantly share code, notes, and snippets.

View GastonZalba's full-sized avatar

Gastón Zalba GastonZalba

View GitHub Profile
@GastonZalba
GastonZalba / parse_decimal_lat_lon_coords.js
Created September 1, 2020 23:16
Convert decimal degree coordinate string formats to a clean array.
/**
* Latitude and longitude decimal values are bounded by ±90° and ±180° respectively.
* This will match only that bound, accepting common uses of commas, points, spaces,
* tabs and degree symbols, returning a clean, standardized latitude and longitude array.
* @returns [{number}, {number}] Latitude and longitude
*/
const parseDecimalLatLon = string => {
let isDecimal = /^([-+]?(?:[1-8]?\d(?:(?:.|,){1}\d+)?|90(?:\.0+)?))°?(?:,|;|\t| )+([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:(?:\.|\,){1}\d+)?))°?$/
let match = string.match(isDecimal);
@GastonZalba
GastonZalba / GoogleAppsScripts.js
Last active August 26, 2020 21:12
Transform comma separated strings cell values to PostgresSQL arrays
const SHEET_NAME = '+para_DB';
const TARGET_COLUMN_NAME = 'categoria';
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName( SHEET_NAME );
const data = sheet.getDataRange().getValues();
let column = data[0].indexOf(TARGET_COLUMN_NAME);
// Transform comma separated strings cell values to PostgresSQL arrays
function transformDataToArray() {
@GastonZalba
GastonZalba / PostGis_to_Geojson.sql
Last active August 13, 2020 16:52
Create a geojson from mutiples tables in PostrgreSQL and PostGIS
SELECT json_build_object(
'type', 'FeatureCollection',
'crs', json_build_object(
'type', 'name',
'properties', json_build_object(
'name', 'EPSG:4326'
)
),
'features', json_agg(ST_AsGeoJSON(t.*)::json)
)