use of org.locationtech.spatial4j.shape.impl.BufferedLineString in project janusgraph by JanusGraph.
the class GeoshapeHelper method getPoint.
@SuppressWarnings("unchecked")
public Geoshape.Point getPoint(Geoshape geoshape, int position) {
final Shape shape = geoshape.getShape();
final Point p;
if (position < 0 || position >= size(shape))
throw new ArrayIndexOutOfBoundsException("Invalid position: " + position);
switch(getType(shape)) {
case POINT:
case CIRCLE:
return geoshape.getPoint();
case BOX:
if (position == 0)
return new Geoshape.Point(shape.getBoundingBox().getMinY(), shape.getBoundingBox().getMinX());
else
return new Geoshape.Point(shape.getBoundingBox().getMaxY(), shape.getBoundingBox().getMaxX());
case LINE:
p = ((BufferedLineString) shape).getPoints().get(position);
break;
case MULTIPOINT:
p = ((ShapeCollection<Point>) shape).getShapes().get(position);
break;
case MULTILINESTRING:
p = ((ShapeCollection<BufferedLineString>) shape).getShapes().stream().flatMap(line -> line.getPoints().stream()).skip(position).findFirst().orElse(null);
break;
case GEOMETRYCOLLECTION:
return ((ShapeCollection<Shape>) shape).getShapes().stream().flatMap(internShape -> IntStream.range(0, size(internShape)).mapToObj(i -> new AbstractMap.SimpleImmutableEntry<>(internShape, i))).skip(position).findFirst().map(entry -> getPoint(new Geoshape(entry.getKey()), entry.getValue())).orElse(null);
default:
throw new IllegalStateException("getPoint(int) not supported for type: " + getType(shape));
}
if (p == null)
throw new ArrayIndexOutOfBoundsException("Invalid position: " + position);
return new Geoshape.Point(p.getY(), p.getX());
}
Aggregations