BAG create queries.pgsql 24 KB

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