void preProcess ( File osmFile ) { try ( OSMInput in = openOsmInputFile ( osmFile ) ) { long tmpWayCounter = 1 ; long tmpRelationCounter = 1 ; ReaderElement item ; while ( ( item = in . getNext ( ) ) != null ) { if ( item . isType ( ReaderElement . WAY ) ) { final ReaderWay way = ( ReaderWay ) item ; boolean valid = filterWay ( way ) ; if ( valid ) { LongIndexedContainer wayNodes = way . getNodes ( ) ; int s = wayNodes . size ( ) ; for ( int index = 0 ; index < s ; index ++ ) { prepareHighwayNode ( wayNodes . get ( index ) ) ; } if ( ++ tmpWayCounter % 10_000_000 == 0 ) { LOGGER . info ( nf ( tmpWayCounter ) + " (preprocess), osmIdMap:" + nf ( getNodeMap ( ) . getSize ( ) ) + " (" + getNodeMap ( ) . getMemoryUsage ( ) + "MB) " + Helper . getMemInfo ( ) ) ; } } } else if ( item . isType ( ReaderElement . RELATION ) ) { final ReaderRelation relation = ( ReaderRelation ) item ; if ( ! relation . isMetaRelation ( ) && relation . hasTag ( "type" , "route" ) ) prepareWaysWithRelationInfo ( relation ) ; if ( relation . hasTag ( "type" , "restriction" ) ) prepareRestrictionRelation ( relation ) ; if ( ++ tmpRelationCounter % 100_000 == 0 ) { LOGGER . info ( nf ( tmpRelationCounter ) + " (preprocess), osmWayMap:" + nf ( getRelFlagsMap ( ) . size ( ) ) + " " + Helper . getMemInfo ( ) ) ; } } else if ( item . isType ( ReaderElement . FILEHEADER ) ) { final OSMFileHeader fileHeader = ( OSMFileHeader ) item ; osmDataDate = Helper . createFormatter ( ) . parse ( fileHeader . getTag ( "timestamp" ) ) ; } } } catch ( Exception ex ) { throw new RuntimeException ( "Problem while parsing file" , ex ) ; } }
Preprocessing of OSM file to select nodes which are used for highways . This allows a more compact graph data structure .