Skip to content

Instantly share code, notes, and snippets.

View ka7eh's full-sized avatar

Kaveh Karimi-Asli ka7eh

View GitHub Profile
@ka7eh
ka7eh / leaflet_to_pdf.html
Created April 12, 2016 16:55
An example for converting Leaflet maps to PDF using leaflet-image and jsPDF
<html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css"/>
<style>
#mapid{
height: 480px;
}
#download {
position:absolute;
@ka7eh
ka7eh / 01_tilemaker.py
Last active August 1, 2016 18:45
A simple tile maker, using mapnik and mercantile
"""
requires:
- mapnik 3.x and its python bindings (https://github.com/mapnik/mapnik)
- mercantile==0.9.0 (https://github.com/mapbox/mercantile)
"""
import os
import mapnik
import mercantile
@ka7eh
ka7eh / loadDependencies.js
Created November 19, 2016 22:37
Dynamic loading of js and css dependencies in DOM
function loadDependencies(deps, callback) {
var dep = deps.shift();
if (dep['script'] && typeof(window[dep['lib']]) != dep['loadType'] || 'function') {
var depScript = document.createElement('script');
depScript.type = 'text/javascript';
depScript.src = dep['script'];
(document.getElementsByTagName('head')[0]).appendChild(depScript);
}
@ka7eh
ka7eh / getStyle.js
Created December 7, 2016 23:57
Returns all styling rules of the passed doc as a string
function getStyles(doc) {
/** idea from https://github.com/NYTimes/svg-crowbar **/
var styles = '',
styleSheets = doc.styleSheets;
if (styleSheets) {
for (var i = 0; i < styleSheets.length; i++) {
processStyleSheet(styleSheets[i]);
}
}
@ka7eh
ka7eh / cssInliner.js
Created December 8, 2016 00:00
Convert styling rules of an element into inline styling
function cssInliner(el) {
var cssProperties = getComputedStyle(el, null);
var cssText = '';
for (var i = 0; i < cssProperties.length; i++) {
cssText += cssProperties[i] + ':' + cssProperties.getPropertyValue(cssProperties[i]) + ';'
}
el.style.cssText = cssText;
for (var j = 0; j < el.childElementCount; j++) {
@ka7eh
ka7eh / geom_factory.py
Created June 2, 2017 00:04
A factory for creating random polygons in a given extent
# requires pyproj and shapely
import collections
import functools
import math
import random
import pyproj
from shapely.geometry import box, point, polygon
from shapely.ops import transform
@ka7eh
ka7eh / st_createfishnet.sql
Created June 12, 2017 23:22
Creates a grid of `xsize*ysize` cells in a given extent
CREATE OR REPLACE FUNCTION ST_CreateFishNet(
IN xsize double precision,
IN ysize double precision,
IN north double precision DEFAULT 0,
IN east double precision DEFAULT 0,
IN south double precision DEFAULT 1,
IN west double precision DEFAULT 1)
RETURNS SETOF geometry AS
$BODY$
SELECT ST_Translate(cell, $6 + (i * $1), $5 + (j * $2)) AS geom
@ka7eh
ka7eh / qgis_model.py
Created June 15, 2017 22:01
An example of how to load and run multiple QGIS algorithms outside of QGIS GUI
import os
import sys
from qgis.core import *
from PyQt4.QtGui import *
home = os.path.expanduser('~')
sys.path.extend([
'/usr/share/qgis/python/plugins/processing',
CREATE OR REPLACE FUNCTION ST_GridFromBbox(
IN x0 double precision,
IN y0 double precision,
IN x1 double precision,
IN y1 double precision,
IN xsize double precision,
IN ysize double precision,
OUT "row" integer,
OUT col integer,
OUT geom geometry)
@ka7eh
ka7eh / psycopg2.md
Last active November 18, 2020 21:15
Python packages install hints

psycopg2:

LDFLAGS="-I<path-to-openssl>/include -L<path-to-openssl>/lib" pip install psycopg2