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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations