Search in sources :

Example 6 with StreetSegment

use of io.opentraffic.engine.geom.StreetSegment in project traffic-engine by opentraffic.

the class StreetDataStore method save.

public void save(SpatialDataItem obj) {
    Tuple3 segmentId = ((StreetSegment) obj).getSegmentId();
    if (segmentIndex.containsKey(segmentId))
        return;
    segmentIndex.put(segmentId, obj.id);
    super.save(obj);
}
Also used : StreetSegment(io.opentraffic.engine.geom.StreetSegment) Tuple3(org.mapdb.Fun.Tuple3)

Example 7 with StreetSegment

use of io.opentraffic.engine.geom.StreetSegment in project traffic-engine by opentraffic.

the class OSMDataStore method addOsm.

private OSMArea addOsm(Fun.Tuple2<Integer, Integer> tile, Envelope env, OSM osm, Boolean keepCompleteGeometries) {
    String placeName = null;
    Long placePop = null;
    for (Entry<Long, Node> entry : osm.nodes.entrySet()) {
        Long id = entry.getKey();
        Node node = entry.getValue();
        if (id == 259009337) {
            try {
                long pop = Long.parseLong(node.getTag("population"));
                if (placePop == null || placePop < pop) {
                    placePop = pop;
                    placeName = node.getTag("name");
                }
            } catch (Exception e) {
            }
        }
    }
    List<StreetSegment> segments = getStreetSegments(osm);
    List<SpatialDataItem> segmentItems = new ArrayList<>();
    List<SpatialDataItem> triplineItems = new ArrayList<>();
    for (StreetSegment segment : segments) {
        if (streetSegments.contains(segment.getSegmentId()))
            continue;
        if (segment.length > MIN_SEGMENT_LEN) {
            LengthIndexedLine lengthIndexedLine = new LengthIndexedLine(segment.getGeometry());
            double scale = (lengthIndexedLine.getEndIndex() - lengthIndexedLine.getStartIndex()) / segment.length;
            List<TripLine> tripLines = new ArrayList<TripLine>();
            tripLines.add(createTripLine(segment, 1, lengthIndexedLine, (OSMDataStore.INTERSECTION_MARGIN_METERS) * scale, OSMDataStore.INTERSECTION_MARGIN_METERS));
            tripLines.add(createTripLine(segment, 2, lengthIndexedLine, ((segment.length - OSMDataStore.INTERSECTION_MARGIN_METERS) * scale), segment.length - OSMDataStore.INTERSECTION_MARGIN_METERS));
            for (TripLine tripLine : tripLines) {
                triplineItems.add(tripLine);
            }
        } else {
            jumperDataStore.addJumper(new Jumper(segment));
        }
        if (!keepCompleteGeometries)
            segment.truncateGeometry();
        segmentItems.add(segment);
    }
    streetSegments.save(segmentItems);
    jumperDataStore.save();
    triplines.save(triplineItems);
    long zoneOffset = timeZoneConverter.getOffsetForCoord(env.centre());
    OSMArea osmArea = new OSMArea(osmAreaIds.getNextId(), tile.a, tile.b, Z_INDEX, placeName, placePop, zoneOffset, env);
    osmAreas.put(tile, osmArea);
    db.commit();
    System.out.println("Loaded OSM " + tile.a + ", " + tile.b);
    if (placeName != null)
        System.out.println("\t" + placeName + ", " + placePop);
    return osmArea;
}
Also used : StreetSegment(io.opentraffic.engine.geom.StreetSegment) Node(com.conveyal.osmlib.Node) SpatialDataItem(io.opentraffic.engine.data.SpatialDataItem) Jumper(io.opentraffic.engine.geom.Jumper) LengthIndexedLine(com.vividsolutions.jts.linearref.LengthIndexedLine) TripLine(io.opentraffic.engine.geom.TripLine)

Example 8 with StreetSegment

use of io.opentraffic.engine.geom.StreetSegment in project traffic-engine by opentraffic.

the class StreetSegmentSerializer method deserialize.

@Override
public StreetSegment deserialize(DataInput in, int available) throws IOException {
    long id = in.readLong();
    int geomSize = in.readInt();
    Coordinate[] coords = new Coordinate[geomSize];
    for (int i = 0; i < geomSize; i++) {
        coords[i] = new Coordinate(in.readDouble(), in.readDouble());
    }
    int streetType = in.readInt();
    boolean oneway = in.readBoolean();
    long wayId = in.readLong();
    long startNodeId = in.readLong();
    long endNodeId = in.readLong();
    double length = in.readDouble();
    StreetSegment item = new StreetSegment(id, streetType, oneway, wayId, startNodeId, endNodeId, coords, length);
    return item;
}
Also used : StreetSegment(io.opentraffic.engine.geom.StreetSegment) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Aggregations

StreetSegment (io.opentraffic.engine.geom.StreetSegment)8 Tuple3 (org.mapdb.Fun.Tuple3)4 SpatialDataItem (io.opentraffic.engine.data.SpatialDataItem)3 Node (com.conveyal.osmlib.Node)1 Way (com.conveyal.osmlib.Way)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 LengthIndexedLine (com.vividsolutions.jts.linearref.LengthIndexedLine)1 Jumper (io.opentraffic.engine.geom.Jumper)1 TripLine (io.opentraffic.engine.geom.TripLine)1