Skip to content

Instantly share code, notes, and snippets.

View nick4rivers's full-sized avatar

Nick Weber nick4rivers

View GitHub Profile

QGIS Calculation Snippets

Little bits and pieces to remember when writing QGIS calculations

Sample From Raster

Grab a value from a raster. Usualy this will be at at apoint. HINT: this uses the raster_value function in the QGIS expression builder. The function just takes the name of the raster layer, the band, and a point geometry.

raster_value("raster layer name", 1, $geometry)
@nick4rivers
nick4rivers / flask_app.md
Last active November 30, 2021 04:48
Flask App Notes

Flask Web Framework Notes

Simple notes useful in building flask web applications

Environmental Local Variables

These should be set in the terminal to allow a development server

  export FLASK_ENV=development
  export FLASK_APP=[index_file_name.py]
@nick4rivers
nick4rivers / pyqgis-geopackage-creation.py
Created October 21, 2021 18:43
Creating geopackages and tables in pyQGIS
# how to create geopackages in pyQGIS
# describes creating a parent and child table
import os
from qgis.PyQt.QtCore import QVariant
from qgis.core import (
QgsField,
QgsVectorLayer,
QgsVectorFileWriter
@nick4rivers
nick4rivers / pyqgis-duplicate-layer.py
Last active October 21, 2021 16:53
PyQGIS duplicate a layer, set a filter, and set a layer variable
# how to duplicate or clone a map layer
# renaming the map layer and setting a filter
# and also setting a variable on a layer for use in scripts
# also shows how to connnect a .qml to a map layer
# Select a layer that is already added to the interface
layer_original = QgsProject.instance().mapLayersByName('original')[0]
# duplicate or clone the layer
layer_cloned = layer_original.clone()
@nick4rivers
nick4rivers / QGIS-Aggreagates.md
Last active August 30, 2021 20:27
QGIS Aggregate Expressions

QGIS Aggregate Expressions

  • These are super useful expressions for initiating spatial lookups and calcuating aggregate values.
  • For example, could be used to look up the parent id of a child record based on their spatial relationship.
  • Could also be used to calculate the average structure length for each parent complex.
  • good example of using this code can be found in this YouTube Video.

Gets the parent complex for each structure if the complex contains the centroid.

aggregate(
@nick4rivers
nick4rivers / windows-device.md
Last active August 16, 2021 16:34
Windows Mobile on Windows 10

Windows Mobile Device Center

  • This is a short Gist on using windows mobile device center on newer Windows operating systems such as windows 10.
  • Windows mobile devide center no longer ships with modern version of Windows
  • For example - connection to a Nikon total station and downloading the survey files.

Required Drivers and Download

@nick4rivers
nick4rivers / nicks-postgres-notes.md
Last active July 30, 2021 16:53
Notes on postgres and post GIS databases

POSTGRES and POST GIS Database Notes

These are basic notes, primarily relevant to accessing postgres and post gis databases. Primarily these will be in the commend line on mac os

Open the postgres prompt

Open a local database in the terminal. In this case, the -U is for username which in this case the user is postgres

psql -U postgres -d [database name] 
@nick4rivers
nick4rivers / Qt-Plugin-Notes.md
Last active April 20, 2022 20:58
My notes for Python, Qt, and QGIS plugin development

PYTHON AND QT NOTES FOR QGIS PLUGIN DEVELOPMENT

My notes for Mac OS Qt and QGIS python plugin development tools on VSCode

Qt DEVELOPMENT VIRTUAL ENV:

NEW

python3 -m venv [my_directory]

ACTIVATE

@nick4rivers
nick4rivers / QGIS-plugin-when-run.md
Last active July 16, 2021 18:49
Simple big of python showing when different sections of a plugin run. See the QMessageBox dialogs

QGIS PLUGIN RUN LOCATIONS

Some python showing when different part of the main QGIS Plugin Python code are run. See the QMessageBox locations and descriptions. This is at the bottom of the main .py file


def run(self):
    """Run method that performs all the real work"""

    # Create the dialog with elements (after translation) and keep reference