Skip to content

Instantly share code, notes, and snippets.

View kgjenkins's full-sized avatar

Keith Jenkins kgjenkins

View GitHub Profile
@kgjenkins
kgjenkins / index.md
Created October 21, 2024 21:05
Different methods to calculate polygon neighbors in QGIS

Different methods to calculate polygon neighbors in QGIS

kgjenkins, 2020-11-10

Before using any of the methods below, make sure that your polygon layer has a spatial index.
Reported timings are based on test data of 1606 counties in the eastern US.

Method 1: Virtual Layers SQL query

select
 a.GEOID,
@kgjenkins
kgjenkins / index.md
Created October 21, 2024 20:23
Merge state-based PUMA files and calculate adjacent polygons

Merge state-based PUMA files and calculate adjacent polygons

kgjenkins, 2020-06-26

Download PUMA boundaries

The US Census has PUMA boundary shapefiles available by state. Here's the directory of all the 2010 PUMAs, 2019 vintage: https://www2.census.gov/geo/tiger/TIGER2019/PUMA/

Download manually one at a time, or automate using wget:

@kgjenkins
kgjenkins / test.py
Created October 21, 2024 20:08
intersect point shapefile with directory of tif files
# this script goes through a directory of tif files and a shapefile of cities
# and reports which city points are contained within each tif
# 2024-04-17 kgjenkins
import os
import fiona
import rasterio
import shapely
from pyproj import Transformer
@kgjenkins
kgjenkins / hash.py
Created May 3, 2024 17:45
generate hashes for a csv of filepaths
# this script goes through a list of files from Excel "data from folder"
# and computes a hash of the file contents (to be used for deduplication)
import csv
import os
import hashlib
import time
# columns: Name,Extension,Date accessed,Date modified,Date created,Folder Path,Hash
@kgjenkins
kgjenkins / README.md
Created April 19, 2024 16:45
variation across multiple scans

The same image (an illustrated book cover) was scanned on the flatbed scanner (EPSON WF-2630) three times at 300dpi.

Analysis of the variation across the three scans:

band min max mean std dev
red 0 36 4.47 2.59
green 0 36 4.41 2.68
blue 0 37 4.72 2.95
@kgjenkins
kgjenkins / index.py
Created April 17, 2024 20:45
Calculate which city points are within each tif in a directory
# this script goes through a directory of tif files and a shapefile of cities
# and reports which city points are contained within each tif
import os
import fiona
import rasterio
import shapely
from pyproj import Transformer
tifpath = "path/to/tiffs"
@kgjenkins
kgjenkins / gist:ad26a278ecbf745873b8504dd7e217b3
Last active March 1, 2024 21:02
Calculating a raster of the network distance to the nearest park
The limiting factor in terms of the speed of the Iso-areas tool seems
to be the number of starting points. I've tried a number of
variations, trying to reduce the number of points while retaining
enough points that the analysis is still accurate. After several
failed attempts, I think I've come up with a workflow that ends up
keeping just the points along the park perimeters that end up being
the closest points to the road network. Here's the general workflow,
assuming we are starting with 2 layers, "streets" and "parks". I'd
suggest creating temporary outputs for each of these steps, and then
make the final result permanent.
@kgjenkins
kgjenkins / README.md
Last active September 12, 2023 20:45
Reclassifying UrbanWatch rasters using QGIS and Rasterio

Reclassifying UrbanWatch rasters using QGIS and Rasterio

See the video demo at https://youtu.be/t-pb5-1Q_Qg

The files here were used to convert UrbanWatch from RGB images to numeric rasters with simple landcover values 0-9, as follows:

Value Category Color
0 No Data Black
1 Building Red
@kgjenkins
kgjenkins / README.md
Last active September 12, 2023 20:32
Reclassifying UrbanWatch rasters using ArcGIS

Reclassifying UrbanWatch rasters using ArcGIS

See the video demo at https://youtu.be/mdYnBFYqXpg

The files here can be used to convert UrbanWatch rasters from RGB images to numeric rasters with simple landcover values 0-9, as follows:

Value Category Color
0 No Data Black
1 Building Red
@kgjenkins
kgjenkins / README.md
Last active October 12, 2022 14:24
LA 3010 GIS data sources