Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ default boolean isEmpty() {
return getValue().isEmpty();
}

@Override
@Value.Default
default Axes getAxes() {
if (isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum Axes {
XYM(3, " M", 2000),
XYZM(4, " ZM", 3000);

public static final int SPECIAL_SHIFT = 1000000;
public static final int SPECIAL_SHIFT = 1_000_000;

private final int size;
private final String wktSuffix;
Expand All @@ -39,10 +39,15 @@ public static Axes fromWkbCode(long geometryTypeCode) {
// with axes XY have a different geometry type code 100000x.
return Axes.XY;
}
return (geometryTypeCode >= Axes.XYZM.wkbShift)
? Axes.XYZM
: (geometryTypeCode >= Axes.XYM.wkbShift)
? Axes.XYM
: (geometryTypeCode >= Axes.XYZ.wkbShift) ? Axes.XYZ : Axes.XY;
if (geometryTypeCode >= Axes.XYZM.wkbShift) {
return Axes.XYZM;
}
if (geometryTypeCode >= Axes.XYM.wkbShift) {
return Axes.XYM;
}
if (geometryTypeCode >= Axes.XYZ.wkbShift) {
return Axes.XYZ;
}
return Axes.XY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static CircularString of(PositionList positionList, Optional<EpsgCrs> crs) {
return ImmutableCircularString.builder().crs(crs).value(positionList).build();
}

@Override
@Value.Default
default Axes getAxes() {
return getValue().getAxes();
Expand All @@ -42,7 +43,7 @@ default boolean isEmpty() {
@Value.Check
default void check() {
Preconditions.checkState(
isEmpty() || (getValue().getNumPositions() > 2 && getValue().getNumPositions() % 2 == 1),
isEmpty() || getValue().getNumPositions() > 2 && getValue().getNumPositions() % 2 == 1,
"A non-empty circular string must have an odd number of positions and at least three positions, found %d positions.",
getValue().getNumPositions());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static CompoundCurve of(List<SingleCurve> curves, Optional<EpsgCrs> crs) {
.build();
}

@Override
@Value.Default
default Axes getAxes() {
if (isEmpty()) {
Expand Down Expand Up @@ -77,6 +78,7 @@ default boolean isClosed() {
numPositionsLastCurve * size);
}

@Override
@Value.Derived
@Value.Auxiliary
default int getNumGeometries() {
Expand Down Expand Up @@ -118,7 +120,7 @@ default void check() {
Preconditions.checkArgument(
getValue().stream()
.allMatch(
g -> (g.getCrs().isEmpty() && getCrs().isEmpty()) || (g.getCrs().equals(getCrs()))),
g -> g.getCrs().isEmpty() && getCrs().isEmpty() || g.getCrs().equals(getCrs())),
"All geometries must have the same CRS.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static CurvePolygon of(List<Curve<?>> rings, Optional<EpsgCrs> crs) {
.build();
}

@Override
@Value.Default
default Axes getAxes() {
if (isEmpty()) {
Expand All @@ -66,7 +67,7 @@ default void check() {
Preconditions.checkArgument(
getValue().stream()
.allMatch(
g -> (g.getCrs().isEmpty() && getCrs().isEmpty()) || (g.getCrs().equals(getCrs()))),
g -> g.getCrs().isEmpty() && getCrs().isEmpty() || g.getCrs().equals(getCrs())),
"All geometries must have the same CRS.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ default void check() {
Preconditions.checkArgument(
getValue().stream()
.allMatch(
g -> (g.getCrs().isEmpty() && getCrs().isEmpty()) || (g.getCrs().equals(getCrs()))),
g -> g.getCrs().isEmpty() && getCrs().isEmpty() || g.getCrs().equals(getCrs())),
"All geometries must have the same CRS.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public enum GeometryType {
public static final Set<GeometryType> DEFAULT_GEOMETRY_TYPES =
Set.of(POINT, MULTI_POINT, LINE_STRING, MULTI_LINE_STRING, POLYGON, MULTI_POLYGON);

public static boolean onlySimpleFeatureGeometries(Set<GeometryType> geometryTypes) {
return geometryTypes.stream().allMatch(GeometryType::isSimpleFeature);
}

private final boolean isSimpleFeature;
private final Integer geometryDimension;
private final Boolean hasNestedGeometries;
Expand All @@ -61,6 +57,10 @@ public static boolean onlySimpleFeatureGeometries(Set<GeometryType> geometryType
this.hasNestedGeometries = hasNestedGeometries;
}

public static boolean onlySimpleFeatureGeometries(Set<GeometryType> geometryTypes) {
return geometryTypes.stream().allMatch(GeometryType::isSimpleFeature);
}

public Optional<Integer> getGeometryDimension() {
return Optional.ofNullable(geometryDimension);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ static LineString empty(Axes axes) {
return ImmutableLineString.builder().value(PositionList.empty(axes)).build();
}

static LineString of(double[] xyCoordinates) {
static LineString of(double... xyCoordinates) {
return ImmutableLineString.builder().value(PositionList.of(Axes.XY, xyCoordinates)).build();
}

@SuppressWarnings("PMD.UseVarargs")
static LineString of(double[] xyCoordinates, EpsgCrs crs) {
return of(crs, xyCoordinates);
}

static LineString of(EpsgCrs crs, double... xyCoordinates) {
return ImmutableLineString.builder()
.crs(crs)
.value(PositionList.of(Axes.XY, xyCoordinates))
Expand Down Expand Up @@ -57,6 +62,7 @@ static LineString of(List<Position> positions) {
return ImmutableLineString.builder().value(PositionList.of(axes, coordinates)).build();
}

@Override
@Value.Derived
@Value.Auxiliary
default Axes getAxes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ default void check() {
Preconditions.checkArgument(
getValue().stream()
.allMatch(
g -> (g.getCrs().isEmpty() && getCrs().isEmpty()) || (g.getCrs().equals(getCrs()))),
g -> g.getCrs().isEmpty() && getCrs().isEmpty() || g.getCrs().equals(getCrs())),
"All geometries must have the same CRS.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ default void check() {
Preconditions.checkArgument(
getValue().stream()
.allMatch(
g -> (g.getCrs().isEmpty() && getCrs().isEmpty()) || (g.getCrs().equals(getCrs()))),
g -> g.getCrs().isEmpty() && getCrs().isEmpty() || g.getCrs().equals(getCrs())),
"All geometries must have the same CRS.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ default void check() {
Preconditions.checkArgument(
getValue().stream()
.allMatch(
g -> (g.getCrs().isEmpty() && getCrs().isEmpty()) || (g.getCrs().equals(getCrs()))),
g -> g.getCrs().isEmpty() && getCrs().isEmpty() || g.getCrs().equals(getCrs())),
"All geometries must have the same CRS.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ default void check() {
Preconditions.checkArgument(
getValue().stream()
.allMatch(
g -> (g.getCrs().isEmpty() && getCrs().isEmpty()) || (g.getCrs().equals(getCrs()))),
g -> g.getCrs().isEmpty() && getCrs().isEmpty() || g.getCrs().equals(getCrs())),
"All geometries must have the same CRS.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ default void check() {
Preconditions.checkArgument(
getValue().stream()
.allMatch(
g -> (g.getCrs().isEmpty() && getCrs().isEmpty()) || (g.getCrs().equals(getCrs()))),
g -> g.getCrs().isEmpty() && getCrs().isEmpty() || g.getCrs().equals(getCrs())),
"All geometries must have the same CRS.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static Point of(Position pos, Optional<EpsgCrs> crs) {
return ImmutablePoint.builder().crs(crs).value(pos).build();
}

@Override
@Value.Derived
@Value.Auxiliary
default Axes getAxes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,29 @@ static Polygon empty(Axes axes) {
return ImmutablePolygon.builder().value(List.of()).axes(axes).build();
}

static Polygon of(double[] xyOuterRing) {
static Polygon of(double... xyOuterRing) {
return ImmutablePolygon.builder().value(List.of(LineString.of(xyOuterRing))).build();
}

@SuppressWarnings("PMD.UseVarargs")
static Polygon of(double[] xyOuterRing, EpsgCrs crs) {
return of(crs, xyOuterRing);
}

static Polygon of(EpsgCrs crs, double... xyOuterRing) {
return ImmutablePolygon.builder()
.crs(crs)
.value(List.of(LineString.of(xyOuterRing, crs)))
.value(List.of(LineString.of(crs, xyOuterRing)))
.build();
}

static Polygon of(List<PositionList> rings) {
return ImmutablePolygon.builder()
.value(rings.stream().map(LineString::of).filter(ring -> !ring.isEmpty()).toList())
.value(
rings.stream()
.map(ring -> LineString.of(ring))
.filter(ring -> !ring.isEmpty())
.toList())
.build();
}

Expand All @@ -59,6 +68,7 @@ static Polygon ofBbox(double xmin, double ymin, double xmax, double ymax, EpsgCr
.build();
}

@Override
@Value.Default
default Axes getAxes() {
if (isEmpty()) {
Expand Down Expand Up @@ -89,7 +99,7 @@ default void check() {
Preconditions.checkArgument(
getValue().stream()
.allMatch(
g -> (g.getCrs().isEmpty() && getCrs().isEmpty()) || (g.getCrs().equals(getCrs()))),
g -> g.getCrs().isEmpty() && getCrs().isEmpty() || g.getCrs().equals(getCrs())),
"All geometries must have the same CRS.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static PolyhedralSurface of(List<Polygon> polygons, boolean closed, Optional<Eps
.build();
}

@Override
@Value.Default
default Axes getAxes() {
if (isEmpty()) {
Expand Down Expand Up @@ -81,7 +82,7 @@ default void check() {
Preconditions.checkArgument(
getValue().stream()
.allMatch(
g -> (g.getCrs().isEmpty() && getCrs().isEmpty()) || (g.getCrs().equals(getCrs()))),
g -> g.getCrs().isEmpty() && getCrs().isEmpty() || g.getCrs().equals(getCrs())),
"All geometries must have the same CRS.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.immutables.value.Value;

@Value.Immutable
@SuppressWarnings({"PMD.TooManyMethods", "PMD.ExcessiveMethodCount"})
public abstract class Position {

@NotNull
Expand All @@ -27,7 +28,7 @@ public static Position empty(Axes axes) {
return ImmutablePosition.builder().axes(axes).coordinates(coordinates).build();
}

public static Position of(Axes axes, double[] coordinates) {
public static Position of(Axes axes, double... coordinates) {
return ImmutablePosition.builder().axes(axes).coordinates(coordinates).build();
}

Expand Down Expand Up @@ -73,6 +74,13 @@ public boolean equals(Object obj) {
return false;
}

@Override
public int hashCode() {
int result = getAxes().hashCode();
result = 31 * result + Arrays.hashCode(getCoordinates());
return result;
}

@Value.Derived
@Value.Auxiliary
public double x() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static PositionList empty(Axes axes) {
return ImmutablePositionList.builder().axes(axes).coordinates(new double[0]).build();
}

public static PositionList of(Axes axes, double[] coordinates) {
public static PositionList of(Axes axes, double... coordinates) {
return ImmutablePositionList.builder().axes(axes).coordinates(coordinates).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
import java.util.List;
import java.util.Optional;

public abstract class AbstractGeometryDecoder {
@SuppressWarnings({"PMD.TooManyMethods", "PMD.ExcessiveMethodCount"})
public class AbstractGeometryDecoder {

@SuppressWarnings("PMD.CyclomaticComplexity")
protected Geometry<?> empty(GeometryType type, Axes axes) {
return switch (type) {
case POINT -> Point.empty(axes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ enum Axis {
Y,
Z;

static final Axis[] fromInt = {X, Y, Z};
static final Axis[] FROM_INT = {X, Y, Z};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import de.ii.xtraplatform.geometries.domain.PositionList.Interpolation;
import de.ii.xtraplatform.geometries.domain.transform.DoubleArrayProcessor;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.OptionalInt;
import org.immutables.value.Value;
Expand All @@ -36,19 +35,18 @@ public Void onCoordinates(
Optional<Interpolation> interpolation,
OptionalInt minNumberOfPositions)
throws IOException {
Integer[] precision = getPrecision().toArray(getPrecision().toArray(new Integer[0]));
Integer[] precision = getPrecision().toArray(new Integer[0]);
for (int i = 0; i < length; i++) {
int axisIndex = i % dimension;
Axis axis = Axis.fromInt[axisIndex];
Axis axis = Axis.FROM_INT[axisIndex];
String value = String.valueOf(coordinates[i]);

/*
TODO: will not be applied when no transformations are given
move to separate step
*/
if (precision[axisIndex] > 0) {
BigDecimal bd = new BigDecimal(value).setScale(precision[axisIndex], RoundingMode.HALF_UP);
value = bd.toPlainString();
value = String.format(Locale.ROOT, "%." + precision[axisIndex] + "f", coordinates[i]);
}

switch (axis) {
Expand Down
Loading
Loading