Skip to content

Instantly share code, notes, and snippets.

View paulovieira's full-sized avatar

Paulo Vieira paulovieira

  • 2adapt
  • Lisbon, Portugal
View GitHub Profile
@paulovieira
paulovieira / ogrIntoPostGIS.md
Created March 14, 2023 13:59 — forked from maptastik/ogrIntoPostGIS.md
Import data into PostGIS with ogr2ogr#

Generally I can use QGIS and its DBManager to import data into a PostGIS database. Sometimes that doesn't work perfectly. ogr2ogr can help though. Here are a few approaches to getting data into PostGIS with ogr2ogr.

This is probably the most basic approach:

 ogr2ogr -f "PostgreSQL" PG:"dbname=<db name> user=<username> password=<password> host=<host> port=<port #>" input.geojson -nln schema.table

Running this little command seems to work if you have need to specify the geometry type (Source):

@paulovieira
paulovieira / slugify.sql
Last active February 9, 2023 17:04 — forked from kez/slugify.sql
Generating Slugs in Postgres
CREATE EXTENSION IF NOT EXISTS "unaccent"
CREATE OR REPLACE FUNCTION slugify("value" TEXT)
RETURNS TEXT AS $$
-- removes accents (diacritic signs) from a given string --
WITH "unaccented" AS (
SELECT unaccent("value") AS "value"
),
-- lowercases the string
"lowercase" AS (
@paulovieira
paulovieira / dropbox
Last active January 14, 2016 12:15 — forked from lmammino/dropbox
Run dropbox CLI as service
#/etc/init.d/dropbox
start() {
echo "Starting dropbox..."
start-stop-daemon -b -o -c dropbox -S -x /home/dropbox/.dropbox-dist/dropboxd
}
stop() {
echo "Stopping dropbox..."
start-stop-daemon -o -c dropbox -K -x /home/dropbox/.dropbox-dist/dropboxd
CREATE OR REPLACE FUNCTION public.json_append(data JSON, insert_data JSON)
RETURNS JSON
LANGUAGE SQL
AS $$
SELECT
('{' || string_agg(to_json(key) || ':' || value, ',') || '}') :: JSON
FROM (
SELECT
*
FROM json_each(data)