Skip to content

Instantly share code, notes, and snippets.

View AsgerPetersen's full-sized avatar

Asger Skovbo Petersen AsgerPetersen

  • Copenhagen, Denmark
View GitHub Profile
@AsgerPetersen
AsgerPetersen / notes.md
Last active February 16, 2024 04:20
Debugging QGIS 3.x python plugins on OSX using VS Code

Debugging QGIS 3.x python plugins on OSX using VS Code

Plugin

In QGIS install the plugin debugvs.

Python dependencies

The debugvs plugin needs the python module ptvsd to function. This module is not installed by default.

In principle you just pip install ptvsd in the python interpreter used by QGIS.

@AsgerPetersen
AsgerPetersen / create_voronoi_function.sql
Last active November 17, 2021 15:41
Fast(er) voronoi polygons in PostGIS
-- plpython needs to be enabled. Furthermore scipy needs to be installed in the python used.
-- CREATE LANGUAGE plpythonu;
CREATE OR REPLACE FUNCTION septima.voronoi(geom geometry, boundingpointdistance double precision)
RETURNS SETOF geometry_dump AS
$BODY$
from scipy.spatial import Voronoi
import numpy
class GeoVoronoi:
@AsgerPetersen
AsgerPetersen / Debugging QGIS on OSX using VSCode and conda.md
Last active November 5, 2021 12:38
Debugging QGIS python plugins on OSX using VSCode

Debugging QGIS python plugins using VSCode on OSX

This is how I debug QGIS using VSCode on OSX. Previously I used this approach. But since then ptvsd was deprecated and I also needed to install python modules backed by native C code. This is much easier to do in a conda based environment (actually, I didn't find a way to make it work with the official QGIS installer :-)).

Get QGIS running in a conda env

Follow this description to get QGIS running in conda.

Install debugpy

ptvsd is superseded by debugpy.

Acti

@AsgerPetersen
AsgerPetersen / QGIS on OSX with Conda.md
Last active November 5, 2021 11:54
QGIS using conda on OSX
@AsgerPetersen
AsgerPetersen / README.md
Last active October 19, 2020 13:15
Test rasterstats with or without boundless reading
@AsgerPetersen
AsgerPetersen / readme.md
Last active June 23, 2020 14:44
PyCharm remote debug of QGIS on OSX

Based heavily on this old guide by TimLinux http://linfiniti.com/2012/09/remote-debugging-qgis-plugins-using-pycharm/

  • In PyCharm click menu "Run -> Edit Configurations" (Or click Edit Configurations in the dropdown in the toolbar)
  • Click the plus to add a new "Python Remote Debug" config
  • Name the config. Use port 53100 (Could probably be any high port)
  • Add to the python code:
import sys
sys.path.append('/Applications/PyCharm.app/Contents/debug-eggs/pycharm-debug.egg')
@AsgerPetersen
AsgerPetersen / pyramid_size.py
Created November 13, 2017 08:23
Size of tile pyramid
from math import log, ceil, sqrt
# Gennemsnitlig stoerrelse af en tile. 25kB passer nogenlunde med ortofoto
size_per_tile = 25 * 1024 # 25kB
# --------GSTs standard skema ---------------
# Koordinater paa tilet omraade (xmin, ymin, xmax, ymax)
#bbox = [120000, 5900000, 1000000, 6500000]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""
Zonal Statistics
Vector-Raster Analysis
Copyright 2013 Matthew Perry
Changes by AsgerPetersen:
- Use band nodata value if user does not override it
- Allow calculating statistics for all geometry types
- Allow buffer to be applied before calculation
@AsgerPetersen
AsgerPetersen / !wedge_buffers.md
Last active February 4, 2016 13:31
Wedge buffers in python

Wedge buffers in python

Copyright (c) 2016, Asger Sigurd Skovbo Petersen

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF