@Override public MultiDimensionalPositions.Builder addChild(Positions p) { if(p instanceof AreaPositions) { return addAreaPosition((AreaPositions) p); } else if (p instanceof LinearPositions) { return addAreaPosition(AreaPositions.builder().addLinearPosition((LinearPositions) p).build()); } else { throw new IllegalArgumentException("The position " + p + "cannot be a child of MultiDimensionalPositions"); } }
@Override public MultiDimensionalPositions.Builder addChild(Positions p) { if(p instanceof AreaPositions) { return addAreaPosition((AreaPositions) p); } else if (p instanceof LinearPositions) { return addAreaPosition(AreaPositions.builder().addLinearPosition((LinearPositions) p).build()); } else { throw new IllegalArgumentException("The position " + p + "cannot be a child of MultiDimensionalPositions"); } }
/** * Merge this Positions with another one. If the given {@link Positions} is: * - SinglePosition, it will raise an IllegalArgumentException. * - LinearPositions, it is a special case in which the given LinearPositions represent a * {@link com.github.filosganga.geogson.model.Polygon} with no holes. This is probably not compliant with the * GeoJson specifications, but it seems to happen quite frequently. It will be handled as the AreaPositions case. * - AreaPositions, it will return a new MultiDimensionalPositions by appending the given AreaPositions to this. * - Any other, it will raise an IllegalArgumentException * * @param other Positions instance to merge with. * * @return Positions results of merging. */ @Override public Positions merge(Positions other) { if (other instanceof SinglePosition) { throw new IllegalArgumentException("Cannot merge single position and multidimensional positions"); } else if (other instanceof LinearPositions) { // It can happen when a Polygon does not have holes and is represented by linear position see bug #19 return merge(AreaPositions.builder().addLinearPosition((LinearPositions) other).build()); } else if (other instanceof AreaPositions) { AreaPositions that = (AreaPositions) other; return new MultiDimensionalPositions.Builder().addAreaPositions(children).addAreaPosition(that).build(); } else { throw new IllegalArgumentException("Cannot merge with: " + other); } }
/** * Merge this Positions with another one. If the given {@link Positions} is: * - SinglePosition, it will raise an IllegalArgumentException. * - LinearPositions, it will return a new AreaPosition by appending the given LinearPositions to this. * - AreaPositions, it will return a new MultiDimensionalPositions composed by this and the given AreaPositions, * in order. * - 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) { throw new IllegalArgumentException("Cannot merge single position and area children"); } else if (other instanceof LinearPositions) { LinearPositions that = (LinearPositions) other; return builder().addLinearPosition(that).build(); } else if (other instanceof AreaPositions) { AreaPositions that = (AreaPositions) other; return MultiDimensionalPositions.builder().addAreaPosition(this).addAreaPosition(that).build(); } else { return other.merge(this); } }
/** * Merge this Positions with another one. If the given {@link Positions} is: * - SinglePosition, it will raise an IllegalArgumentException. * - LinearPositions, it is a special case in which the given LinearPositions represent a * {@link com.github.filosganga.geogson.model.Polygon} with no holes. This is probably not compliant with the * GeoJson specifications, but it seems to happen quite frequently. It will be handled as the AreaPositions case. * - AreaPositions, it will return a new MultiDimensionalPositions by appending the given AreaPositions to this. * - Any other, it will raise an IllegalArgumentException * * @param other Positions instance to merge with. * * @return Positions results of merging. */ @Override public Positions merge(Positions other) { if (other instanceof SinglePosition) { throw new IllegalArgumentException("Cannot merge single position and multidimensional positions"); } else if (other instanceof LinearPositions) { // It can happen when a Polygon does not have holes and is represented by linear position see bug #19 return merge(AreaPositions.builder().addLinearPosition((LinearPositions) other).build()); } else if (other instanceof AreaPositions) { AreaPositions that = (AreaPositions) other; return new MultiDimensionalPositions.Builder().addAreaPositions(children).addAreaPosition(that).build(); } else { throw new IllegalArgumentException("Cannot merge with: " + other); } }
/** * Merge this Positions with another one. If the given {@link Positions} is: * - SinglePosition, it will raise an IllegalArgumentException. * - LinearPositions, it will return a new AreaPosition by appending the given LinearPositions to this. * - AreaPositions, it will return a new MultiDimensionalPositions composed by this and the given AreaPositions, * in order. * - 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) { throw new IllegalArgumentException("Cannot merge single position and area children"); } else if (other instanceof LinearPositions) { LinearPositions that = (LinearPositions) other; return builder().addLinearPosition(that).build(); } else if (other instanceof AreaPositions) { AreaPositions that = (AreaPositions) other; return MultiDimensionalPositions.builder().addAreaPosition(this).addAreaPosition(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 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); } }
/** * Creates a Polygon from the given perimeter and holes. * * @param perimeter The perimeter {@link LinearRing}. * @param holes The holes {@link LinearRing} Stream. * * @return Polygon */ public static Polygon of(LinearRing perimeter, Stream<LinearRing> holes) { return new Polygon(AreaPositions.builder() .addLinearPosition(perimeter.positions()) .addLinearPositions(holes .map(LinearRing::positions)::iterator) .build()); }
/** * Creates a Polygon from the given perimeter and holes. * * @param perimeter The perimeter {@link LinearRing}. * @param holes The holes {@link LinearRing} Stream. * * @return Polygon */ public static Polygon of(LinearRing perimeter, Stream<LinearRing> holes) { return new Polygon(AreaPositions.builder() .addLinearPosition(perimeter.positions()) .addLinearPositions(holes .map(LinearRing::positions)::iterator) .build()); }
/** * Creates a MultiLineString from the given LineStrings. * * @param lineStrings The Iterable of {@link LineString}. * @return MultiLineString. */ public static MultiLineString of(Iterable<LineString> lineStrings) { AreaPositions.Builder positionsBuilder = AreaPositions.builder(); for(LineString lineString : lineStrings) { positionsBuilder.addLinearPosition(lineString.positions()); } return new MultiLineString(positionsBuilder.build()); }
/** * Creates a MultiLineString from the given LineStrings. * * @param lineStrings The Iterable of {@link LineString}. * @return MultiLineString. */ public static MultiLineString of(Iterable<LineString> lineStrings) { AreaPositions.Builder positionsBuilder = AreaPositions.builder(); for(LineString lineString : lineStrings) { positionsBuilder.addLinearPosition(lineString.positions()); } return new MultiLineString(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"); } }
@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"); } }