BAG create queries.pgsql 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. UPDATE bagactueel.pand
  2. SET bouwjaar = NULL
  3. WHERE bouwjaar > 2050;
  4. UPDATE bagactueel.verblijfsobject
  5. SET oppervlakteverblijfsobject = NULL
  6. WHERE oppervlakteverblijfsobject IN (1, 9999, 99999, 999999);
  7. DROP TABLE bagactueel.verblijfsobject_compleet CASCADE;
  8. DROP TABLE bagactueel.pand_compleet;
  9. DROP TABLE bagactueel.pand_oppervlakte CASCADE;
  10. DROP TABLE bagactueel.temp_verblijfsobject_oppervlakte;
  11. /* Maak nieuwe tabel aan voor complete verblijfsobjecten */
  12. CREATE TABLE bagactueel.verblijfsobject_compleet(
  13. gid serial,
  14. identificatie numeric(16,0),
  15. verblijfsobjectstatus bagactueel.verblijfsobjectstatus,
  16. oppervlakteverblijfsobject numeric(6,0),
  17. gebruiksdoelverblijfsobject bagactueel.gebruiksdoelverblijfsobject,
  18. gerelateerdpand numeric(16,0),
  19. geopunt geometry(PointZ,28992),
  20. openbareruimtenaam varchar(80),
  21. huisnummer numeric(5,0),
  22. huisletter varchar(1),
  23. huisnummertoevoeging varchar(4),
  24. postcode varchar(6),
  25. woonplaatsnaam varchar(80),
  26. gemeentenaam varchar(80),
  27. provincienaam varchar(16)
  28. );
  29. /* Zorg ervoor dat er geen dubbelingen kunnen ontstaan door een UNIQUE INDEX op de identificatie te zetten */
  30. CREATE UNIQUE INDEX bagactueel_identificatie ON bagactueel.verblijfsobject_compleet (identificatie);
  31. /* Voeg de verschillende VO tabellen en de adres-tabel samen */
  32. INSERT INTO bagactueel.verblijfsobject_compleet (
  33. identificatie,
  34. verblijfsobjectstatus,
  35. oppervlakteverblijfsobject,
  36. gebruiksdoelverblijfsobject,
  37. gerelateerdpand,
  38. geopunt,
  39. openbareruimtenaam,
  40. huisnummer,
  41. huisletter,
  42. huisnummertoevoeging,
  43. postcode,
  44. woonplaatsnaam,
  45. gemeentenaam,
  46. provincienaam
  47. ) SELECT
  48. VO.identificatie,
  49. VO.verblijfsobjectstatus,
  50. VO.oppervlakteverblijfsobject,
  51. VOGD.gebruiksdoelverblijfsobject,
  52. VOGP.gerelateerdpand,
  53. VO.geopunt,
  54. A.openbareruimtenaam,
  55. A.huisnummer,
  56. A.huisletter,
  57. A.huisnummertoevoeging,
  58. A.postcode,
  59. A.woonplaatsnaam,
  60. A.gemeentenaam,
  61. A.provincienaam
  62. FROM
  63. bagactueel.verblijfsobjectactueelbestaand VO
  64. LEFT JOIN bagactueel.verblijfsobjectgebruiksdoelactueelbestaand VOGD
  65. ON VO.identificatie = VOGD.identificatie
  66. LEFT JOIN bagactueel.verblijfsobjectpandactueelbestaand VOGP
  67. ON VO.identificatie = VOGP.identificatie
  68. LEFT JOIN bagactueel.adres A
  69. ON VO.identificatie = A.adresseerbaarobject
  70. AND A.nevenadres = FALSE
  71. ON CONFLICT DO NOTHING;
  72. /* Maak indexen zodat snel op deze kolommen gefilterd kan worden */
  73. CREATE INDEX verblijfsobject_gerelateerdpand ON bagactueel.verblijfsobject_compleet (gerelateerdpand);
  74. CREATE INDEX verblijfsobject_gebruiksdoel ON bagactueel.verblijfsobject_compleet (gebruiksdoelverblijfsobject);
  75. CREATE INDEX verblijfsobject_woonplaats ON bagactueel.verblijfsobject_compleet (woonplaatsnaam);
  76. CREATE INDEX verblijfsobject_gemeente ON bagactueel.verblijfsobject_compleet (gemeentenaam);
  77. CREATE INDEX verblijfsobject_provincie ON bagactueel.verblijfsobject_compleet (provincienaam);
  78. /* In een paar stappen gaan we de oppervlaktes afleiden voor de panden */
  79. CREATE TABLE bagactueel.temp_verblijfsobject_oppervlakte(
  80. gid integer,
  81. gerelateerdpand numeric(16,0),
  82. oppervlakteverblijfsobject numeric(6,0),
  83. gebruiksdoelverblijfsobject bagactueel.gebruiksdoelverblijfsobject
  84. );
  85. CREATE UNIQUE INDEX temp_verblijfsobject_dubbelingen ON bagactueel.temp_verblijfsobject_oppervlakte (gid);
  86. INSERT INTO bagactueel.temp_verblijfsobject_oppervlakte (gid, gerelateerdpand, oppervlakteverblijfsobject, gebruiksdoelverblijfsobject)
  87. SELECT gid, gerelateerdpand, oppervlakteverblijfsobject, gebruiksdoelverblijfsobject FROM bagactueel.verblijfsobject_compleet
  88. ON CONFLICT DO NOTHING;
  89. CREATE TABLE bagactueel.pand_oppervlakte(
  90. identificatie numeric(16,0),
  91. oppervlakte_totaal numeric(6,0),
  92. oppervlakte_woonfunctie numeric(6,0),
  93. oppervlakte_bijeenkomstfunctie numeric(6,0),
  94. oppervlakte_celfunctie numeric(6,0),
  95. oppervlakte_gezondheidszorgfunctie numeric(6,0),
  96. oppervlakte_industriefunctie numeric(6,0),
  97. oppervlakte_kantoorfunctie numeric(6,0),
  98. oppervlakte_logiesfunctie numeric(6,0),
  99. oppervlakte_onderwijsfunctie numeric(6,0),
  100. oppervlakte_sportfunctie numeric(6,0),
  101. oppervlakte_winkelfunctie numeric(6,0),
  102. oppervlakte_overige numeric(6,0),
  103. aantal_totaal numeric(6,0),
  104. aantal_woonfunctie numeric(6,0),
  105. aantal_bijeenkomstfunctie numeric(6,0),
  106. aantal_celfunctie numeric(6,0),
  107. aantal_gezondheidszorgfunctie numeric(6,0),
  108. aantal_industriefunctie numeric(6,0),
  109. aantal_kantoorfunctie numeric(6,0),
  110. aantal_logiesfunctie numeric(6,0),
  111. aantal_onderwijsfunctie numeric(6,0),
  112. aantal_sportfunctie numeric(6,0),
  113. aantal_winkelfunctie numeric(6,0),
  114. aantal_overige numeric(6,0)
  115. );
  116. /* INSERT THE TOTALS INTO TEMPORARY HOLDING TABLE */
  117. INSERT INTO bagactueel.pand_oppervlakte(
  118. identificatie,
  119. oppervlakte_totaal,
  120. aantal_totaal
  121. ) SELECT
  122. gerelateerdpand,
  123. SUM(oppervlakteverblijfsobject),
  124. COUNT(*)
  125. FROM
  126. bagactueel.verblijfsobject_compleet
  127. GROUP BY
  128. gerelateerdpand;
  129. INSERT INTO bagactueel.pand_oppervlakte(
  130. identificatie,
  131. oppervlakte_woonfunctie,
  132. aantal_woonfunctie
  133. ) SELECT
  134. gerelateerdpand,
  135. SUM(oppervlakteverblijfsobject),
  136. COUNT(*)
  137. FROM
  138. bagactueel.verblijfsobject_compleet
  139. WHERE
  140. gebruiksdoelverblijfsobject = 'woonfunctie'
  141. GROUP BY
  142. gerelateerdpand;
  143. INSERT INTO bagactueel.pand_oppervlakte(
  144. identificatie,
  145. oppervlakte_bijeenkomstfunctie,
  146. aantal_bijeenkomstfunctie
  147. ) SELECT
  148. gerelateerdpand,
  149. SUM(oppervlakteverblijfsobject),
  150. COUNT(*)
  151. FROM
  152. bagactueel.verblijfsobject_compleet
  153. WHERE
  154. gebruiksdoelverblijfsobject = 'bijeenkomstfunctie'
  155. GROUP BY
  156. gerelateerdpand;
  157. INSERT INTO bagactueel.pand_oppervlakte(
  158. identificatie,
  159. oppervlakte_celfunctie,
  160. aantal_celfunctie
  161. ) SELECT
  162. gerelateerdpand,
  163. SUM(oppervlakteverblijfsobject),
  164. COUNT(*)
  165. FROM
  166. bagactueel.verblijfsobject_compleet
  167. WHERE
  168. gebruiksdoelverblijfsobject = 'celfunctie'
  169. GROUP BY
  170. gerelateerdpand;
  171. INSERT INTO bagactueel.pand_oppervlakte(
  172. identificatie,
  173. oppervlakte_gezondheidszorgfunctie,
  174. aantal_gezondheidszorgfunctie
  175. ) SELECT
  176. gerelateerdpand,
  177. SUM(oppervlakteverblijfsobject),
  178. COUNT(*)
  179. FROM
  180. bagactueel.verblijfsobject_compleet
  181. WHERE
  182. gebruiksdoelverblijfsobject = 'gezondheidszorgfunctie'
  183. GROUP BY
  184. gerelateerdpand;
  185. INSERT INTO bagactueel.pand_oppervlakte(
  186. identificatie,
  187. oppervlakte_industriefunctie,
  188. aantal_industriefunctie
  189. ) SELECT
  190. gerelateerdpand,
  191. SUM(oppervlakteverblijfsobject),
  192. COUNT(*)
  193. FROM
  194. bagactueel.verblijfsobject_compleet
  195. WHERE
  196. gebruiksdoelverblijfsobject = 'industriefunctie'
  197. GROUP BY
  198. gerelateerdpand;
  199. INSERT INTO bagactueel.pand_oppervlakte(
  200. identificatie,
  201. oppervlakte_kantoorfunctie,
  202. aantal_kantoorfunctie
  203. ) SELECT
  204. gerelateerdpand,
  205. SUM(oppervlakteverblijfsobject),
  206. COUNT(*)
  207. FROM
  208. bagactueel.verblijfsobject_compleet
  209. WHERE
  210. gebruiksdoelverblijfsobject = 'kantoorfunctie'
  211. GROUP BY
  212. gerelateerdpand;
  213. INSERT INTO bagactueel.pand_oppervlakte(
  214. identificatie,
  215. oppervlakte_logiesfunctie,
  216. aantal_logiesfunctie
  217. ) SELECT
  218. gerelateerdpand,
  219. SUM(oppervlakteverblijfsobject),
  220. COUNT(*)
  221. FROM
  222. bagactueel.verblijfsobject_compleet
  223. WHERE
  224. gebruiksdoelverblijfsobject = 'logiesfunctie'
  225. GROUP BY
  226. gerelateerdpand;
  227. INSERT INTO bagactueel.pand_oppervlakte(
  228. identificatie,
  229. oppervlakte_onderwijsfunctie,
  230. aantal_onderwijsfunctie
  231. ) SELECT
  232. gerelateerdpand,
  233. SUM(oppervlakteverblijfsobject),
  234. COUNT(*)
  235. FROM
  236. bagactueel.verblijfsobject_compleet
  237. WHERE
  238. gebruiksdoelverblijfsobject = 'onderwijsfunctie'
  239. GROUP BY
  240. gerelateerdpand;
  241. INSERT INTO bagactueel.pand_oppervlakte(
  242. identificatie,
  243. oppervlakte_sportfunctie,
  244. aantal_sportfunctie
  245. ) SELECT
  246. gerelateerdpand,
  247. SUM(oppervlakteverblijfsobject),
  248. COUNT(*)
  249. FROM
  250. bagactueel.verblijfsobject_compleet
  251. WHERE
  252. gebruiksdoelverblijfsobject = 'sportfunctie'
  253. GROUP BY
  254. gerelateerdpand;
  255. INSERT INTO bagactueel.pand_oppervlakte(
  256. identificatie,
  257. oppervlakte_winkelfunctie,
  258. aantal_winkelfunctie
  259. ) SELECT
  260. gerelateerdpand,
  261. SUM(oppervlakteverblijfsobject),
  262. COUNT(*)
  263. FROM
  264. bagactueel.verblijfsobject_compleet
  265. WHERE
  266. gebruiksdoelverblijfsobject = 'winkelfunctie'
  267. GROUP BY
  268. gerelateerdpand;
  269. INSERT INTO bagactueel.pand_oppervlakte(
  270. identificatie,
  271. oppervlakte_overige,
  272. aantal_overige
  273. ) SELECT
  274. gerelateerdpand,
  275. SUM(oppervlakteverblijfsobject),
  276. COUNT(*)
  277. FROM
  278. bagactueel.verblijfsobject_compleet
  279. WHERE
  280. gebruiksdoelverblijfsobject = 'overige gebruiksfunctie'
  281. GROUP BY
  282. gerelateerdpand;
  283. CREATE INDEX pand_oppervlakte_ident ON bagactueel.pand_oppervlakte (identificatie);
  284. /* CREATE THE TABLE THAT HOLDS THE TOTALS PER PAND */
  285. CREATE MATERIALIZED VIEW bagactueel.pand_oppervlakte_sum AS
  286. SELECT identificatie,
  287. SUM(oppervlakte_totaal) oppervlakte_totaal,
  288. SUM(oppervlakte_woonfunctie) oppervlakte_woonfunctie,
  289. SUM(oppervlakte_bijeenkomstfunctie) oppervlakte_bijeenkomstfunctie,
  290. SUM(oppervlakte_celfunctie) oppervlakte_celfunctie,
  291. SUM(oppervlakte_gezondheidszorgfunctie) oppervlakte_gezondheidszorgfunctie,
  292. SUM(oppervlakte_industriefunctie) oppervlakte_industriefunctie,
  293. SUM(oppervlakte_kantoorfunctie) oppervlakte_kantoorfunctie,
  294. SUM(oppervlakte_logiesfunctie) oppervlakte_logiesfunctie,
  295. SUM(oppervlakte_onderwijsfunctie) oppervlakte_onderwijsfunctie,
  296. SUM(oppervlakte_sportfunctie) oppervlakte_sportfunctie,
  297. SUM(oppervlakte_winkelfunctie) oppervlakte_winkelfunctie,
  298. SUM(oppervlakte_overige) oppervlakte_overige,
  299. SUM(aantal_totaal) aantal_totaal,
  300. SUM(aantal_woonfunctie) aantal_woonfunctie,
  301. SUM(aantal_bijeenkomstfunctie) aantal_bijeenkomstfunctie,
  302. SUM(aantal_celfunctie) aantal_celfunctie,
  303. SUM(aantal_gezondheidszorgfunctie) aantal_gezondheidszorgfunctie,
  304. SUM(aantal_industriefunctie) aantal_industriefunctie,
  305. SUM(aantal_kantoorfunctie) aantal_kantoorfunctie,
  306. SUM(aantal_logiesfunctie) aantal_logiesfunctie,
  307. SUM(aantal_onderwijsfunctie) aantal_onderwijsfunctie,
  308. SUM(aantal_sportfunctie) aantal_sportfunctie,
  309. SUM(aantal_winkelfunctie) aantal_winkelfunctie,
  310. SUM(aantal_overige) aantal_overige
  311. FROM
  312. bagactueel.pand_oppervlakte
  313. GROUP BY identificatie;
  314. CREATE INDEX pand_oppervlakte_sum_ident ON bagactueel.pand_oppervlakte_sum (identificatie);
  315. /* Verzamel de adressen per verblijfsobject in een tabel */
  316. CREATE MATERIALIZED VIEW bagactueel.pand_adres AS
  317. SELECT V.gerelateerdpand identificatie,
  318. string_agg(CONCAT(A.openbareruimtenaam,' ',A.huisnummer,A.huisletter,A.huisnummertoevoeging,' ',A.postcode,' ')) adres,
  319. MIN(A.gemeentenaam) gemeentenaam,
  320. MIN(A.woonplaatsnaam) woonplaatsnaam,
  321. MIN(A.provincienaam) provincienaam
  322. FROM bagactueel.verblijfsobject_compleet V
  323. LEFT JOIN bagactueel.adres A
  324. ON V.identificatie = A.adresseerbaarobject
  325. GROUP BY V.gerelateerdpand;
  326. CREATE INDEX pand_adres_index ON bagactueel.pand_adres (identificatie);
  327. /* Construeer de tabel pand_compleet */
  328. CREATE TABLE bagactueel.pand_compleet(
  329. gid serial,
  330. identificatie numeric(16,0),
  331. pandstatus bagactueel.pandstatus,
  332. bouwjaar numeric(4,0),
  333. geovlak geometry(PolygonZ,28992),
  334. gemeentenaam varchar(80),
  335. woonplaatsnaam varchar(80),
  336. provincienaam varchar(16),
  337. adres TEXT,
  338. OTO_oppervlakte_totaal numeric(6,0),
  339. OWO_oppervlakte_woonfunctie numeric(6,0),
  340. OBI_oppervlakte_bijeenkomstfunctie numeric(6,0),
  341. OCE_oppervlakte_celfunctie numeric(6,0),
  342. OGZ_oppervlakte_gezondheidszorgfunctie numeric(6,0),
  343. OIN_oppervlakte_industriefunctie numeric(6,0),
  344. OKA_oppervlakte_kantoorfunctie numeric(6,0),
  345. OLO_oppervlakte_logiesfunctie numeric(6,0),
  346. OOW_oppervlakte_onderwijsfunctie numeric(6,0),
  347. OSP_oppervlakte_sportfunctie numeric(6,0),
  348. OWI_oppervlakte_winkelfunctie numeric(6,0),
  349. OOV_oppervlakte_overige numeric(6,0),
  350. ATO_aantal_totaal numeric(6,0),
  351. AWO_aantal_woonfunctie numeric(6,0),
  352. ABI_aantal_bijeenkomstfunctie numeric(6,0),
  353. ACE_aantal_celfunctie numeric(6,0),
  354. AGZ_aantal_gezondheidszorgfunctie numeric(6,0),
  355. AIN_aantal_industriefunctie numeric(6,0),
  356. AKA_aantal_kantoorfunctie numeric(6,0),
  357. ALO_aantal_logiesfunctie numeric(6,0),
  358. AOW_aantal_onderwijsfunctie numeric(6,0),
  359. ASP_aantal_sportfunctie numeric(6,0),
  360. AWI_aantal_winkelfunctie numeric(6,0),
  361. AOV_aantal_overige numeric(6,0),
  362. HFO_hoofdfunctie_naar_oppervlakte varchar(30),
  363. HFA_hoofdfunctie_naar_aantal varchar(30)
  364. );
  365. INSERT INTO bagactueel.pand_compleet(
  366. identificatie,
  367. pandstatus,
  368. bouwjaar,
  369. geovlak,
  370. gemeentenaam,
  371. woonplaatsnaam,
  372. provincienaam,
  373. adres,
  374. OTO_oppervlakte_totaal,
  375. OWO_oppervlakte_woonfunctie,
  376. OBI_oppervlakte_bijeenkomstfunctie,
  377. OCE_oppervlakte_celfunctie,
  378. OGZ_oppervlakte_gezondheidszorgfunctie,
  379. OIN_oppervlakte_industriefunctie,
  380. OKA_oppervlakte_kantoorfunctie,
  381. OLO_oppervlakte_logiesfunctie,
  382. OOW_oppervlakte_onderwijsfunctie,
  383. OSP_oppervlakte_sportfunctie,
  384. OWI_oppervlakte_winkelfunctie,
  385. OOV_oppervlakte_overige,
  386. ATO_aantal_totaal,
  387. AWO_aantal_woonfunctie,
  388. ABI_aantal_bijeenkomstfunctie,
  389. ACE_aantal_celfunctie,
  390. AGZ_aantal_gezondheidszorgfunctie,
  391. AIN_aantal_industriefunctie,
  392. AKA_aantal_kantoorfunctie,
  393. ALO_aantal_logiesfunctie,
  394. AOW_aantal_onderwijsfunctie,
  395. ASP_aantal_sportfunctie,
  396. AWI_aantal_winkelfunctie,
  397. AOV_aantal_overige,
  398. HFO_hoofdfunctie_naar_oppervlakte,
  399. HFA_hoofdfunctie_naar_aantal
  400. ) SELECT
  401. P.identificatie,
  402. P.pandstatus,
  403. P.bouwjaar,
  404. P.geovlak,
  405. A.gemeentenaam,
  406. A.woonplaatsnaam,
  407. A.provincienaam,
  408. A.adres,
  409. oppervlakte_totaal,
  410. oppervlakte_woonfunctie,
  411. oppervlakte_bijeenkomstfunctie,
  412. oppervlakte_celfunctie,
  413. oppervlakte_gezondheidszorgfunctie,
  414. oppervlakte_industriefunctie,
  415. oppervlakte_kantoorfunctie,
  416. oppervlakte_logiesfunctie,
  417. oppervlakte_onderwijsfunctie,
  418. oppervlakte_sportfunctie,
  419. oppervlakte_winkelfunctie,
  420. oppervlakte_overige,
  421. aantal_totaal,
  422. aantal_woonfunctie,
  423. aantal_bijeenkomstfunctie,
  424. aantal_celfunctie,
  425. aantal_gezondheidszorgfunctie,
  426. aantal_industriefunctie,
  427. aantal_kantoorfunctie,
  428. aantal_logiesfunctie,
  429. aantal_onderwijsfunctie,
  430. aantal_sportfunctie,
  431. aantal_winkelfunctie,
  432. aantal_overige,
  433. CASE WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_woonfunctie THEN 'woonfunctie'
  434. WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_bijeenkomstfunctie THEN 'bijeenkomstfunctie'
  435. WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_celfunctie THEN 'celfunctie'
  436. WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_gezondheidszorgfunctie THEN 'gezondheidszorgfunctie'
  437. WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_industriefunctie THEN 'industriefunctie'
  438. WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_kantoorfunctie THEN 'kantoorfunctie'
  439. WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_logiesfunctie THEN 'logiesfunctie'
  440. WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_onderwijsfunctie THEN 'onderwijsfunctie'
  441. WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_sportfunctie THEN 'sportfunctie'
  442. WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_winkelfunctie THEN 'winkelfunctie'
  443. WHEN GREATEST(oppervlakte_woonfunctie, oppervlakte_bijeenkomstfunctie, oppervlakte_celfunctie, oppervlakte_gezondheidszorgfunctie, oppervlakte_industriefunctie, oppervlakte_kantoorfunctie, oppervlakte_logiesfunctie, oppervlakte_onderwijsfunctie, oppervlakte_sportfunctie, oppervlakte_winkelfunctie, oppervlakte_overige) = oppervlakte_overige THEN 'overige gebruiksfunctie'
  444. ELSE NULL
  445. END,
  446. CASE WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_woonfunctie THEN 'woonfunctie'
  447. WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_bijeenkomstfunctie THEN 'bijeenkomstfunctie'
  448. WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_celfunctie THEN 'celfunctie'
  449. WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_gezondheidszorgfunctie THEN 'gezondheidszorgfunctie'
  450. WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_industriefunctie THEN 'industriefunctie'
  451. WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_kantoorfunctie THEN 'kantoorfunctie'
  452. WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_logiesfunctie THEN 'logiesfunctie'
  453. WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_onderwijsfunctie THEN 'onderwijsfunctie'
  454. WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_sportfunctie THEN 'sportfunctie'
  455. WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_winkelfunctie THEN 'winkelfunctie'
  456. WHEN GREATEST(aantal_woonfunctie, aantal_bijeenkomstfunctie, aantal_celfunctie, aantal_gezondheidszorgfunctie, aantal_industriefunctie, aantal_kantoorfunctie, aantal_logiesfunctie, aantal_onderwijsfunctie, aantal_sportfunctie, aantal_winkelfunctie, aantal_overige) = aantal_overige THEN 'overige gebruiksfunctie'
  457. ELSE NULL
  458. END
  459. -- Test
  460. FROM bagactueel.pandactueelbestaand P
  461. LEFT JOIN bagactueel.pand_adres A
  462. ON P.identificatie = A.identificatie
  463. LEFT JOIN bagactueel.pand_oppervlakte_sum PO
  464. ON P.identificatie = PO.identificatie;
  465. CREATE INDEX pand_compleet_gemeentenaam ON bagactueel.pand_compleet (gemeentenaam);
  466. CREATE INDEX pand_compleet_woonplaatsnaam ON bagactueel.pand_compleet (woonplaatsnaam);
  467. CREATE INDEX pand_compleet_provincienaam ON bagactueel.pand_compleet (provincienaam);
  468. CREATE MATERIALIZED VIEW bagactueel.pand_adres_onbekend AS
  469. SELECT P.identificatie, G.gemeentenaam, W.woonplaatsnaam, Prov.provincienaam
  470. FROM bagactueel.pand_compleet P
  471. LEFT JOIN bagactueel.woonplaats W
  472. ON ST_Intersects(P.geovlak, W.geovlak)
  473. LEFT JOIN bagactueel.gemeente G
  474. ON ST_Intersects(P.geovlak, G.geovlak)
  475. LEFT JOIN bagactueel.provincie Prov
  476. ON ST_Intersects(P.geovlak, Prov.geovlak)
  477. WHERE P.gemeentenaam IS NULL;
  478. CREATE INDEX pand_adres_onbekend_ident ON bagactueel.pand_adres_onbekend (identificatie);
  479. UPDATE bagactueel.pand_compleet P
  480. SET P.gemeentenaam = T.gemeentenaam,
  481. P.woonplaatsnaam = T.woonplaatsnaam,
  482. P.provincienaam = T.provincienaam
  483. FROM bagactueel.pand_overige_adres AS T
  484. WHERE P.gemeentenaam IS NULL;