Skip to content

Commit ed4f30a

Browse files
christophstroblmp911de
authored andcommitted
Fix GeoJson polygon conversion for polygons with inner ring.
Closes: #4104 Original pull request: #4156.
1 parent cf38ba1 commit ed4f30a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/GeoConverters.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,9 @@ static List<Point> toListOfPoint(List listOfCoordinatePairs) {
841841
* @since 1.7
842842
*/
843843
static GeoJsonPolygon toGeoJsonPolygon(List dbList) {
844-
return new GeoJsonPolygon(toListOfPoint((List) dbList.get(0)));
844+
845+
GeoJsonPolygon polygon = new GeoJsonPolygon(toListOfPoint((List) dbList.get(0)));
846+
return dbList.size() > 1 ? polygon.withInnerRing(toListOfPoint((List) dbList.get(1))) : polygon;
845847
}
846848

847849
/**

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/GeoJsonPolygon.java

+25
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.data.geo.Point;
2525
import org.springframework.data.geo.Polygon;
2626
import org.springframework.util.Assert;
27+
import org.springframework.util.ObjectUtils;
2728

2829
/**
2930
* {@link GeoJson} representation of {@link Polygon}. Unlike {@link Polygon} the {@link GeoJsonPolygon} requires a
@@ -142,4 +143,28 @@ private static List<Point> asList(Point first, Point second, Point third, Point
142143

143144
return result;
144145
}
146+
147+
@Override
148+
public boolean equals(Object o) {
149+
if (this == o) {
150+
return true;
151+
}
152+
if (o == null || getClass() != o.getClass()) {
153+
return false;
154+
}
155+
if (!super.equals(o)) {
156+
return false;
157+
}
158+
159+
GeoJsonPolygon that = (GeoJsonPolygon) o;
160+
161+
return ObjectUtils.nullSafeEquals(this.coordinates, that.coordinates);
162+
}
163+
164+
@Override
165+
public int hashCode() {
166+
int result = super.hashCode();
167+
result = 31 * result + ObjectUtils.nullSafeHashCode(coordinates);
168+
return result;
169+
}
145170
}

0 commit comments

Comments
 (0)