Search in sources :

Example 1 with StreetSegment

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

the class StreetDataStore method delete.

@Override
public void delete(SpatialDataItem obj) {
    Tuple3 segmentId = ((StreetSegment) obj).getSegmentId();
    segmentIndex.remove(segmentId);
    super.delete(obj);
}
Also used : StreetSegment(io.opentraffic.engine.geom.StreetSegment) Tuple3(org.mapdb.Fun.Tuple3)

Example 2 with StreetSegment

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

the class StreetDataStore method delete.

@Override
public void delete(List<SpatialDataItem> objs) {
    List<SpatialDataItem> segments = new ArrayList<SpatialDataItem>();
    for (SpatialDataItem obj : objs) {
        Tuple3 segmentId = ((StreetSegment) obj).getSegmentId();
        if (!segmentIndex.containsKey(segmentId))
            continue;
        segments.add(obj);
        segmentIndex.remove(segmentId);
    }
    super.delete(segments);
}
Also used : StreetSegment(io.opentraffic.engine.geom.StreetSegment) Tuple3(org.mapdb.Fun.Tuple3) SpatialDataItem(io.opentraffic.engine.data.SpatialDataItem)

Example 3 with StreetSegment

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

the class StreetDataStore method getSegmentTypeById.

public int getSegmentTypeById(long id) {
    if (!segmentTypeMap.containsKey(id)) {
        StreetSegment segment = (StreetSegment) map.get(id);
        segmentTypeMap.put(id, segment.streetType);
    }
    return segmentTypeMap.get(id);
}
Also used : StreetSegment(io.opentraffic.engine.geom.StreetSegment)

Example 4 with StreetSegment

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

the class StreetDataStore method save.

@Override
public void save(List<SpatialDataItem> objs) {
    List<SpatialDataItem> segments = new ArrayList<SpatialDataItem>();
    for (SpatialDataItem obj : objs) {
        Tuple3 segmentId = ((StreetSegment) obj).getSegmentId();
        if (segmentIndex.containsKey(segmentId))
            continue;
        segments.add(obj);
        segmentIndex.put(segmentId, obj.id);
    }
    super.save(segments);
}
Also used : StreetSegment(io.opentraffic.engine.geom.StreetSegment) Tuple3(org.mapdb.Fun.Tuple3) SpatialDataItem(io.opentraffic.engine.data.SpatialDataItem)

Example 5 with StreetSegment

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

the class OSMDataStore method getStreetSegments.

/**
 * Chop up given OSM into segments at tripengine's tripline clusters.
 *
 * @param osm	an osm object
 * @return	a list of street segments
 */
private List<StreetSegment> getStreetSegments(OSM osm) {
    GeometryFactory gf = new GeometryFactory();
    Set<Long> intersectionNodes = findIntersections(osm);
    List<StreetSegment> newSegments = new ArrayList<>();
    for (Entry<Long, Way> entry : osm.ways.entrySet()) {
        Long wayId = entry.getKey();
        Way way = entry.getValue();
        // only find segments for traffic edges
        if (!StreetSegment.isTrafficEdge(way))
            continue;
        LineString wayLineString;
        try {
            wayLineString = OSMUtils.getLineStringForWay(way, osm);
        } catch (RuntimeException ex) {
            continue;
        }
        double segmentDist = 0;
        Long lastNodeId = null;
        Point lastPoint = null;
        List<Coordinate> segmentCords = new ArrayList<>();
        for (int i = 0; i < way.nodes.length; i++) {
            Long nodeId = way.nodes[i];
            if (lastNodeId == null)
                lastNodeId = nodeId;
            // get the linear reference of this node along the way
            Point point = wayLineString.getPointN(i);
            if (lastPoint != null)
                segmentDist += getDistance(lastPoint.getX(), lastPoint.getY(), point.getX(), point.getY());
            lastPoint = point;
            segmentCords.add(point.getCoordinate());
            // check to see if segment completes the line or is an intersection pair
            if (segmentCords.size() > 1 && (intersectionNodes.contains(nodeId) || i == (way.nodes.length - 1))) {
                // make segment
                Coordinate[] segmentCoordArray = new Coordinate[segmentCords.size()];
                LineString segmentGeometry = gf.createLineString(segmentCords.toArray(segmentCoordArray));
                StreetSegment streetSegment = new StreetSegment(this.streetSegments.getNextId(), way, wayId, lastNodeId, nodeId, segmentGeometry, segmentDist);
                newSegments.add(streetSegment);
                // create reverse
                if (!streetSegment.oneway) {
                    LineString reverseSegmentGeometry = (LineString) segmentGeometry.reverse();
                    newSegments.add(new StreetSegment(this.streetSegments.getNextId(), way, wayId, nodeId, lastNodeId, reverseSegmentGeometry, segmentDist));
                }
                // reset for next segment
                segmentCords = new ArrayList<>();
                segmentCords.add(point.getCoordinate());
                segmentDist = 0;
                lastNodeId = nodeId;
            }
        }
    }
    return newSegments;
}
Also used : StreetSegment(io.opentraffic.engine.geom.StreetSegment) Way(com.conveyal.osmlib.Way)

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