@@ -105,6 +105,7 @@ public void importData(String pbfFilePath, String dataDir) throws Exception {
105105 Path appendDbPath = dataDirectory .resolve ("tmp/append_poi" );
106106 Path nodeCacheDbPath = dataDirectory .resolve ("tmp/node_cache" );
107107 Path wayIndexDbPath = dataDirectory .resolve ("tmp/way_index" );
108+ Path boundaryWayIndexDbPath = dataDirectory .resolve ("tmp/boundary_way_index" );
108109 Path neededNodesDbPath = dataDirectory .resolve ("tmp/needed_nodes" );
109110 Path relIndexDbPath = dataDirectory .resolve ("tmp/rel_index" );
110111 Path poiIndexDbPath = dataDirectory .resolve ("tmp/poi_index" );
@@ -114,6 +115,7 @@ public void importData(String pbfFilePath, String dataDir) throws Exception {
114115 cleanupDatabase (gridIndexDbPath );
115116 cleanupDatabase (nodeCacheDbPath );
116117 cleanupDatabase (wayIndexDbPath );
118+ cleanupDatabase (boundaryWayIndexDbPath );
117119 cleanupDatabase (neededNodesDbPath );
118120 cleanupDatabase (relIndexDbPath );
119121 cleanupDatabase (poiIndexDbPath );
@@ -185,6 +187,7 @@ public void importData(String pbfFilePath, String dataDir) throws Exception {
185187 RocksDB gridIndexDb = RocksDB .open (gridOpts , gridIndexDbPath .toString ());
186188 RocksDB nodeCache = RocksDB .open (nodeOpts , nodeCacheDbPath .toString ());
187189 RocksDB wayIndexDb = RocksDB .open (wayIndexOpts , wayIndexDbPath .toString ());
190+ RocksDB neededBoundaryWaysDb = RocksDB .open (wayIndexOpts , boundaryWayIndexDbPath .toString ());
188191 RocksDB neededNodesDb = RocksDB .open (neededNodesOpts , neededNodesDbPath .toString ());
189192 RocksDB relIndexDb = RocksDB .open (wayIndexOpts , relIndexDbPath .toString ());
190193 RocksDB poiIndexDb = RocksDB .open (poiIndexOpts , poiIndexDbPath .toString ());
@@ -194,21 +197,23 @@ public void importData(String pbfFilePath, String dataDir) throws Exception {
194197 stats .printPhaseHeader ("PASS 1: Discovery & Indexing" );
195198 long pass1Start = System .currentTimeMillis ();
196199 stats .setCurrentPhase (1 , "1.1.1: Discovery & Indexing" );
197- pass1DiscoveryAndIndexing (pbfFile , wayIndexDb , neededNodesDb , relIndexDb , poiIndexDb , stats );
200+ pass1DiscoveryAndIndexing (pbfFile , wayIndexDb , neededBoundaryWaysDb , neededNodesDb , relIndexDb , poiIndexDb , stats );
201+ stats .setCurrentPhase (2 , "1.1.2: Indexing boundary member ways" );
202+ indexBoundaryMemberWays (pbfFile , neededBoundaryWaysDb , wayIndexDb , neededNodesDb , stats );
198203 stats .printPhaseSummary ("PASS 1" , pass1Start );
199204
200205 // PASS 2: Nodes Cache, Boundaries, POIs
201206 stats .printPhaseHeader ("PASS 2: Nodes Cache, Boundaries, POIs" );
202207 long pass2Start = System .currentTimeMillis ();
203- stats .setCurrentPhase (2 , "1.1.2 : Caching node coordinates" );
208+ stats .setCurrentPhase (3 , "1.1.3 : Caching node coordinates" );
204209 cacheNeededNodeCoordinates (pbfFile , neededNodesDb , nodeCache , stats );
205210
206- stats .setCurrentPhase (3 , "1.2: Processing administrative boundaries" );
211+ stats .setCurrentPhase (4 , "1.2: Processing administrative boundaries" );
207212 processAdministrativeBoundariesFromIndex (relIndexDb , nodeCache , wayIndexDb , gridIndexDb , boundariesDb , stats );
208- stats .setCurrentPhase (4 , "2.1: Processing POIs & Sharding" );
213+ stats .setCurrentPhase (5 , "2.1: Processing POIs & Sharding" );
209214 pass2PoiShardingFromIndex (nodeCache , wayIndexDb , appendDb , boundariesDb , poiIndexDb , gridIndexDb , stats );
210215
211- stats .setCurrentPhase (5 , "2.2: Compacting POIs" );
216+ stats .setCurrentPhase (6 , "2.2: Compacting POIs" );
212217 compactShards (appendDb , shardsDb , stats );
213218 stats .stop ();
214219 stats .printPhaseSummary ("PASS 2" , pass2Start );
@@ -226,6 +231,7 @@ public void importData(String pbfFilePath, String dataDir) throws Exception {
226231 gridIndexDbPath ,
227232 nodeCacheDbPath ,
228233 wayIndexDbPath ,
234+ boundaryWayIndexDbPath ,
229235 neededNodesDbPath ,
230236 relIndexDbPath ,
231237 poiIndexDbPath ,
@@ -264,6 +270,43 @@ private void writeMetadataFile(Path pbfFile, Path dataDirectory) throws IOExcept
264270 System .out .println ("\n \033 [1;32mMetadata file written to: " + metadataPath + "\033 [0m" );
265271 }
266272
273+ private void indexBoundaryMemberWays (Path pbfFile ,
274+ RocksDB neededBoundaryWaysDb ,
275+ RocksDB wayIndexDb ,
276+ RocksDB neededNodesDb ,
277+ ImportStatistics stats ) throws Exception {
278+ final byte [] ONE = new byte []{1 };
279+ try (RocksBatchWriter wayWriter = new RocksBatchWriter (wayIndexDb , 10_000 , stats );
280+ RocksBatchWriter neededWriter = new RocksBatchWriter (neededNodesDb , 500_000 , stats )) {
281+
282+ withPbfIterator (pbfFile , iterator -> {
283+
284+ while (iterator .hasNext ()) {
285+ EntityContainer container = iterator .next ();
286+ if (container .getType () != EntityType .Way ) continue ;
287+
288+ OsmWay way = (OsmWay ) container .getEntity ();
289+ byte [] wayKey = s2Helper .longToByteArray (way .getId ());
290+
291+ // Only process ways that are needed AND not already indexed
292+ if (neededBoundaryWaysDb .get (wayKey ) == null ) continue ;
293+ if (wayIndexDb .get (wayKey ) != null ) { continue ; }
294+ int n = way .getNumberOfNodes ();
295+ long [] nodeIds = new long [n ];
296+ for (int j = 0 ; j < n ; j ++) {
297+ long nid = way .getNodeId (j );
298+ nodeIds [j ] = nid ;
299+ neededWriter .put (s2Helper .longToByteArray (nid ), ONE );
300+ }
301+ wayWriter .put (wayKey , s2Helper .longArrayToByteArray (nodeIds ));
302+ stats .incrementWaysProcessed ();
303+ }
304+ });
305+
306+ wayWriter .flush ();
307+ neededWriter .flush ();
308+ }
309+ }
267310
268311 private void updateGridIndexEntry (RocksDB gridIndexDb , long cellId , long osmId ) throws Exception {
269312 byte [] key = s2Helper .longToByteArray (cellId );
@@ -282,10 +325,11 @@ private void updateGridIndexEntry(RocksDB gridIndexDb, long cellId, long osmId)
282325 }
283326 }
284327
285- private void pass1DiscoveryAndIndexing (Path pbfFile , RocksDB wayIndexDb , RocksDB neededNodesDb , RocksDB relIndexDb , RocksDB poiIndexDb , ImportStatistics stats ) throws Exception {
328+ private void pass1DiscoveryAndIndexing (Path pbfFile , RocksDB wayIndexDb , RocksDB boundaryWayIndexDb , RocksDB neededNodesDb , RocksDB relIndexDb , RocksDB poiIndexDb , ImportStatistics stats ) throws Exception {
286329
287330 final byte [] ONE = new byte []{1 };
288331 try (RocksBatchWriter wayWriter = new RocksBatchWriter (wayIndexDb , 10_000 , stats );
332+ RocksBatchWriter boundaryWayWriter = new RocksBatchWriter (boundaryWayIndexDb , 10_000 , stats );
289333 RocksBatchWriter neededWriter = new RocksBatchWriter (neededNodesDb , 500_000 , stats );
290334 RocksBatchWriter relWriter = new RocksBatchWriter (relIndexDb , 2_000 , stats );
291335 RocksBatchWriter poiWriter = new RocksBatchWriter (poiIndexDb , 20_000 , stats )) {
@@ -336,6 +380,13 @@ private void pass1DiscoveryAndIndexing(Path pbfFile, RocksDB wayIndexDb, RocksDB
336380 stats .incrementRelationsFound ();
337381 RelRec rec = buildRelRec (relation );
338382 relWriter .put (s2Helper .longToByteArray (relation .getId ()), encodeRelRec (rec ));
383+ for (long wid : rec .outer ) {
384+ boundaryWayWriter .put (s2Helper .longToByteArray (wid ), ONE );
385+ }
386+ for (long wid : rec .inner ) {
387+ boundaryWayWriter .put (s2Helper .longToByteArray (wid ), ONE );
388+ }
389+
339390 }
340391 }
341392 } catch (Exception e ) {
@@ -1447,19 +1498,30 @@ private long computeDirectorySize(Path root) {
14471498 }
14481499 }
14491500
1450- private void recordSizeMetrics (ImportStatistics stats , Path shardsDbPath , Path boundariesDbPath , Path gridIndexDbPath , Path nodeCacheDbPath , Path wayIndexDbPath , Path neededNodesDbPath , Path relIndexDbPath , Path poiIndexDbPath , Path appendDbPath ) {
1501+ private void recordSizeMetrics (ImportStatistics stats ,
1502+ Path shardsDbPath ,
1503+ Path boundariesDbPath ,
1504+ Path gridIndexDbPath ,
1505+ Path nodeCacheDbPath ,
1506+ Path wayIndexDbPath ,
1507+ Path boundaryWayIndexDbPath ,
1508+ Path neededNodesDbPath ,
1509+ Path relIndexDbPath ,
1510+ Path poiIndexDbPath ,
1511+ Path appendDbPath ) {
14511512 long shards = computeDirectorySize (shardsDbPath );
14521513 long boundaries = computeDirectorySize (boundariesDbPath );
14531514 long dataset = shards + boundaries ;
14541515
14551516 long grid = computeDirectorySize (gridIndexDbPath );
14561517 long node = computeDirectorySize (nodeCacheDbPath );
14571518 long way = computeDirectorySize (wayIndexDbPath );
1519+ long boundaryWay = computeDirectorySize (boundaryWayIndexDbPath );
14581520 long needed = computeDirectorySize (neededNodesDbPath );
14591521 long rel = computeDirectorySize (relIndexDbPath );
14601522 long poi = computeDirectorySize (poiIndexDbPath );
14611523 long append = computeDirectorySize (appendDbPath );
1462- long tmpTotal = grid + node + way + needed + rel + poi + append ;
1524+ long tmpTotal = grid + node + way + boundaryWay + needed + rel + poi + append ;
14631525
14641526 stats .setShardsBytes (shards );
14651527 stats .setBoundariesBytes (boundaries );
@@ -1468,6 +1530,7 @@ private void recordSizeMetrics(ImportStatistics stats, Path shardsDbPath, Path b
14681530 stats .setTmpGridBytes (grid );
14691531 stats .setTmpNodeBytes (node );
14701532 stats .setTmpWayBytes (way );
1533+ stats .setTmpBoundaryWayBytes (boundaryWay );
14711534 stats .setTmpNeededBytes (needed );
14721535 stats .setTmpRelBytes (rel );
14731536 stats .setTmpPoiBytes (poi );
0 commit comments