Skip to content

Commit 33ad792

Browse files
authored
Geo: extract dateline handling logic from ShapeBuilders (#44187)
Extracts dateline decomposition logic from ShapeBuilder into a separate utility class that is used on the indexing side. The search side will be handled as part of another PR at this time we will remove the decomposition logic from ShapeBuilders as well. This PR also doesn't change any existing logic including bugs. Relates to #40908
1 parent f16ec49 commit 33ad792

File tree

10 files changed

+1269
-73
lines changed

10 files changed

+1269
-73
lines changed

server/src/main/java/org/elasticsearch/common/geo/GeoJson.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,12 @@ private XContentBuilder coordinatesToXContent(Polygon polygon) throws IOExceptio
228228

229229
private static Geometry createGeometry(String type, List<Geometry> geometries, CoordinateNode coordinates, Boolean orientation,
230230
boolean defaultOrientation, boolean coerce, DistanceUnit.Distance radius) {
231-
232-
ShapeType shapeType = ShapeType.forName(type);
231+
ShapeType shapeType;
232+
if ("bbox".equalsIgnoreCase(type)) {
233+
shapeType = ShapeType.ENVELOPE;
234+
} else {
235+
shapeType = ShapeType.forName(type);
236+
}
233237
if (shapeType == ShapeType.GEOMETRYCOLLECTION) {
234238
if (geometries == null) {
235239
throw new ElasticsearchParseException("geometries not included");
@@ -484,7 +488,7 @@ public MultiPoint asMultiPoint() {
484488
return new MultiPoint(points);
485489
}
486490

487-
private double[][] asLineComponents(boolean orientation, boolean coerce) {
491+
private double[][] asLineComponents(boolean orientation, boolean coerce, boolean close) {
488492
if (coordinate != null) {
489493
throw new ElasticsearchException("expected a list of points but got a point");
490494
}
@@ -495,7 +499,7 @@ private double[][] asLineComponents(boolean orientation, boolean coerce) {
495499

496500
boolean needsClosing;
497501
int resultSize;
498-
if (coerce && children.get(0).asPoint().equals(children.get(children.size() - 1).asPoint()) == false) {
502+
if (close && coerce && children.get(0).asPoint().equals(children.get(children.size() - 1).asPoint()) == false) {
499503
needsClosing = true;
500504
resultSize = children.size() + 1;
501505
} else {
@@ -531,12 +535,12 @@ private double[][] asLineComponents(boolean orientation, boolean coerce) {
531535
}
532536

533537
public Line asLineString(boolean coerce) {
534-
double[][] components = asLineComponents(true, coerce);
538+
double[][] components = asLineComponents(true, coerce, false);
535539
return new Line(components[0], components[1], components[2]);
536540
}
537541

538542
public LinearRing asLinearRing(boolean orientation, boolean coerce) {
539-
double[][] components = asLineComponents(orientation, coerce);
543+
double[][] components = asLineComponents(orientation, coerce, true);
540544
return new LinearRing(components[0], components[1], components[2]);
541545
}
542546

0 commit comments

Comments
 (0)