20
20
import static com .graphhopper .util .Helper .nf ;
21
21
import gnu .trove .list .TLongList ;
22
22
import gnu .trove .list .array .TLongArrayList ;
23
+ import gnu .trove .map .TIntLongMap ;
23
24
import gnu .trove .map .TLongLongMap ;
25
+ import gnu .trove .map .hash .TIntLongHashMap ;
24
26
import gnu .trove .map .hash .TLongLongHashMap ;
27
+ import gnu .trove .set .TLongSet ;
28
+ import gnu .trove .set .hash .TLongHashSet ;
25
29
26
30
import java .io .File ;
27
31
import java .io .IOException ;
44
48
import com .graphhopper .storage .GraphHopperStorage ;
45
49
import com .graphhopper .storage .GraphStorage ;
46
50
import com .graphhopper .storage .TurnCostStorage ;
47
- import com .graphhopper .util .BitUtil ;
48
51
import com .graphhopper .util .DistanceCalc ;
49
52
import com .graphhopper .util .DistanceCalcEarth ;
50
53
import com .graphhopper .util .DouglasPeucker ;
@@ -106,20 +109,21 @@ public class OSMReader
106
109
private LongIntMap osmNodeIdToInternalNodeMap ;
107
110
private TLongLongHashMap osmNodeIdToNodeFlagsMap ;
108
111
private TLongLongHashMap osmWayIdToRouteWeightMap ;
112
+ private TLongHashSet osmIdStoreRequiredSet ; //stores osm ids used by relations to identify which edge ids needs to be mapped later
113
+ private TIntLongMap edgeIdToOsmidMap ;
109
114
private final TLongList barrierNodeIDs = new TLongArrayList ();
110
115
protected DataAccess pillarLats ;
111
116
protected DataAccess pillarLons ;
112
- protected DataAccess edgeOsmIds ;
113
117
private final DistanceCalc distCalc = new DistanceCalcEarth ();
114
118
private final DouglasPeucker simplifyAlgo = new DouglasPeucker ();
115
119
private int nextTowerId = 0 ;
116
120
private int nextPillarId = 0 ;
117
121
// negative but increasing to avoid clash with custom created OSM files
118
122
private long newUniqueOSMId = -Long .MAX_VALUE ;
119
123
private boolean exitOnlyPillarNodeException = true ;
124
+
120
125
//relation factory specifies an arbitrary osm relation
121
126
private OSMRelationFactory relationFactory = new OSMRelationFactory ();
122
- private final BitUtil bitUtil ;
123
127
124
128
public OSMReader ( GraphStorage storage , long expectedCap )
125
129
{
@@ -133,13 +137,10 @@ public OSMReader( GraphStorage storage, long expectedCap )
133
137
dir = graphStorage .getDirectory ();
134
138
pillarLats = dir .find ("tmpLatitudes" );
135
139
pillarLons = dir .find ("tmpLongitudes" );
136
- edgeOsmIds = dir .find ("tmpEdgeOsmIds" );
137
140
pillarLats .create (Math .max (expectedCap , 100 ));
138
141
pillarLons .create (Math .max (expectedCap , 100 ));
139
- edgeOsmIds .create (Math .max (expectedCap , 100 ));
140
142
141
143
relationFactory = new OSMRelationFactory ();
142
- bitUtil = BitUtil .get (dir .getByteOrder ());
143
144
}
144
145
145
146
public void doOSM2Graph ( File osmFile ) throws IOException
@@ -203,6 +204,11 @@ void preProcess( File osmFile )
203
204
prepareWaysWithRelationInfo (relation );
204
205
}
205
206
207
+ if (relation .hasTag ("type" , "restriction" ))
208
+ {
209
+ prepareRestrictionRelation (relation );
210
+ }
211
+
206
212
if (++tmpRelationCounter % 50000 == 0 )
207
213
{
208
214
logger .info (nf (tmpRelationCounter ) + " (preprocess), osmWayMap:" + nf (getRelFlagsMap ().size ())
@@ -220,6 +226,34 @@ void preProcess( File osmFile )
220
226
}
221
227
}
222
228
229
+ private void prepareRestrictionRelation ( OSMRelation relation )
230
+ {
231
+ OSMRelation specifiedRelation = relationFactory .specify (relation );
232
+ if (specifiedRelation != null && specifiedRelation instanceof OSMTurnRelation )
233
+ {
234
+ getOsmIdStoreRequiredSet ().add (((OSMTurnRelation ) specifiedRelation ).getOsmIdFrom ());
235
+ getOsmIdStoreRequiredSet ().add (((OSMTurnRelation ) specifiedRelation ).getOsmIdTo ());
236
+ }
237
+ }
238
+
239
+ private TLongSet getOsmIdStoreRequiredSet ()
240
+ {
241
+ if (osmIdStoreRequiredSet == null )
242
+ {
243
+ osmIdStoreRequiredSet = new TLongHashSet ();
244
+ }
245
+ return osmIdStoreRequiredSet ;
246
+ }
247
+
248
+ private TIntLongMap getEdgeIdToOsmidMap ()
249
+ {
250
+ if (edgeIdToOsmidMap == null )
251
+ {
252
+ edgeIdToOsmidMap = new TIntLongHashMap (getOsmIdStoreRequiredSet ().size ());
253
+ }
254
+ return edgeIdToOsmidMap ;
255
+ }
256
+
223
257
/**
224
258
* Filter ways but do not analyze properties wayNodes will be filled with participating node
225
259
* ids.
@@ -453,9 +487,7 @@ public void processRelation( OSMRelation relation ) throws XMLStreamException
453
487
454
488
public long getOsmIdOfInternalEdge ( int edgeId )
455
489
{
456
- byte [] bytesOsmWayId = new byte [8 ];
457
- edgeOsmIds .getBytes (edgeId * 8 , bytesOsmWayId , 8 );
458
- return bitUtil .toLong (bytesOsmWayId );
490
+ return getEdgeIdToOsmidMap ().get (edgeId );
459
491
}
460
492
461
493
public int getInternalNodeIdOfOsmNode ( long nodeOsmId )
@@ -735,9 +767,10 @@ EdgeIteratorState addEdge( int fromIndex, int toIndex, PointList pointList, long
735
767
736
768
private void storeOSMWayID ( int edgeId , long osmWayID )
737
769
{
738
- long ptr = (long ) edgeId * 8 ;
739
- edgeOsmIds .incCapacity (ptr + 8 );
740
- edgeOsmIds .setBytes (ptr , bitUtil .fromLong (osmWayID ), 8 );
770
+ if (getOsmIdStoreRequiredSet ().contains (osmWayID ))
771
+ {
772
+ getEdgeIdToOsmidMap ().put (edgeId , osmWayID );
773
+ }
741
774
}
742
775
743
776
/**
@@ -776,10 +809,8 @@ void finishedReading()
776
809
printInfo ("way" );
777
810
dir .remove (pillarLats );
778
811
dir .remove (pillarLons );
779
- dir .remove (edgeOsmIds );
780
812
pillarLons = null ;
781
813
pillarLats = null ;
782
- edgeOsmIds = null ;
783
814
osmNodeIdToInternalNodeMap = null ;
784
815
osmNodeIdToNodeFlagsMap = null ;
785
816
osmWayIdToRouteWeightMap = null ;
0 commit comments