Skip to content

Instantly share code, notes, and snippets.

View kgjenkins's full-sized avatar

Keith Jenkins kgjenkins

View GitHub Profile
@kgjenkins
kgjenkins / README.md
Last active February 20, 2020 17:30
Splitting MS Buildings into county-based files

Splitting Microsoft Buildings into county-based files

Microsoft US Building Footprints are available at:
https://github.com/Microsoft/USBuildingFootprints

The state-based downloads are in .geojson format, which is a pretty bad choice for datasets this large. Bad because .geojson has no spatial index, making it very slow to load and render. So it will be useful to split and save them into a separate file (geopackage or shapefile) for each county. Also, some of the polygons have invalid geometries that we should fix along the way.

@kgjenkins
kgjenkins / readme.md
Last active February 13, 2020 18:03
QGIS actions for loading raster tiles from an index map
from qgis.utils import iface
active_layer = iface.activeLayer()

tile = QgsRasterLayer('[%downloadUrl%]')
QgsProject.instance().addMapLayer(tile)
r = QgsHillshadeRenderer(tile.dataProvider(), 1, 315, 45)
tile.setRenderer(r)

iface.setActiveLayer(active_layer)
@kgjenkins
kgjenkins / readme.md
Last active June 9, 2022 10:13
QGIS line fill based on polygon angle

image

Use the following expression for the rotation value:

90 - azimuth(
  point_n( $geometry, 1),
  point_n( $geometry, 2)
) / 3.1415927 * 180
@kgjenkins
kgjenkins / readme.md
Created November 18, 2019 22:36
Flow mapping

Resources for flow mapping

flowmap.blue offers a relatively easy way to create flow maps in a web browser. It's also possible to create the maps from data in a google sheet. https://flowmap.blue/in-browser

Tom Chadwin describes how he created pseudo-3d arched flow lines using QGIS https://medium.com/@tomchadwin/mapping-emotion-fighting-school-closures-with-qgis-28842661bf14

"Design principles for origin-destination flow maps", an article by Bernhard Jenny, et al. discusses all the things you'll want to think about for the cartography of a flow map.

@kgjenkins
kgjenkins / readme.md
Last active October 29, 2019 19:36
GeoCorr example

geocorr2014

Download the GeoCorr2014 table via http://mcdc.missouri.edu/applications/geocorr2014.html

  • Select a state.
  • Select the "source" and "target" geographies. (For example, if you have demographic data at the tract level, and want to map it to Voting Tabulation Districts (VTD), set VTD as the source and tract as the target. (Yes, this seems counterintuitive.)
  • Weight by population (2010 census)
  • Generate CSV file. (The report is unnecessary.)

NOTE: Unfortunately, the output doesn't include the full tract FIPS codes, so we'll need to deal with that. Here are some rows showing the geocorr columns we'll be using:

@kgjenkins
kgjenkins / readme.md
Last active July 23, 2019 21:41
Aggregate counts of multi-valued columns

Aggregate counts of multi-valued columns

Let's suppose we have a dataset of research studies conducted in various countries, and some studies are associated with multiple countries. Our studies table might have multiple comma-delimited values in the country column, and there might be spaces after some of those commas, looking something like this:

id title country
1 Study one Mauritania
2 Study two Mali
3 Study three Guinea
4 Study four Mali,Guinea
@kgjenkins
kgjenkins / readme.md
Last active May 3, 2024 12:21
Creating halftones in QGIS

Creating halftones in QGIS

A quick demo using a hexagon grid with a centroid fill of points sized using raster values from the image layer.

qgis-hex-halftones2

@kgjenkins
kgjenkins / readme.md
Last active April 28, 2020 18:45
Geocoding in Google Sheets

Geocoding in Google Sheets

The NYS GIS Program Office geocoding service can geocode structured addresses (with street number, city, zipcode, etc. in different fields) as well as freeform addresses (with everything in a single field).

This geocoder is available as an ArcGIS REST GeocodeServer, which is great if you are using Esri software, but what if you are not? Below, we'll see how to use the geocoder within Google Sheets, for an easy way to geocode addresses across New York State, without having to use any special software.

Understanding the GeocodeServer request URL

Calls to an ArcGIS GeocodeServer can be written in the form of a URL with parameters for the input address and output settings. Here is an example, broken into separate lines for readability:

@kgjenkins
kgjenkins / readme.md
Last active January 27, 2024 22:01
TIFF compression options

TIFF compression options

Summary

Realistically, especially when considering the inherent noise in the original image, I'd settle for lossy compression with COMPRESS=JPEG JPEG_QUALITY=90, which could reduce file size fairly quickly to 16% of the original.

But if lossless compression is a hard requirement, I'd probably go with COMPRESS=LZW PREDICTOR=2. However, I would want to verify that any downstream tools would support this sort of compression.

UPDATE: When saving with JPEG compression, further speed and size improvements are gained by adding PHOTOMETRIC=YCBCR, which uses a different color space that has even better compression. I've added new rows to the table for YCBCR, as well as .jp2 formats.

@kgjenkins
kgjenkins / gbl-dcat-alternative.md
Last active February 8, 2019 00:28
Alternative to using DCAT Distribution in GeoBlacklight records

Alternative to using DCAT Distribution in GeoBlacklight records

DCAT is pretty complex, and I'm wondering if it perhaps is overkill for GeoBlacklight records. If we aren't planning to use the full DCAT standard (and, no, I'm not suggesting that we do), is it really that helpful to use just the DCAT distribution?

The following is an attempt to present metadata, webservices, and downloads as simply as possible, with a top-level property for each of those groupings. These groupings will make it easier to automatically render a list of metadata options, or download options, or webservices options, on the GeoBlacklight page.

Each grouping contains an array of objects which typically have just a type and a url. I've tried to keep the type values as simple as possible. The type value could be used as button or link labels in GeoBlacklight, but this could be overridden by the optional label value, which would be especially useful to distinguish multiple entries of the having the same basic `t