Search in sources :

Example 1 with LengthIndexedLine

use of com.vividsolutions.jts.linearref.LengthIndexedLine in project OpenTripPlanner by opentripplanner.

the class SIsochrone method getSubLineString.

/**
 * Extraction of a sub-LineString from an existing line, starting from 0;
 *
 * @param ls the line from which we extract the sub LineString ()
 * @param fraction [0..1], the length until where we want the substring to go
 * @return the sub-LineString
 */
LineString getSubLineString(LineString ls, double fraction) {
    if (fraction >= 1)
        return ls;
    LengthIndexedLine linRefLine = new LengthIndexedLine(ls);
    LineString subLine = (LineString) linRefLine.extractLine(0, fraction * ls.getLength());
    return subLine;
}
Also used : LengthIndexedLine(com.vividsolutions.jts.linearref.LengthIndexedLine)

Example 2 with LengthIndexedLine

use of com.vividsolutions.jts.linearref.LengthIndexedLine 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 3 with LengthIndexedLine

use of com.vividsolutions.jts.linearref.LengthIndexedLine in project OpenTripPlanner by opentripplanner.

the class OtpsIndividual method getSnappedLocation.

/**
 * @return The snapped location of the individual on the graph (ie a point on the nearest
 *         walkable/drivable street). This can be useful to output a more precise location for a
 *         generated grid point, as the returned location is the effective one used for
 *         path/time computations. Return NULL if the individual has never been evualuated (by a
 *         call to OtpsSPT.eval). Return the original location if the point can't be snapped
 *         (too far away from a street).
 */
public OtpsLatLon getSnappedLocation() {
    if (cachedSample == null)
        return null;
    // Maybe the Sample should store the snapped location itself
    for (Edge e : cachedSample.v0.getOutgoingStreetEdges()) {
        if (e.getToVertex().equals(cachedSample.v1) && e.getGeometry() != null) {
            LineString geom = e.getGeometry();
            LengthIndexedLine liline = new LengthIndexedLine(geom);
            int d = cachedSample.d0 + cachedSample.d1;
            double k = d == 0 ? 0.0 : 1.0 * cachedSample.d0 / d;
            double x = liline.getStartIndex() + (liline.getEndIndex() - liline.getStartIndex()) * k;
            Coordinate p = liline.extractPoint(x);
            return new OtpsLatLon(p.y, p.x);
        }
    }
    return getLocation();
}
Also used : LineString(com.vividsolutions.jts.geom.LineString) LengthIndexedLine(com.vividsolutions.jts.linearref.LengthIndexedLine) Coordinate(com.vividsolutions.jts.geom.Coordinate) Edge(org.opentripplanner.routing.graph.Edge)

Example 4 with LengthIndexedLine

use of com.vividsolutions.jts.linearref.LengthIndexedLine in project UVMS-ActivityModule-APP by UnionVMS.

the class FluxMessageServiceBean method calculateIntermediatePoint.

private Geometry calculateIntermediatePoint(MovementType previousMovement, MovementType nextMovement, Date acceptedDate) throws ServiceException {
    Geometry point;
    Long durationAB = nextMovement.getPositionTime().getTime() - previousMovement.getPositionTime().getTime();
    Long durationAC = acceptedDate.getTime() - previousMovement.getPositionTime().getTime();
    Long durationBC = nextMovement.getPositionTime().getTime() - acceptedDate.getTime();
    try {
        if (durationAC == 0) {
            log.info("The point is same as the start point");
            point = GeometryMapper.INSTANCE.wktToGeometry(previousMovement.getWkt()).getValue();
        } else if (durationBC == 0) {
            log.info("The point is the same as end point");
            point = GeometryMapper.INSTANCE.wktToGeometry(nextMovement.getWkt()).getValue();
        } else {
            log.info("The point is between start and end point");
            LengthIndexedLine lengthIndexedLine = GeometryUtils.createLengthIndexedLine(previousMovement.getWkt(), nextMovement.getWkt());
            Double index = durationAC * (lengthIndexedLine.getEndIndex() - lengthIndexedLine.getStartIndex()) / durationAB;
            point = GeometryUtils.calculateIntersectingPoint(lengthIndexedLine, index);
        }
    } catch (ParseException e) {
        throw new ServiceException(e.getMessage(), e);
    }
    point.setSRID(dialect.defaultSRID());
    return point;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) LengthIndexedLine(com.vividsolutions.jts.linearref.LengthIndexedLine) ParseException(com.vividsolutions.jts.io.ParseException)

Aggregations

LengthIndexedLine (com.vividsolutions.jts.linearref.LengthIndexedLine)4 Node (com.conveyal.osmlib.Node)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 LineString (com.vividsolutions.jts.geom.LineString)1 ParseException (com.vividsolutions.jts.io.ParseException)1 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)1 SpatialDataItem (io.opentraffic.engine.data.SpatialDataItem)1 Jumper (io.opentraffic.engine.geom.Jumper)1 StreetSegment (io.opentraffic.engine.geom.StreetSegment)1 TripLine (io.opentraffic.engine.geom.TripLine)1 Edge (org.opentripplanner.routing.graph.Edge)1