Skip to content

Instantly share code, notes, and snippets.

@kgjenkins
Last active March 1, 2024 21:02
Show Gist options
  • Save kgjenkins/ad26a278ecbf745873b8504dd7e217b3 to your computer and use it in GitHub Desktop.
Save kgjenkins/ad26a278ecbf745873b8504dd7e217b3 to your computer and use it in GitHub Desktop.
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.
1. Run processing tool "Explode Lines" on the "streets" layer
2. Run processing tool "Select within Distance"
- select features from "Exploded"
- by comparing to the features from "parks"
- where the features are within 100 meters
3. Run processing tool "Shortest line between features"
- source layer = "Exploded" SELECTED FEATURES ONLY
- destination layer = "parks"
- method = distance to nearest point on feature
- maximum number of neighbors = 1
4. Right-click the "Shortest lines" layer > Properties
- On the "source" tab, click the button to "Create spatial index"
5. Select all features in the "Shortest lines" layer
6. Run processing tool "Select by location"
- select features from "Shortest lines"
- where the features "are within"
- by comparing to... "parks"
- modify current selection by "removing from current selection"
(after running, the selection should only include shortest lines outside the parks)
7. Run processing tool "Extract specific vertices"
- input layer = "Shortest lines" SELECTED FEATURES ONLY
- vertex indices = 1 (these will be the points on the park polygons closest to the streets)
At this point, we'll have too many points and many duplicate points.
8. Run processing tool "Snap geometries to layer"
- input layer = "Vertices"
- reference layer = "Vertices"
- tolerance = 50 meters
9. Run processing tool "Delete duplicate geometries"
- input layer = "Snapped geometry"
10. Save the "Cleaned" layer to a file
- First, we need to remove the "fid" field, since it may have non-unique values:
- Open the attribute table, turn on editing, delete the "fid" field, and save the changes
- Right-click the "Cleaned" layer > Make permanent
- save file as a geopackage
Now you should have a reasonable point file of just the unique points
along the park boundaries that are closest to the roads.
Now you can run the "Iso-Area as Interpolation (From Layer)" tool
using this layer as the start points. I'd suggest setting the size of
the iso-area to at least 2500 meters, and set the cellsize to 50m.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment