@@ -232,6 +232,46 @@ select place_id as parent_place_resolved from prec where linked_place_id is null
232232              << " ; Missing parents: "   << hierarchy.get_missing_count () << std::endl;
233233  }
234234
235+   //  load centroids for postal codes
236+   const  std::string postal_codes_query
237+       = R"SQL( 
238+ select pc.place_id, NULL as linked_place_id, parent_place_resolved as parent_place_id, country_code, 'postal' as class, 'code' as type, 
239+ NULL as name, NULL as extra, NULL as housenumber, 
240+ postcode, ST_X(geometry) as longitude, ST_Y(geometry) as latitude, 
241+ NULL as osm_type, NULL as osm_id 
242+ from location_postcode pc 
243+ left join lateral 
244+ (with recursive prec as 
245+ (select place_id, linked_place_id from placex where pc.parent_place_id=placex.place_id 
246+ union select p.place_id, p.linked_place_id from placex p join prec on p.place_id=prec.linked_place_id) 
247+ select place_id as parent_place_resolved from prec where linked_place_id is null limit 1) as pres on true 
248+       )SQL"  ;
249+   {
250+     pqxx::result r = txn.exec_params (postal_codes_query
251+                                          + " where " 
252+                                            " ST_Intersects(ST_GeomFromGeoJSON($1), geometry)"  ,
253+                                      border);
254+ 
255+     size_t  count = 0 ;
256+     for  (const  pqxx::row &row : r)
257+       {
258+         ++count;
259+         std::shared_ptr<HierarchyItem> item = std::make_shared<HierarchyItem>(row);
260+         if  (!item->keep ())
261+           {
262+             std::cout << " Dropping postcode?" 
263+                       << " \n "  ;
264+             item->print_item (0 );
265+             continue ;
266+           }
267+         hierarchy.add_item (item);
268+         if  (count % printout_step == 0 )
269+           std::cout << " Imported postal codes: "   << count
270+                     << " ; Root elements: "   << hierarchy.get_root_count ()
271+                     << " ; Missing parents: "   << hierarchy.get_missing_count () << std::endl;
272+       }
273+   }
274+ 
235275  //  find missing parents for root nodes
236276  std::cout << " Fill missing hierarchies. Root size: "   << hierarchy.get_root_count () << " \n "  ;
237277  for  (hindex parent = hierarchy.get_next_nonzero_root_parent (); parent;
0 commit comments