@@ -41,13 +41,17 @@ AS $$
4141 h .house_number ::text ,
4242 c .postcode ::text ,
4343 NULLIF(c .name , ' ' )::text as city,
44+ NULLIF(a6 .name , ' ' )::text as county,
45+ NULLIF(a4 .name , ' ' )::text as " state" ,
4446 h .geometry ::gis .geometry (point , 3857 ),
4547 gis .ST_Distance (h .geometry , center) as distance,
4648 ' 00000000-0000-0000-0000-000000000000' ::uuid as license_id
4749 FROM
4850 public .osm_struct_streets s
4951 JOIN public .osm_struct_cities c ON s .city_id = c .id
5052 JOIN public .osm_struct_house h ON h .street_id = s .id
53+ LEFT JOIN public .osm_admin a4 ON gis .ST_Contains (a4 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a4 .admin_level = 4
54+ LEFT JOIN public .osm_admin a6 ON gis .ST_Contains (a6 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a6 .admin_level = 6
5155 WHERE
5256 (center IS NULL OR gis .ST_DWithin (h .geometry , center, radius)) -- only search around center if center is not null
5357 AND s .name % search_term
@@ -92,13 +96,17 @@ BEGIN
9296 h .house_number ::text ,
9397 c .postcode ::text ,
9498 NULLIF(c .name , ' ' )::text as city,
99+ NULLIF(a6 .name , ' ' )::text as county,
100+ NULLIF(a4 .name , ' ' )::text as " state" ,
95101 h .geometry ::gis .geometry (point , 3857 ),
96102 gis .ST_Distance (h .geometry , center) as distance,
97103 ' 00000000-0000-0000-0000-000000000000' ::uuid as license_id
98104 FROM
99105 public .osm_struct_streets s
100106 JOIN public .osm_struct_cities c ON s .city_id = c .id
101107 JOIN public .osm_struct_house h ON h .street_id = s .id
108+ LEFT JOIN public .osm_admin a4 ON gis .ST_Contains (a4 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a4 .admin_level = 4
109+ LEFT JOIN public .osm_admin a6 ON gis .ST_Contains (a6 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a6 .admin_level = 6
102110 WHERE
103111 (center IS NULL OR gis .ST_DWithin (h .geometry , center, radius)) -- only search around center if center is not null
104112 AND gis .ST_Within (gis .ST_Centroid (h .geometry ), country_poly) -- intersect with country polygon
177185 h .house_number ::text ,
178186 c .postcode ::text ,
179187 NULLIF(c .name , ' ' )::text as city,
188+ NULLIF(a6 .name , ' ' )::text as county,
189+ NULLIF(a4 .name , ' ' )::text as " state" ,
180190 h .geometry ::gis .geometry (point , 3857 ),
181191 gis .ST_Distance (h .geometry , center) as distance,
182192 ' 00000000-0000-0000-0000-000000000000' ::uuid as license_id
183193 FROM
184194 public .osm_struct_streets s
185195 JOIN public .osm_struct_cities c ON s .city_id = c .id
186196 JOIN public .osm_struct_house h ON h .street_id = s .id
197+ LEFT JOIN public .osm_admin a4 ON gis .ST_Contains (a4 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a4 .admin_level = 4
198+ LEFT JOIN public .osm_admin a6 ON gis .ST_Contains (a6 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a6 .admin_level = 6
187199 WHERE
188200 (center IS NULL OR gis .ST_DWithin (h .geometry , center, radius)) -- only search around center if center is not null
189201 AND c .name % search_city
@@ -232,13 +244,17 @@ BEGIN
232244 h .house_number ::text ,
233245 c .postcode ::text ,
234246 NULLIF(c .name , ' ' )::text as city,
247+ NULLIF(a6 .name , ' ' )::text as county,
248+ NULLIF(a4 .name , ' ' )::text as " state" ,
235249 h .geometry ::gis .geometry (point , 3857 ),
236250 gis .ST_Distance (h .geometry , center) as distance,
237251 ' 00000000-0000-0000-0000-000000000000' ::uuid as license_id
238252 FROM
239253 public .osm_struct_streets s
240254 JOIN public .osm_struct_cities c ON s .city_id = c .id
241255 JOIN public .osm_struct_house h ON h .street_id = s .id
256+ LEFT JOIN public .osm_admin a4 ON gis .ST_Contains (a4 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a4 .admin_level = 4
257+ LEFT JOIN public .osm_admin a6 ON gis .ST_Contains (a6 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a6 .admin_level = 6
242258 WHERE
243259 (center IS NULL OR gis .ST_DWithin (h .geometry , center, radius)) -- only search around center if center is not null
244260 AND gis .ST_Within (gis .ST_Centroid (h .geometry ), country_poly) -- intersect with country polygon
314330 h .house_number ::text ,
315331 c .postcode ::text ,
316332 NULLIF(c .name , ' ' )::text as city,
333+ NULLIF(a6 .name , ' ' )::text as county,
334+ NULLIF(a4 .name , ' ' )::text as " state" ,
317335 h .geometry ::gis .geometry (point , 3857 ),
318336 gis .ST_Distance (h .geometry , center) as distance,
319337 ' 00000000-0000-0000-0000-000000000000' ::uuid as license_id
320338 FROM
321339 public .osm_struct_streets s
322340 JOIN public .osm_struct_cities c ON s .city_id = c .id
323341 JOIN public .osm_struct_house h ON h .street_id = s .id
342+ LEFT JOIN public .osm_admin a4 ON gis .ST_Contains (a4 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a4 .admin_level = 4
343+ LEFT JOIN public .osm_admin a6 ON gis .ST_Contains (a6 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a6 .admin_level = 6
324344 WHERE
325345 (center IS NULL OR gis .ST_DWithin (h .geometry , center, radius)) -- only search around center if center is not null
326346 AND s .name % search_term
@@ -369,13 +389,17 @@ BEGIN
369389 h .house_number ::text ,
370390 c .postcode ::text ,
371391 NULLIF(c .name , ' ' )::text as city,
392+ NULLIF(a6 .name , ' ' )::text as county,
393+ NULLIF(a4 .name , ' ' )::text as " state" ,
372394 h .geometry ::gis .geometry (point , 3857 ),
373395 gis .ST_Distance (h .geometry , center) as distance,
374396 ' 00000000-0000-0000-0000-000000000000' ::uuid as license_id
375397 FROM
376398 public .osm_struct_streets s
377399 JOIN public .osm_struct_cities c ON s .city_id = c .id
378400 JOIN public .osm_struct_house h ON h .street_id = s .id
401+ LEFT JOIN public .osm_admin a4 ON gis .ST_Contains (a4 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a4 .admin_level = 4
402+ LEFT JOIN public .osm_admin a6 ON gis .ST_Contains (a6 .geometry , h .geometry ::gis .geometry (point , 3857 )) and a6 .admin_level = 6
379403 WHERE
380404 (center IS NULL OR gis .ST_DWithin (h .geometry , center, radius)) -- only search around center if center is not null
381405 AND gis .ST_Within (gis .ST_Centroid (h .geometry ), country_poly) -- intersect with country polygon
0 commit comments