/** * @return The length of this item */ public Distance length() { return asPolyLine().length(); }
@Override protected double getValue(final T item) { return item.asPolyLine().length().asKilometers(); } }
/** * Gets the length of the item to count * * @param item * The item to count * @return The length of the item to count. In case this is a {@link Relation}, the length is * the sum of all the relation's lowest order {@link LineItem}s. */ private Distance getDistance(final AtlasEntity item) { Distance result = Distance.ZERO; if (item instanceof LineItem) { return ((LineItem) item).asPolyLine().length(); } else if (item instanceof Relation) { for (final RelationMember member : ((Relation) item).members()) { result = result.add(getDistance(member.getEntity())); } } return result; }
|| edgeInBounds.asPolyLine().length().equals(ZERO_DISTANCE) || this.isFlagged(edgeInBounds.getIdentifier()) || edge.getIdentifier() == edgeInBounds.getIdentifier()) final PolyLine longerEdge = (edgePoly.length().isGreaterThan(edgeInBoundsPoly.length())) ? edgePoly : edgeInBoundsPoly; final PolyLine subsetEdge = (longerEdge == edgePoly) ? edgeInBoundsPoly : edgePoly;
/** * Get the offset from the start of the node's location * * @param node * The location to test * @param occurrenceIndex * In case of a self intersecting polyline (one or more locations appear more than * once), indicate the index at which this method should return the location. 0 would * be first occurrence, 1 second, etc. * @return The offset ratio from the start of the {@link PolyLine} */ public Ratio offsetFromStart(final Location node, final int occurrenceIndex) { final Distance max = this.length(); Distance candidate = Distance.ZERO; Location previous = this.first(); int index = 0; for (final Location location : this) { candidate = candidate.add(previous.distanceTo(location)); if (location.equals(node) && occurrenceIndex == index++) { return Ratio.ratio(candidate.asMeters() / max.asMeters()); } previous = location; } throw new CoreException("The location {} is not a node of the PolyLine", node); }
public Location offsetFromStart(final Ratio ratio) { final Distance length = length(); final Distance stop = length.scaleBy(ratio); Distance accumulated = Distance.ZERO; final List<Segment> segments = this.segments(); for (final Segment segment : segments) { if (accumulated.add(segment.length()).isGreaterThan(stop)) { // This is the proper segment final Ratio segmentRatio = Ratio.ratio( stop.substract(accumulated).asMeters() / segment.length().asMeters()); return segment.offsetFromStart(segmentRatio); } if (accumulated.add(segment.length()).equals(stop)) { return segment.end(); } accumulated = accumulated.add(segment.length()); } throw new CoreException("This exception should never be thrown."); }
Assert.assertEquals(POLY_LINE.length().asKilometers(), atlasStatistics.get("secondary", "length_roads_named", "true").getCount(), 0.01); Assert.assertEquals(POLY_LINE.length().asKilometers(), atlasStatistics.get(Coverage.AGGREGATE_KEY, "length_total", "true").getCount(), 0.01); Assert.assertEquals(2 * POLY_LINE.length().asKilometers(), atlasStatistics.get(Coverage.NULL_KEY, "river_length", "true").getCount(), 0.01); Assert.assertEquals(POLY_LINE.length().asKilometers(), atlasStatistics.get(Coverage.NULL_KEY, "rail_length", "true").getCount(), 0.01); Assert.assertEquals(2 * POLY_LINE.length().asKilometers(), atlasStatistics.get(Coverage.NULL_KEY, "transit_bus_length", "true").getCount(), 0.01);
Assert.assertEquals(POLY_LINE.length().asKilometers() / 3, atlasStatistics.get("secondary", "length_roads_named", "true").getCount(), 0.01); Assert.assertEquals(POLY_LINE.length().asKilometers() / 3, atlasStatistics.get(Coverage.AGGREGATE_KEY, "length_total", "true").getCount(), 0.01); Assert.assertEquals(2 * POLY_LINE.length().asKilometers() / 3, atlasStatistics.get(Coverage.NULL_KEY, "river_length", "true").getCount(), 0.01); Assert.assertEquals(POLY_LINE.length().asKilometers() / 3, atlasStatistics.get(Coverage.NULL_KEY, "rail_length", "true").getCount(), 0.01); Assert.assertEquals(2 * POLY_LINE.length().asKilometers() / 3, atlasStatistics.get(Coverage.NULL_KEY, "transit_bus_length", "true").getCount(), 0.01);