Skip to content

Instantly share code, notes, and snippets.

View francbartoli's full-sized avatar

Francesco Bartoli francbartoli

View GitHub Profile
@francbartoli
francbartoli / test_geography.py
Created November 10, 2024 16:46 — forked from thruflo/test_geography.py
Example using PostGIS Geography Type with GeoAlchemy.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import code
import logging
from datetime import datetime
from sqlalchemy import create_engine, event
from sqlalchemy import Column, Float, Integer, MetaData, UnicodeText

I had a large dataset in postgis and wanted to avoid the hassle of first exporting it to a several GB geojson file before tiling it with Tippecanoe.

ogr2ogr -f GeoJSON /dev/stdout \                                                                            
PG:"host=localhost dbname=postgres user=postgres password=thepassword" \
-sql "select * from a, roi where a.geom && roi.geom" \
| docker run -i -v ${PWD}:/data tippecanoe:latest tippecanoe \
--output=/data/yourtiles.mbtiles
@francbartoli
francbartoli / Dockerfile
Created November 19, 2019 22:00
A multi-stage Dockerfile to build an image for a minimal python pipenv-managed app
FROM python:3.7 as build
# The python:3.7 image is HUGE but already comes with all the essentials
# for compiling (most) python modules with native dependencies
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
RUN pip install pipenv
WORKDIR /build
COPY Pipfile Pipfile.lock /build/

GeoNode 2.4 -> 2.10.1 migration

PostgreSQL

Create a role and a database for Django:

create role user with superuser login with password '***';
create database gn_24 with owner user;
\c gn_24
@francbartoli
francbartoli / timescale--db--backend--base.py
Created August 9, 2019 09:58 — forked from dedsm/timescale--db--backend--base.py
WeRiot Django Timescale integration
import logging
from django.contrib.gis.db.backends.postgis.base import \
DatabaseWrapper as PostgisDBWrapper
from django.db import ProgrammingError
from .schema import TimescaleSchemaEditor
logger = logging.getLogger(__name__)
@francbartoli
francbartoli / diff_strings.py
Created August 1, 2019 14:20 — forked from ines/diff_strings.py
Print colored visual diff in Python
import difflib
import wasabi
def diff_strings(a, b):
output = []
matcher = difflib.SequenceMatcher(None, a, b)
for opcode, a0, a1, b0, b1 in matcher.get_opcodes():
if opcode == "equal":
output.append(a[a0:a1])
elif opcode == "insert":
from typing import Optional
import base64
from passlib.context import CryptContext
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from pydantic import BaseModel
from fastapi import Security, Depends, FastAPI, HTTPException
from fastapi.security.api_key import APIKeyQuery, APIKeyCookie, APIKeyHeader, APIKey
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.openapi.utils import get_openapi
from starlette.status import HTTP_403_FORBIDDEN
from starlette.responses import RedirectResponse, JSONResponse
API_KEY = "1234567asdfgh"
API_KEY_NAME = "access_token"
from typing import Optional
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from fastapi import Depends, FastAPI, HTTPException
from fastapi.encoders import jsonable_encoder
from fastapi.security.oauth2 import (
OAuth2,
from typing import Optional
import base64
from passlib.context import CryptContext
from datetime import datetime, timedelta
import jwt
from jwt import PyJWTError
from pydantic import BaseModel