forked from cliffpat/spatial-sql-isnt-scary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproximity-analysis.sql
More file actions
30 lines (26 loc) · 1.2 KB
/
proximity-analysis.sql
File metadata and controls
30 lines (26 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--How far is each parcel from a community centre?
SELECT DISTINCT ON (a.id)
a.*, b.centre,
st_distance(a.geom,b.geom) as distance_m
FROM spatial_sql_webinar.windsor_parcels AS a
LEFT JOIN spatial_sql_webinar.windsor_community_centres b
ON st_dwithin(a.geom,b.geom,10000)
ORDER BY a.id, distance_m;
--CREATE TABLE spatial_sql_webinar.windsor_parcels_with_community_centres AS
SELECT DISTINCT ON (a.id)
a.*, b.centre,
st_distance(a.geom,b.geom) as distance_m
FROM spatial_sql_webinar.windsor_parcels AS a
LEFT JOIN spatial_sql_webinar.windsor_community_centres b
ON st_dwithin(a.geom,b.geom,10000)
ORDER BY a.id, distance_m;
--How many residential parcels are there within 500m of the Willistead Heritage Complex?
SELECT count(*) AS residential_parcels
FROM spatial_sql_webinar.windsor_parcels_with_community_centres
WHERE centre LIKE 'Willistead Heritage Complex' AND distance_m < 500 AND zoning LIKE 'RD%';
--Which community centre served the highest number of residential parcels within a 2km radius?
SELECT centre, count(centre) AS residential_parcels
FROM spatial_sql_webinar.windsor_parcels_with_community_centres
WHERE zoning LIKE 'RD%' AND distance_m < 2000
GROUP BY centre
ORDER BY residential_parcels desc;