@Override public Shape build() { return new ShapeCollection<>(shapes, ctx); } }
public List<Point> getPoints() { if (segments.isEmpty()) return Collections.emptyList(); final List<BufferedLine> lines = segments.getShapes(); return new AbstractList<Point>() { @Override public Point get(int index) { if (index == 0) return lines.get(0).getA(); return lines.get(index - 1).getB(); } @Override public int size() { return lines.size() + 1; } }; }
public void writeCollection(DataOutput dataOutput, ShapeCollection col) throws IOException { byte type = (byte) 0;//TODO add type to ShapeCollection dataOutput.writeByte(type); dataOutput.writeInt(col.size()); for (int i = 0; i < col.size(); i++) { Shape s = col.get(i); if (type == 0) { writeShape(dataOutput, s); } else { boolean written = writeShapeByTypeIfSupported(dataOutput, s, type); if (!written) throw new IllegalArgumentException("Unsupported shape type "+s.getClass()); } } }
@Override public ShapeCollection getBuffered(double distance, SpatialContext ctx) { List<Shape> bufColl = new ArrayList<Shape>(size()); for (Shape shape : shapes) { bufColl.add(shape.getBuffered(distance, ctx)); } return ctx.makeCollection(bufColl); }
@Override public boolean isEmpty() { return segments.isEmpty(); }
type = Geoshape.Type.LINE; } else if (ShapeCollection.class.isAssignableFrom(shape.getClass())) { final Set<Geoshape.Type> types = ((ShapeCollection<? extends Shape>) shape).getShapes().stream() .map(this::getType) .collect(Collectors.toSet());
/** * WARNING: {@code shapes} is copied by reference. * @param shapes Copied by reference! (make a defensive copy if caller modifies) * @param ctx */ public ShapeCollection(List<S> shapes, SpatialContext ctx) { if (!(shapes instanceof RandomAccess)) throw new IllegalArgumentException("Shapes arg must implement RandomAccess: "+shapes.getClass()); this.shapes = shapes; this.ctx = ctx; this.bbox = computeBoundingBox(shapes, ctx); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; BufferedLineString that = (BufferedLineString) o; if (Double.compare(that.buf, buf) != 0) return false; if (!segments.equals(that.segments)) return false; return true; }
output.append("{\"type\":\"LineString\",\"coordinates\":["); BufferedLine last = null; Iterator<BufferedLine> iter = v.getSegments().iterator(); while (iter.hasNext()) { BufferedLine seg = iter.next(); ShapeCollection v = (ShapeCollection) shape; output.append("{\"type\":\"GeometryCollection\",\"geometries\":["); for (int i = 0; i < v.size(); i++) { if (i > 0) { output.append(','); write(output, v.get(i));
@Override public ODocument toDoc(ShapeCollection<Shape> shapes) { ODocument doc = new ODocument(getName()); List<ODocument> geometries = new ArrayList<ODocument>(shapes.size()); for (Shape s : shapes) { geometries.add(shapeFactory.toDoc(s)); } doc.field("geometries", geometries); return doc; } }
@Override public Shape boundary(Shape s) { if (s instanceof Point) { // points have no boundary so return empty shape return createEmptyGeometry(); } else if (s instanceof ShapeCollection<?>) { ShapeCollection<?> col = (ShapeCollection<?>)s; if (col.isEmpty()) { return createEmptyGeometry(); } for (Shape p : col) { if (!(p instanceof Point)) { return notSupported(); } } return createEmptyGeometry(); } return notSupported(); }
public int size(Shape shape) { switch(getType(shape)) { case LINE: case POLYGON: case MULTIPOINT: case MULTILINESTRING: case MULTIPOLYGON: return ((JtsGeometry) shape).getGeom().getCoordinates().length; case POINT: return 1; case CIRCLE: return 1; case BOX: return 2; case GEOMETRYCOLLECTION: return ((ShapeCollection<?>) shape).getShapes().stream().map(s -> (Shape) s).mapToInt(s -> size(s)).sum(); default: throw new IllegalStateException("size() not supported for type: " + getType(shape)); } }
@Override public <S extends Shape> ShapeCollection<S> multiShape(List<S> coll) { return new ShapeCollection<>(coll, ctx); }
protected JtsGeometry createMultiLine(ShapeCollection<JtsGeometry> geometries) { LineString[] multiLineString = new LineString[geometries.size()]; int i = 0; for (JtsGeometry geometry : geometries) { multiLineString[i] = (LineString) geometry.getGeom(); i++; } MultiLineString multiPoints = GEOMETRY_FACTORY.createMultiLineString(multiLineString); return SPATIAL_CONTEXT.makeShape(multiPoints); }
@Override public Shape boundary(Shape s) { if (s instanceof Point) { // points have no boundary so return empty shape return createEmptyGeometry(); } else if (s instanceof ShapeCollection<?>) { ShapeCollection<?> col = (ShapeCollection<?>)s; if (col.isEmpty()) { return createEmptyGeometry(); } for (Shape p : col) { if (!(p instanceof Point)) { return notSupported(); } } return createEmptyGeometry(); } return notSupported(); }
return new Geoshape.Point(shape.getBoundingBox().getMaxY(), shape.getBoundingBox().getMaxX()); case GEOMETRYCOLLECTION: return ((ShapeCollection<Shape>) shape).getShapes().stream() .flatMap(internShape -> IntStream.range(0, size(internShape)) .mapToObj(i -> new AbstractMap.SimpleImmutableEntry<>(internShape, i)))
private Shape createEmptyGeometry() { return new ShapeCollection<Shape>(Collections.<Shape> emptyList(), SpatialSupport.getSpatialContext()); }
@Override public String asText(ShapeCollection<Shape> shapes) { Geometry[] geometries = new Geometry[shapes.size()]; int i = 0; for (Shape shape : shapes) { geometries[i] = SPATIAL_CONTEXT.getGeometryFrom(shape); i++; } return GEOMETRY_FACTORY.createGeometryCollection(geometries).toText(); }