Skip to content

Commit 6676389

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,9 @@ static List<Point> toListOfPoint(List listOfCoordinatePairs) {
757757
* @since 1.7
758758
*/
759759
static GeoJsonPolygon toGeoJsonPolygon(List dbList) {
760-
return new GeoJsonPolygon(toListOfPoint((List) dbList.get(0)));
760+
761+
GeoJsonPolygon polygon = new GeoJsonPolygon(toListOfPoint((List) dbList.get(0)));
762+
return dbList.size() > 1 ? polygon.withInnerRing(toListOfPoint((List) dbList.get(1))) : polygon;
761763
}
762764

763765
/**

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

Lines changed: 25 additions & 0 deletions
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
@@ -134,4 +135,28 @@ private static List<Point> asList(Point first, Point second, Point third, Point
134135

135136
return result;
136137
}
138+
139+
@Override
140+
public boolean equals(Object o) {
141+
if (this == o) {
142+
return true;
143+
}
144+
if (o == null || getClass() != o.getClass()) {
145+
return false;
146+
}
147+
if (!super.equals(o)) {
148+
return false;
149+
}
150+
151+
GeoJsonPolygon that = (GeoJsonPolygon) o;
152+
153+
return ObjectUtils.nullSafeEquals(this.coordinates, that.coordinates);
154+
}
155+
156+
@Override
157+
public int hashCode() {
158+
int result = super.hashCode();
159+
result = 31 * result + ObjectUtils.nullSafeHashCode(coordinates);
160+
return result;
161+
}
137162
}

0 commit comments

Comments
 (0)