Skip to content

Commit 535c09c

Browse files
committed
Load postal codes on import, fixes #68
1 parent b2b836c commit 535c09c

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

importer/src/hierarchyitem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ bool HierarchyItem::keep(bool verbose) const
8787
if (s_skip_types.count(m_type) > 0)
8888
return false;
8989

90-
return !m_name.empty() || s_priority_types.count(m_type) > 0;
90+
return !m_name.empty() || !m_postcode.empty() || s_priority_types.count(m_type) > 0;
9191
}
9292

9393
bool HierarchyItem::is_duplicate(std::shared_ptr<HierarchyItem> item) const

importer/src/main.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)