Skip to content

Instantly share code, notes, and snippets.

@stevevance
Created January 25, 2022 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevevance/442afd6a018f338c3e128440e5c698e9 to your computer and use it in GitHub Desktop.
Save stevevance/442afd6a018f338c3e128440e5c698e9 to your computer and use it in GitHub Desktop.
How to find adjacent parcels
/* thanks to https://stackoverflow.com/a/12521268/464883 for help writing the query */
/* find 2 parcels that share an edge */
SELECT DISTINCT v1.pin14, v1.property_class
FROM view_cook_scavenger_sale_2022 v1
WHERE EXISTS (
SELECT v2.pin14 FROM view_cook_scavenger_sale_2022 v2
WHERE st_touches(v1.geom, v2.geom)
and v2.area >= 3000
)
and v1.city = 'CHICAGO'
and property_class = '1-00'
and v1.area >= 3000;
/* find 3 parcels that share an edge (v1 will probably be the "center" parcel of the trio) */
--create view view_cook_scavenger_sale_2022_trios as
SELECT v1.pin14, v1.property_class, v1.geom
FROM view_cook_scavenger_sale_2022 v1
WHERE EXISTS (
SELECT v2.pin14 FROM view_cook_scavenger_sale_2022 v2, view_cook_scavenger_sale_2022 v3
WHERE st_touches(v1.geom, v2.geom)
AND st_touches(v1.geom, v3.geom)
and v2.area >= 3000
and v3.area >= 3000
AND v1.pin14 != v2.pin14
AND v1.pin14 != v3.pin14
and v2.pin14 != v3.pin14
)
and v1.city = 'CHICAGO'
and property_class = '1-00'
and v1.area >= 3000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment