private PolyLine createPolyLineFromRoad(final TemporaryRoad road) { // A set of locations to collect from the road final SortedSet<TemporaryOrderedLocation> temporaryNodeSet = createTemporaryOrderedLocations( road); return new PolyLine(temporaryNodeSet.stream().map(TemporaryOrderedLocation::getLocation) .collect(Collectors.toList())); }
@Override public PolyLine convert(final String object) { final StringList split = StringList.split(object, PolyLine.SEPARATOR); final List<Location> locations = new ArrayList<>(); for (final String location : split) { locations.add(Location.forString(location)); } return new PolyLine(locations); } }
public PolyLine reversed() { final List<Location> reversed = new ArrayList<>(); for (int i = this.size() - 1; i >= 0; i--) { reversed.add(this.get(i)); } return new PolyLine(reversed); }
@Override public PolyLine deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { final JsonArray coordinates = (JsonArray) ((JsonObject) json).get("coordinates"); return new PolyLine(this.multiCoordinateConverter.revert().convert(coordinates)); } }
@Test(expected = CoreException.class) public void testInvalidPrepend() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1); final PolyLine line2 = new PolyLine(Location.CROSSING_85_280, Location.TEST_7); @SuppressWarnings("unused") final PolyLine prepended = line.prepend(line2); }
@Test public void testPrepend() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1); final PolyLine line2 = new PolyLine(Location.TEST_7, Location.CROSSING_85_280); final PolyLine prepended = line.prepend(line2); Assert.assertTrue(prepended.equalsShape( new PolyLine(Location.TEST_7, Location.CROSSING_85_280, Location.TEST_1))); }
@Test(expected = OpenPolygonException.class) public void testSingleOpenPolyLine() { final List<PolyLine> list = new ArrayList<>(); list.add(new PolyLine(ONE, TWO)); CONVERTER.convert(list); } }
private static void verifyEdge(final Edge edge, final String... locations) { Assert.assertEquals(edge.asPolyLine(), new PolyLine(StreamSupport.stream(Iterables.from(locations).spliterator(), false) .map(Location::forString).collect(Collectors.toList()))); }
@Test public void testMultiLineString() { final List<PolyLine> polyLines = new ArrayList<>(); polyLines.add(new PolyLine(Location.TEST_5, Location.TEST_2)); polyLines.add(new PolyLine(Location.COLOSSEUM, Location.EIFFEL_TOWER)); final GeoJsonObject object = new GeoJsonBuilder().createMultiLineStrings(polyLines); Assert.assertEquals( "{\"type\":\"Feature\",\"geometry\":{\"type\":\"MultiLineString\",\"coordinates\":[[[-122.031007,37.390535],[-122.028464,37.321628]],[[12.49234,41.890224],[2.294495,48.858241]]]}}", object.toString()); }
public PolyLine shiftLastAlongGreatCircle(final Heading initialHeading, final Distance distance) { return new PolyLine(new MultiIterable<>(this.truncate(0, 1), Iterables.from(this.last().shiftAlongGreatCircle(initialHeading, distance)))); }
public PolyLine shiftFirstAlongGreatCircle(final Heading initialHeading, final Distance distance) { return new PolyLine(new MultiIterable<>( Iterables.from(this.first().shiftAlongGreatCircle(initialHeading, distance)), this.truncate(1, 0))); }
@Test public void testAngleLocation() { final PolyLine polyLine = new PolyLine(this.quadrant); Assert.assertEquals(Location.forString("37.33531,-122.009566"), polyLine.maximumAngleLocation().get()); }
@Test public void testNoAnglesMatchingOurCriteria() { final PolyLine polyLine = new PolyLine(this.quadrant); // Find all angles greater than or equal to 140 degrees. final List<Tuple<Angle, Location>> result = polyLine .anglesGreaterThanOrEqualTo(Angle.degrees(179)); Assert.assertTrue(result.size() == 0); }
@Test public void testFindingAnglesLessThanTarget() { final PolyLine polyLine = new PolyLine(this.quadrant); // Find all angles less than or equal to 30 degrees. final List<Tuple<Angle, Location>> result = polyLine .anglesLessThanOrEqualTo(Angle.degrees(30)); Assert.assertEquals(1, result.size()); Assert.assertEquals(Tuple.createTuple(Angle.degrees(28.3372516), Location.forString("37.332451,-122.028932")), result.get(0)); }
/** * Construct a polyline from the centers of the provided shards */ private PolyLine polylineForShards(final Iterable<? extends Shard> shards) { return new PolyLine( new StreamIterable<>(shards).map(tile -> tile.bounds().center()).collectToList()); } }
@Test public void testSinglePointConversion() { final Location location = Location.TEST_1; final PolyLine polyline = new PolyLine(location); final byte[] wkb = new WkbPolyLineConverter().convert(polyline); final PolyLine polylineConverted = new WkbPolyLineConverter().backwardConvert(wkb); Assert.assertTrue("Input/output PolyLine must be the same", polyline.equals(polylineConverted)); }
@Test public void testWrite() { final StringResource resource = new StringResource(); final JsonWriter writer = new JsonWriter(resource); final PolyLine polyLine = new PolyLine(Location.TEST_6, Location.TEST_2, Location.TEST_2); writer.write(polyLine.asGeoJson().jsonObject()); writer.close(); Assert.assertEquals(polyLine.asGeoJson().toString(), resource.writtenString()); } }
@Test public void testMergePolyLines() { final PolyLine result = new PolyLine(Location.COLOSSEUM, Location.EIFFEL_TOWER); final FeatureChange featureChange1 = new FeatureChange(ChangeType.ADD, new CompleteLine(123L, result, null, null)); final FeatureChange featureChange2 = new FeatureChange(ChangeType.ADD, new CompleteLine(123L, result, null, null)); Assert.assertEquals(result, ((LineItem) featureChange1.merge(featureChange2).getReference()).asPolyLine()); }