Skip to content

Instantly share code, notes, and snippets.

@gpprojekt-marcin
gpprojekt-marcin / wg_genkeys.sh
Created March 9, 2021 08:57
Generate WireGuard keys
#! /usr/bin/env bash
umask go=
wg genkey | tee wg_${1}.key | wg pubkey > wg_${1}.pub
wg genpsk > wg_${1}.psk
@gpprojekt-marcin
gpprojekt-marcin / flask_mvt.py
Created January 5, 2021 11:03 — forked from giohappy/flask_mvt.py
OL + Flask + PostGIS for MVT rendering
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import shutil
import math
import psycopg2
from flask import Flask, render_template, make_response
app = Flask(__name__)
@gpprojekt-marcin
gpprojekt-marcin / extents.py
Created September 25, 2020 08:36
PyQGIS get Layout maps extents
project = QgsProject.instance()
manager = project.layoutManager()
layoutName = 'KIERUNKI'
layoutMain = [layout for layout in manager.printLayouts() if layout.name() == layoutName][0]
maps = [item for item in layoutMain.items() if hasattr(item, 'extent')]
[m.extent() for m in maps]
<?xml version="1.0" encoding="utf-8"?>
<gml:FeatureCollection xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:gco="http://www.isotc211.org/2005/gco"
xmlns:gmd="http://www.isotc211.org/2005/gmd"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:gsr="http://www.isotc211.org/2005/gsr"
xmlns:gss="http://www.isotc211.org/2005/gss"
xmlns:gts="http://www.isotc211.org/2005/gts"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:bt="urn:gugik:specyfikacje:gmlas:modelPodstawowy:1.0" xmlns:mz="urn:gugik:specyfikacje:gmlas:mapaZasadnicza:1.0" targetNamespace="urn:gugik:specyfikacje:gmlas:modelPodstawowy:1.0" elementFormDefault="qualified" attributeFormDefault="unqualified">
<import namespace="http://www.opengis.net/gml/3.2" schemaLocation="http://schemas.opengis.net/gml/3.2.1/gml.xsd"/>
<import namespace="http://www.isotc211.org/2005/gmd" schemaLocation="http://schemas.opengis.net/iso/19139/20070417/gmd/gmd.xsd"/>
<import namespace="http://www.isotc211.org/2005/gmd" schemaLocation="http://schemas.opengis.net/iso/19139/20070417/gmd/citation.xsd"/>
<import namespace="urn:gugik:specyfikacje:gmlas:mapaZasadnicza:1.0" schemaLocation="MZ_MapaZasadnicza.xsd"/>
<!--======================================-->
<element name="BT_ObiektPrzestrzenny" type="bt:BT_Obie
@gpprojekt-marcin
gpprojekt-marcin / notCoveringLines.sql
Last active March 13, 2020 14:30
Linie rozgraniczające nieprzebiegające po granicach działek
SELECT row_number() OVER () rn, *
FROM (
SELECT (ST_Dump(ST_Difference(ST_Snap(luse, lparcels, tolerance), lparcels))).*
FROM (
SELECT
ST_Union(DISTINCT land_use_only.geom) AS luse,
ST_Union(DISTINCT land_parcels_only.geom) AS lparcels,
1e-5 AS tolerance
FROM (
SELECT
@gpprojekt-marcin
gpprojekt-marcin / unBlendColor.js
Created February 26, 2020 08:40
Color unBlender/unMixer
function unblendColorChanel(value, opacity){
return Math.round((value - 255*(1-opacity))/opacity)
}
export function unblendColor(rgbA, opacity){
return rgbA.map(ch=> unblendColorChanel(ch, opacity))
}
@gpprojekt-marcin
gpprojekt-marcin / map_extends.py
Last active February 20, 2020 12:39
PyQGIS Composer Map Extends in layer
from qgis.core import *
from PyQt5.QtCore import QVariant
project = QgsProject.instance()
projectLayoutManager = project.layoutManager()
layout = projectLayoutManager.layoutByName('KIERUNKI_A0+')
treeRoot = project.layerTreeRoot()
temp = QgsVectorLayer("Polygon?crs=epsg:2180", "map_extends", "memory")
temp_data = temp.dataProvider()
@gpprojekt-marcin
gpprojekt-marcin / arcpy_sync.py
Created November 18, 2019 20:19
Sync project extents with base
arcpy.env.workspace = "."
current_mxd = arcpy.mapping.MapDocument("CURRENT")
current_dfs = arcpy.mapping.ListDataFrames(current_mxd)
project_filename = current_mxd.filePath.split('\\')[-1]
project_name = project_filename[:-4].split('_')[0]
project_scale = project_filename[:-4].split('_')[-1]
plan_filename = "{}_RysunekPlanu_{}.mxd".format(project_name, project_scale)
plan_mxd = arcpy.mapping.MapDocument(plan_filename)
source_dfs = arcpy.mapping.ListDataFrames(plan_mxd)
for index in range(len(source_dfs)):
@gpprojekt-marcin
gpprojekt-marcin / acrPy_labelBreak.py
Created September 20, 2019 14:18
Python break string in the middle space
def FindLabel ( [NAZWA_OBIEKTU] ):
label = [NAZWA_OBIEKTU]
if (label.count('-') != 0):
return '\n'.join([e.strip() for e in label.split('-')])
lens=[n for n in range(len(label)) if label.find(' ', n) == n]
abss = [abs(round(len(label)/2)-e) for e in lens]
i=lens[abss.index(min(abss))]
return '\n'.join([label[:i].strip(),label[i:].strip()])