Skip to content

Instantly share code, notes, and snippets.

@kgjenkins
Created March 3, 2016 16:34
Show Gist options
  • Save kgjenkins/992fc7b9f494f16e8e7b to your computer and use it in GitHub Desktop.
Save kgjenkins/992fc7b9f494f16e8e7b to your computer and use it in GitHub Desktop.
Count polygons within a given distance of each feature

Given a layer called parcels that has a column called abandoned (0 or 1), we add a column called abandoned70ft and to store the number of abandoned parcels within 70 feet.

UPDATE parcels
SET abandoned70ft = (
  SELECT count(*)
  FROM parcels a
  WHERE a.abandoned = 1
  AND ST_Distance(parcels.the_geom::geography, a.the_geom::geography)*3.28084 < 70
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment