Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Examples

For a gentler introduction and simpler examples, see the Tutorial.

Merge all counties within a 10 mile radius of Philadelphia

Given this FeatureCollection of counties in the Delaware Valley (del_val.geojson):

gq '
(
  find(.properties.fips == "42101").geometry |
  centroid |
  buffer(10, {unit: "miles"})
) as $philly_buffer |
    merge(.geometry | intersects($philly_buffer))
' del_val.geojson

This works by:

  1. Finding the Feature corresponding to Philadelphia county (FIPS county code of 42101)
  2. Calculating the centroid of its geometry
  3. Generating a buffer with a radius of 10 miles around the centroid
  4. Merging all Features whose geometries intersect with that buffer

Historical Markers in Philadelphia

Given this FeatureCollection of historical markers (historical_markers.geojson) and this FeatureCollection of the city limits of Philadelphia (City_Limits.geojson):

gq '
($2 | union) as $city_limits |
  $1 |
  filter(
    .geometry != null and (
      .geometry | contained_by($city_limits)
    )
  )
' historical_markers.geojson City_Limits.geojson

This works by:

  1. Unioning the geometries of all Features within the city limits FeatureCollection ($2 refers to the second input file)
  2. Filtering the historical markers FeatureCollection ($1 refers to the first input file) by non-null geometries falling within the city limits