Skip to content

Instantly share code, notes, and snippets.

Keith Jenkins kgjenkins

  • Ithaca, NY
Block or report user

Report or block kgjenkins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kgjenkins
kgjenkins / readme.md
Last active Jul 23, 2019
Aggregate counts of multi-valued columns
View readme.md

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 13, 2019
Creating halftones in QGIS
View readme.md

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 May 19, 2019
Geocoding in Google Sheets
View readme.md

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 Apr 29, 2019
TIFF compression options
View readme.md

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 wolud 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 Feb 8, 2019
Alternative to using DCAT Distribution in GeoBlacklight records
View gbl-dcat-alternative.md

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

@kgjenkins
kgjenkins / readme.md
Last active Aug 6, 2019
Labels with callout lines in QGIS
View readme.md

Labels with callout lines in QGIS

Callouts, sometimes called leader lines, are lines between labels and features on a map. They are useful when constraints of space force a label to be moved away from the feature. The callout helps to reconnect the label to the feature it refers to.

image

There are probably multiple ways to do this, but here is one way using a geometry generator in QGIS 3.x:

@kgjenkins
kgjenkins / readme.md
Last active May 26, 2018
Interpolate points along lines using QGIS virtual layers
View readme.md

Interpolate points along lines using QGIS virtual layers

Suppose we want to interpolate a number of points along each line in a layer:

image

We have a column called stations that specifies how many points to interpolate on each line:

image

@kgjenkins
kgjenkins / readme.md
Last active Aug 6, 2018
Straighten lines in a layer using QGIS virtual layers
View readme.md

Straighten lines in a layer using QGIS virtual layers

Suppose we have a layer of wiggly lines (black), and we want to straighten the lines (blue):

image

We can use QGIS virtual layers to create a new layer of straightened lines:

select
  make_line(start_point(geometry), end_point(geometry)) as geometry,
@kgjenkins
kgjenkins / readme.md
Last active May 26, 2018
Faster, faster distance matrix
View readme.md

Faster, faster distance matrix

Suppose you have a set of points, and would like to calculate the distance from each point to every other point. QGIS provides a "Distance Matrix" tool that can do this. It can actually produce several types of distance matrices, but for now this post will focus on what the tool calls a "Linear (N*k x 3) distance matrix", which gives us an output that looks like this:

InputID TargetID Distance
1 1 0
@kgjenkins
kgjenkins / readme.md
Last active May 19, 2017
Allocate polygon population values to a grid of points, and save as delimited text
View readme.md

Allocate polygon population values to a grid of points, and save as delimited text

We have population data (total population, male, female, etc.) by polygon (Census tracts), but want a CSV file of the population densities for a regular grid of points at 1km spacing.

Below are the steps to do this using QGIS. In this example, we have already added a polygon layer called "Tracts" to the map, and will calculate the male population densities. (Repeat this process for other subpopulations.)

Step 1: Transform the tract polygons to UTM

In order to calculate densities per square kilometer, we will to transform the tracts to a UTM (meters-based) coordinate system. For New York State tracts, we will use UTM zone 18N.

You can’t perform that action at this time.