@Override public PositionsBuilder addChild(Positions p) { if(p instanceof SinglePosition) { return addSinglePosition((SinglePosition) p); } else if (p instanceof LinearPositions) { return AreaPositions.builder().addChild(this.build()).addChild(p); } else { throw new IllegalArgumentException("The position " + p + "cannot be a child of LinearPositions"); } }
@Override public PositionsBuilder addChild(Positions p) { if(p instanceof SinglePosition) { return addSinglePosition((SinglePosition) p); } else if (p instanceof LinearPositions) { return AreaPositions.builder().addChild(this.build()).addChild(p); } else { throw new IllegalArgumentException("The position " + p + "cannot be a child of LinearPositions"); } }
@Override public PositionsBuilder addChild(Positions p) { if(p instanceof LinearPositions) { return addLinearPosition((LinearPositions)p); } else if (p instanceof SinglePosition) { return addLinearPosition(LinearPositions.builder().addSinglePosition((SinglePosition) p).build()); } else if (p instanceof AreaPositions) { return MultiDimensionalPositions.builder().addAreaPosition(this.build()).addChild(p); } else { throw new IllegalArgumentException("The position " + p + "cannot be a child of AreaPosition"); } }
private Geometry<?> buildGeometry(final Geometry.Type type, final Positions positions, final Geometry<?> geometries) { switch (type) { case GEOMETRY_COLLECTION: return geometries; case MULTI_POLYGON: return new MultiPolygon((MultiDimensionalPositions) positions); case POLYGON: return new Polygon((AreaPositions) positions); case MULTI_LINE_STRING: return new MultiLineString((AreaPositions) positions); case LINEAR_RING: case LINE_STRING: return ((LinearPositions) positions).isClosed() ? new LinearRing((LinearPositions) positions) : new LineString((LinearPositions) positions); case MULTI_POINT: if (positions instanceof SinglePosition) { return new MultiPoint(LinearPositions.builder().addSinglePosition((SinglePosition) positions).build()); } else { return new MultiPoint((LinearPositions) positions); } case POINT: return new Point(((SinglePosition) positions)); default: throw new IllegalArgumentException("Cannot build a geometry for type: " + type); } }
private Geometry<?> buildGeometry(final Geometry.Type type, final Positions positions, final Geometry<?> geometries) { switch (type) { case GEOMETRY_COLLECTION: return geometries; case MULTI_POLYGON: return new MultiPolygon((MultiDimensionalPositions) positions); case POLYGON: return new Polygon((AreaPositions) positions); case MULTI_LINE_STRING: return new MultiLineString((AreaPositions) positions); case LINEAR_RING: case LINE_STRING: return ((LinearPositions) positions).isClosed() ? new LinearRing((LinearPositions) positions) : new LineString((LinearPositions) positions); case MULTI_POINT: if (positions instanceof SinglePosition) { return new MultiPoint(LinearPositions.builder().addSinglePosition((SinglePosition) positions).build()); } else { return new MultiPoint((LinearPositions) positions); } case POINT: return new Point(((SinglePosition) positions)); default: throw new IllegalArgumentException("Cannot build a geometry for type: " + type); } }
/** * Merge this LinearPositions with another one. If the given {@link Positions} is: * - SinglePosition, it will return a new LinearPositions with the given SinglePosition appended. * - LinearPositions, it will return a new AreaPosition composed by this and the given LinearPositions. * - Any other, it delegates to the other the merge logic. * * @param other Positions instance to merge with. * * @return Positions results of merging. */ @Override public Positions merge(Positions other) { if (other instanceof SinglePosition) { SinglePosition that = (SinglePosition) other; return builder().addSinglePosition(that).build(); } else if (other instanceof LinearPositions) { LinearPositions that = (LinearPositions) other; return AreaPositions.builder().addLinearPosition(this).addLinearPosition(that).build(); } else { return other.merge(this); } }
/** * Merge this LinearPositions with another one. If the given {@link Positions} is: * - SinglePosition, it will return a new LinearPositions with the given SinglePosition appended. * - LinearPositions, it will return a new AreaPosition composed by this and the given LinearPositions. * - Any other, it delegates to the other the merge logic. * * @param other Positions instance to merge with. * * @return Positions results of merging. */ @Override public Positions merge(Positions other) { if (other instanceof SinglePosition) { SinglePosition that = (SinglePosition) other; return builder().addSinglePosition(that).build(); } else if (other instanceof LinearPositions) { LinearPositions that = (LinearPositions) other; return AreaPositions.builder().addLinearPosition(this).addLinearPosition(that).build(); } else { return other.merge(this); } }
/** * Merge this SinglePosition with another {@link Positions} instance. If the given {@link Positions} is: * - a SinglePosition, it returns a {@link LinearPositions} composed by this and the given positions, in order. * - any other {@link Positions}, it delegates to the given {@link Positions} merge. * * @param other Positions instance to merge with. * * @return Positions instance result of merge. */ @Override public Positions merge(Positions other) { if (other instanceof SinglePosition) { SinglePosition that = (SinglePosition) other; return LinearPositions.builder().addSinglePosition(this).addSinglePosition(that).build(); } else { return other.merge(this); } }
/** * Merge this SinglePosition with another {@link Positions} instance. If the given {@link Positions} is: * - a SinglePosition, it returns a {@link LinearPositions} composed by this and the given positions, in order. * - any other {@link Positions}, it delegates to the given {@link Positions} merge. * * @param other Positions instance to merge with. * * @return Positions instance result of merge. */ @Override public Positions merge(Positions other) { if (other instanceof SinglePosition) { SinglePosition that = (SinglePosition) other; return LinearPositions.builder().addSinglePosition(this).addSinglePosition(that).build(); } else { return other.merge(this); } }
/** * Creates a MultiPoint from the given points. * * @param points The {@link Point} Iterable. * @return MultiPoint */ public static MultiPoint of(Iterable<Point> points) { LinearPositions.Builder positionsBuilder = LinearPositions.builder(); for(Point point : points) { positionsBuilder.addSinglePosition(point.positions()); } return new MultiPoint(positionsBuilder.build()); }
/** * Creates a LineString from the given points. * * @param points Iterable of Point at least by 2 points. * @return a LineString */ public static LineString of(Iterable<Point> points) { LinearPositions.Builder positionsBuilder = LinearPositions.builder(); for(Point point : points) { positionsBuilder.addSinglePosition(point.positions()); } return new LineString(positionsBuilder.build()); }
/** * Create a LinearRing from the given points. * * @param points Point Iterable composed at least by 4 points, with the first and the last that are the same. * @return a LinearRing */ public static LinearRing of(Iterable<Point> points) { LinearPositions.Builder builder = LinearPositions.builder(); for(Point point : points) { builder.addSinglePosition(point.positions()); } return new LinearRing(builder.build()); }
/** * Create a LinearRing from the given points. * * @param points Point Iterable composed at least by 4 points, with the first and the last that are the same. * @return a LinearRing */ public static LinearRing of(Iterable<Point> points) { LinearPositions.Builder builder = LinearPositions.builder(); for(Point point : points) { builder.addSinglePosition(point.positions()); } return new LinearRing(builder.build()); }
/** * Creates a LineString from the given points. * * @param points Iterable of Point at least by 2 points. * @return a LineString */ public static LineString of(Iterable<Point> points) { LinearPositions.Builder positionsBuilder = LinearPositions.builder(); for(Point point : points) { positionsBuilder.addSinglePosition(point.positions()); } return new LineString(positionsBuilder.build()); }
/** * Creates a MultiPoint from the given points. * * @param points The {@link Point} Iterable. * @return MultiPoint */ public static MultiPoint of(Iterable<Point> points) { LinearPositions.Builder positionsBuilder = LinearPositions.builder(); for(Point point : points) { positionsBuilder.addSinglePosition(point.positions()); } return new MultiPoint(positionsBuilder.build()); }
@Override public PositionsBuilder addChild(Positions p) { if(p instanceof LinearPositions) { return addLinearPosition((LinearPositions)p); } else if (p instanceof SinglePosition) { return addLinearPosition(LinearPositions.builder().addSinglePosition((SinglePosition) p).build()); } else if (p instanceof AreaPositions) { return MultiDimensionalPositions.builder().addAreaPosition(this.build()).addChild(p); } else { throw new IllegalArgumentException("The position " + p + "cannot be a child of AreaPosition"); } }