Skip to content

Instantly share code, notes, and snippets.

View mhugo's full-sized avatar

Hugo Mercier mhugo

View GitHub Profile
#!/usr/bin/env python
# This set of classes demonstrate how to implement a defered renderer with QT
#
# The idea is to be source compatible with existing QPainter operations (drawXXX, setBrush, etc.)
# and add extra commands that allow to "insert back" operations in the pipeline before they are actually rendered.
#
# This is a possible component for the "symbol clipping" feature of QGIS
#
# This prototype implements a custom QPaintDevice / QPaintEngine that will
#!/usr/bin/env python
# This set of classes demonstrate how to implement a defered renderer with QT
#
# The idea is to be source compatible with existing QPainter operations (drawXXX, setBrush, etc.)
# and add extra commands that allow to "insert back" operations in the pipeline before they are actually rendered.
#
# This is a possible component for the "symbol clipping" feature of QGIS
#
# The rendering is split into "rendering layers" that correspond to "symbol layers" of QGIS.

Keybase proof

I hereby claim:

  • I am mhugo on github.
  • I am mhugo (https://keybase.io/mhugo) on keybase.
  • I have a public key ASAd4IAWv0qHrPFtkviC3nYwCb0YVIw_ml06fbAFIRzSQQo

To claim this, I am signing this object:

import struct
from fractions import Fraction
import psycopg2
def double_to_hex(f):
h = hex(struct.unpack('<Q', struct.pack('<d', f))[0])[2:]
# reverse each byte for endianness
return h[6:]+h[4:6]+h[2:4]+h[0:2]
def poly_wkb(x,y):
@mhugo
mhugo / test_qtcharts.py
Created March 14, 2019 15:16
QtCharts test
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsExpression
from PyQt5.QtCore import QPointF, QVariant, Qt
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QPushButton
from PyQt5.QtChart import QLineSeries, QChart, QChartView, QDateTimeAxis, QValueAxis
import numpy as np
def series_to_polyline(xdata, ydata):
@mhugo
mhugo / run-qgis-test-locally.sh
Created December 4, 2019 07:05
Run QGIS test locally
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [ -z "$1" ]
then
echo "Argument: string to pass to ctest -R"
exit 1
fi
if [ "$2" = "gdb" ]; then
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'ods.core.settings')
django.setup()
from _pytest.monkeypatch import MonkeyPatch
from django.test import RequestFactory
from django.core.handlers.base import BaseHandler
from ods.core.utils import platform_utils
@mhugo
mhugo / subordereddict.py
Created February 7, 2022 08:42
Ordered dict with predicate filtering
from collections import OrderedDict
from enum import Enum
from typing import Any, Callable, Dict, Optional
class SubOrderedDict(dict):
def __init__(self, original_dict: OrderedDict, predicate: Optional[Callable[[Any], bool]] = None):
self._dict = original_dict
import json
import requests
ES = "http://localhost:9200"
INDEX = "test_shard_doc"
class ESClient:
def __init__(self, host: str, index_name: str):
self._host = host
# 58 shapes
# curl "https://public.opendatasoft.com/api/explore/v2.0/catalog/datasets/georef-france-commune-millesime/exports/geojson?select=geo_shape&where=arrdep_code=561&refine=year:2021" -o arrdep561.geojson
# 250 shapes
# curl "https://public.opendatasoft.com/api/explore/v2.0/catalog/datasets/georef-france-commune-millesime/exports/geojson?select=geo_shape&where=dep_code=56&refine=year:2021" -o dep56.geojson
# 1208 shapes
# curl "https://public.opendatasoft.com/api/explore/v2.0/catalog/datasets/georef-france-commune-millesime/exports/geojson?select=geo_shape&where=reg_code=53&refine=year:2021" -o reg53.geojson
# 34978 shapes - warning too large for a unique http index call
# curl "https://public.opendatasoft.com/api/explore/v2.0/catalog/datasets/georef-france-commune-millesime/exports/geojson?select=geo_shape&refine=year:2021" -o fr.geojson
INPUTFILE=$1