Skip to content

Instantly share code, notes, and snippets.

View Jeremiah-England's full-sized avatar

Jeremiah England Jeremiah-England

View GitHub Profile
@Jeremiah-England
Jeremiah-England / us_census_tracts.py
Last active July 31, 2022 00:34
Download a shapefile will all the US Census Tracts.
import geopandas as gpd
import os
import requests
import shutil
# downloading all the ANSI codes for all the states and DC, skipping the territories
states_list = requests.get('https://www2.census.gov/geo/docs/reference/state.txt').text.split('\n')[1:52]
# states_list should =
'''
@Jeremiah-England
Jeremiah-England / qgis-algorithm-names.txt
Last active April 24, 2020 12:26
The following printout contains all the algorithm names for QGIS 3.10.5. The code to generate the printout can be found here: https://docs.qgis.org/3.10/en/docs/user_manual/processing/console.html#calling-algorithms-from-the-python-console
3d:tessellate -> Tessellate
gdal:aspect -> Aspect
gdal:assignprojection -> Assign projection
gdal:buffervectors -> Buffer vectors
gdal:buildvirtualraster -> Build virtual raster
gdal:cliprasterbyextent -> Clip raster by extent
gdal:cliprasterbymasklayer -> Clip raster by mask layer
gdal:clipvectorbyextent -> Clip vector by extent
gdal:clipvectorbypolygon -> Clip vector by mask layer
gdal:colorrelief -> Color relief
@Jeremiah-England
Jeremiah-England / pag-timer.py
Created May 21, 2020 00:22
Time points along geometry in QGIS
from shapely.geometry import mapping, LineString
from qgis import processing
import timeit
import fiona
SHAPEFILE_DIRECTORY = 'path/to/shapefiles'
# create some linestrings to test on
scheme = {'geometry': 'LineString', 'properties': []}
@Jeremiah-England
Jeremiah-England / delete_dups.py
Last active January 10, 2024 16:07
Delete large numbers of duplicate files from Duplicate Files Finder output
"""
A script for deleting large numbers of duplicates from the output .txt file of
the open source Duplciate Files Finder application (https://sourceforge.net/projects/doubles/).
Given a list of duplicate files, the one with the shortest path (by character count)
is kept and all the rest are deleted. If several have the same length and there are
none shorter, then the least "alphabetically" is kept.
I used this to reduce a heavily duplicated picture archive from 121Gb to 57Gb. There
wasn't really a best way to decide which to delete so the "least path" logic above was
@Jeremiah-England
Jeremiah-England / README.md
Created November 21, 2020 22:46
Syncing Getting Things Gnome with Git

Syncing Getting Things Gnome with Git

The Getting Things Gnome application is what I'm currently using for David Allen's Getting Things Done self-management method. The application was stagnant for a few years but has recently been revived. The new team has not had the time to catch up the old plugins that synced different computers using Remember The Milk (there may have been others as well?)

@Jeremiah-England
Jeremiah-England / silly_wkt.py
Last active December 12, 2020 00:33
Silly WKT parser for Polygons and Multipolygons
"""
Just a silly little wkt parser I wrote because for a minute there
I thought invalid shapely MultiPolygons were missing the
`difference` method if loaded via the `shapely.wkt` module. Turns
out it was just a spelling error. :D
Not made to be easy to read, sorry. But I thought it was cool so
I made a gist out of it.
"""
from shapely.geometry import Polygon, MultiPolygon
@Jeremiah-England
Jeremiah-England / fast_buffer.md
Last active February 16, 2024 19:48
Fast Buffer for Shapely Point

It's common to use the [shapely.stretree.STRtree.query] to find what's near a point. Often the point is buffered to get whatever is roughly within a radius of the point. For example,

dist = 123.456
geoms_near_point = tree.query(pt.buffer(dist))

What's really being returned here are any geometries in the tree whose bounding boxes intersect with the point's bounding box. By default, pt.buffer(dist) returns a buffer

@Jeremiah-England
Jeremiah-England / directional_distance.py
Last active January 3, 2021 04:32
Directional Distance with Shapely
"""A small module for finding the distance between two geometries in an arbitrary direction
Inspired by a question/issue in the Shapely github repository (`#1051`_).
Notes
-----
There is another way I can think of doing this which will probably be much faster for
large geometries, but less accurate. It should be possible to stretch both geometries
by a very large amount in the direction perpendicular to the direction you want to
find the distance in. Of course, you would loose the 'movement' idea (i.e. it could
@Jeremiah-England
Jeremiah-England / without_wikidata.sh
Created December 23, 2020 11:04
A list of spiders in alltheplaces without wikidata
# A list of spiders in alltheplacs that do not have wikidata added to them
# There are 548/690 which do not.
# Repository link: https://github.com/alltheplaces/alltheplaces
grep -rL 'brand_wikidata' locations/spiders/
: '
locations/spiders/lane_bryant.py
locations/spiders/chilis.py
locations/spiders/half_price_books.py
locations/spiders/trader_joes.py
@Jeremiah-England
Jeremiah-England / christmas_music_timer.py
Created December 27, 2020 12:55
Start playing a song randomly between two times
"""
A short script to start a song at a random time on Christmas morning.
Usage
-----
You will need a way to keep your computer from falling asleep. I
used the Caffiene program which I believe is crossplatform. If your
computer does fall asleep, run out of batteries, get stolen by
Santa, etc; the music will not play in the morning.