Fix GeoJson polygon conversion for polygons with inner ring.

Closes: #4104
Original pull request: #4156.
This commit is contained in:
Christoph Strobl
2022-09-08 09:30:57 +02:00
committed by Mark Paluch
parent 81f85b8cca
commit 6676389062
2 changed files with 28 additions and 1 deletions

View File

@@ -757,7 +757,9 @@ abstract class GeoConverters {
* @since 1.7
*/
static GeoJsonPolygon toGeoJsonPolygon(List dbList) {
return new GeoJsonPolygon(toListOfPoint((List) dbList.get(0)));
GeoJsonPolygon polygon = new GeoJsonPolygon(toListOfPoint((List) dbList.get(0)));
return dbList.size() > 1 ? polygon.withInnerRing(toListOfPoint((List) dbList.get(1))) : polygon;
}
/**

View File

@@ -24,6 +24,7 @@ import java.util.List;
import org.springframework.data.geo.Point;
import org.springframework.data.geo.Polygon;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* {@link GeoJson} representation of {@link Polygon}. Unlike {@link Polygon} the {@link GeoJsonPolygon} requires a
@@ -134,4 +135,28 @@ public class GeoJsonPolygon extends Polygon implements GeoJson<List<GeoJsonLineS
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
GeoJsonPolygon that = (GeoJsonPolygon) o;
return ObjectUtils.nullSafeEquals(this.coordinates, that.coordinates);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + ObjectUtils.nullSafeHashCode(coordinates);
return result;
}
}