This repository was archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuilding_composite.sql
81 lines (69 loc) · 1.68 KB
/
building_composite.sql
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
-- creates the Buildings Composite Dataset
DROP TABLE IF EXISTS building_composite;
CREATE TABLE building_composite AS (
WITH footprint_centroid AS(
SELECT name,
bin,
bbl,
cnstrct_yr,
lstmoddate,
lststatype,
doitt_id,
heightroof,
feat_code,
groundelev,
num_floors,
built_code,
ST_Centroid(geom) as geom
FROM doitt_buildingfootprints
),
footprint_mappluto AS (
SELECT
a.bbl,
a.bbl::text as bbl_text,
a.bin,
a.doitt_id,
b.cd,
b.bldgclass,
b.landuse,
b.ownername,
b.ownertype,
b.numbldgs,
b.numfloors,
b.lotarea,
b.unitsres,
b.unitstotal,
b.bsmtcode,
b.proxcode,
b.lottype,
b.yearbuilt,
b.yearalter1,
b.yearalter2,
b.borocode,
a.heightroof,
a.feat_code,
a.groundelev,
a.lststatype,
b.bbl AS sv_bbl
FROM footprint_centroid a, dcp_mappluto b
WHERE ST_Within(a.geom, b.geom)
)
SELECT a.*, b.alladd as padaddress
FROM footprint_mappluto a
LEFT JOIN dcp_pad b
ON a.bin::text=b.bin
);
UPDATE building_composite
SET padaddress = REPLACE(padaddress,'(','')
WHERE padaddress LIKE '%(%)%' AND (lottype='3' OR lottype = '4' OR (lottype='1' AND lotarea::double precision >= 10000) OR (numbldgs > 3 AND numfloors >= 8 AND lotarea::double precision >= 10000));
UPDATE building_composite
SET padaddress = REPLACE(padaddress,')','')
WHERE padaddress LIKE '%)%' AND (lottype='3' OR lottype = '4' OR (lottype='1' AND lotarea::double precision >= 10000) OR (numbldgs > 3 AND numfloors >= 8 AND lotarea::double precision >= 10000));
-- COPY(
-- SELECT * FROM footprint_mappluto_pad
-- )TO '/prod/db-pad/output/building_composite.csv' DELIMITER ',' CSV HEADER;
-- ;
-- DROP TABLE IF EXISTS building_composite;
-- CREATE building_composite AS (
-- SELECT
-- )