Skip to content

Commit

Permalink
Geo: extract dateline handling logic from ShapeBuilders (#44187)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
imotov committed Jul 17, 2019
1 parent 51d8e6e commit cd5a334
Show file tree
Hide file tree
Showing 10 changed files with 1,269 additions and 73 deletions.
16 changes: 10 additions & 6 deletions server/src/main/java/org/elasticsearch/common/geo/GeoJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,12 @@ private XContentBuilder coordinatesToXContent(Polygon polygon) throws IOExceptio

private static Geometry createGeometry(String type, List<Geometry> geometries, CoordinateNode coordinates, Boolean orientation,
boolean defaultOrientation, boolean coerce, DistanceUnit.Distance radius) {

ShapeType shapeType = ShapeType.forName(type);
ShapeType shapeType;
if ("bbox".equalsIgnoreCase(type)) {
shapeType = ShapeType.ENVELOPE;
} else {
shapeType = ShapeType.forName(type);
}
if (shapeType == ShapeType.GEOMETRYCOLLECTION) {
if (geometries == null) {
throw new ElasticsearchParseException("geometries not included");
Expand Down Expand Up @@ -484,7 +488,7 @@ public MultiPoint asMultiPoint() {
return new MultiPoint(points);
}

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

boolean needsClosing;
int resultSize;
if (coerce && children.get(0).asPoint().equals(children.get(children.size() - 1).asPoint()) == false) {
if (close && coerce && children.get(0).asPoint().equals(children.get(children.size() - 1).asPoint()) == false) {
needsClosing = true;
resultSize = children.size() + 1;
} else {
Expand Down Expand Up @@ -531,12 +535,12 @@ private double[][] asLineComponents(boolean orientation, boolean coerce) {
}

public Line asLineString(boolean coerce) {
double[][] components = asLineComponents(true, coerce);
double[][] components = asLineComponents(true, coerce, false);
return new Line(components[0], components[1], components[2]);
}

public LinearRing asLinearRing(boolean orientation, boolean coerce) {
double[][] components = asLineComponents(orientation, coerce);
double[][] components = asLineComponents(orientation, coerce, true);
return new LinearRing(components[0], components[1], components[2]);
}

Expand Down
Loading

0 comments on commit cd5a334

Please sign in to comment.