Search in sources :

Example 1 with LongIndexedContainer

use of com.carrotsearch.hppc.LongIndexedContainer in project graphhopper by graphhopper.

the class OSMReader method preProcess.

/**
     * Preprocessing of OSM file to select nodes which are used for highways. This allows a more
     * compact graph data structure.
     */
void preProcess(File osmFile) {
    OSMInputFile in = null;
    try {
        in = new OSMInputFile(osmFile).setWorkerThreads(workerThreads).open();
        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);
    } finally {
        Helper.close(in);
    }
}
Also used : LongIndexedContainer(com.carrotsearch.hppc.LongIndexedContainer) GHPoint(com.graphhopper.util.shapes.GHPoint) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException)

Example 2 with LongIndexedContainer

use of com.carrotsearch.hppc.LongIndexedContainer in project graphhopper by graphhopper.

the class PbfBlobDecoder method processWays.

private void processWays(List<Osmformat.Way> ways, PbfFieldDecoder fieldDecoder) {
    for (Osmformat.Way way : ways) {
        Map<String, String> tags = buildTags(way.getKeysList(), way.getValsList(), fieldDecoder);
        ReaderWay osmWay = new ReaderWay(way.getId());
        osmWay.setTags(tags);
        // Build up the list of way nodes for the way. The node ids are
        // delta encoded meaning that each id is stored as a delta against
        // the previous one.
        long nodeId = 0;
        LongIndexedContainer wayNodes = osmWay.getNodes();
        for (long nodeIdOffset : way.getRefsList()) {
            nodeId += nodeIdOffset;
            wayNodes.add(nodeId);
        }
        decodedEntities.add(osmWay);
    }
}
Also used : LongIndexedContainer(com.carrotsearch.hppc.LongIndexedContainer) ReaderWay(com.graphhopper.reader.ReaderWay) Osmformat(org.openstreetmap.osmosis.osmbinary.Osmformat)

Example 3 with LongIndexedContainer

use of com.carrotsearch.hppc.LongIndexedContainer in project graphhopper by graphhopper.

the class OSMReaderTest method testEstimatedCenter.

@Test
public void testEstimatedCenter() {
    final CarFlagEncoder encoder = new CarFlagEncoder() {

        private EncodedValue objectEncoder;

        @Override
        public int defineNodeBits(int index, int shift) {
            shift = super.defineNodeBits(index, shift);
            objectEncoder = new EncodedValue("oEnc", shift, 2, 1, 0, 3, true);
            return shift + 2;
        }

        @Override
        public long handleNodeTags(ReaderNode node) {
            if (node.hasTag("test", "now"))
                return -objectEncoder.setValue(0, 1);
            return 0;
        }
    };
    EncodingManager manager = new EncodingManager(encoder);
    GraphHopperStorage ghStorage = newGraph(dir, manager, false, false);
    final Map<Integer, Double> latMap = new HashMap<Integer, Double>();
    final Map<Integer, Double> lonMap = new HashMap<Integer, Double>();
    latMap.put(1, 1.1d);
    latMap.put(2, 1.2d);
    lonMap.put(1, 1.0d);
    lonMap.put(2, 1.0d);
    OSMReader osmreader = new OSMReader(ghStorage) {

        // mock data access
        @Override
        double getTmpLatitude(int id) {
            return latMap.get(id);
        }

        @Override
        double getTmpLongitude(int id) {
            return lonMap.get(id);
        }

        @Override
        Collection<EdgeIteratorState> addOSMWay(LongIndexedContainer osmNodeIds, long wayFlags, long osmId) {
            return Collections.emptyList();
        }
    };
    // save some node tags for first node
    ReaderNode osmNode = new ReaderNode(1, 1.1d, 1.0d);
    osmNode.setTag("test", "now");
    osmreader.getNodeFlagsMap().put(1, encoder.handleNodeTags(osmNode));
    ReaderWay way = new ReaderWay(1L);
    way.getNodes().add(1);
    way.getNodes().add(2);
    way.setTag("highway", "motorway");
    osmreader.getNodeMap().put(1, 1);
    osmreader.getNodeMap().put(2, 2);
    osmreader.processWay(way);
    GHPoint p = way.getTag("estimated_center", null);
    assertEquals(1.15, p.lat, 1e-3);
    assertEquals(1.0, p.lon, 1e-3);
    Double d = way.getTag("estimated_distance", null);
    assertEquals(11119.5, d, 1e-1);
}
Also used : LongIndexedContainer(com.carrotsearch.hppc.LongIndexedContainer) ReaderNode(com.graphhopper.reader.ReaderNode) ReaderWay(com.graphhopper.reader.ReaderWay) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Aggregations

LongIndexedContainer (com.carrotsearch.hppc.LongIndexedContainer)3 ReaderWay (com.graphhopper.reader.ReaderWay)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 ReaderNode (com.graphhopper.reader.ReaderNode)1 IOException (java.io.IOException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Test (org.junit.Test)1 Osmformat (org.openstreetmap.osmosis.osmbinary.Osmformat)1