-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Geometry formatters should be applied to the full array (#75177)
Changes the way we fetch values from source in geo fields so we can format all data in one go.
- Loading branch information
Showing
12 changed files
with
110 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
server/src/main/java/org/elasticsearch/common/geo/GeoFormatterFactory.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
server/src/main/java/org/elasticsearch/common/geo/GeometryFormatterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.common.geo; | ||
|
||
import org.elasticsearch.geometry.Geometry; | ||
import org.elasticsearch.geometry.utils.WellKnownText; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Output formatters supported by geometry fields. | ||
*/ | ||
public class GeometryFormatterFactory { | ||
|
||
public static final String GEOJSON = "geojson"; | ||
public static final String WKT = "wkt"; | ||
|
||
/** | ||
* Returns a formatter by name | ||
*/ | ||
public static <T> Function<List<T>, List<Object>> getFormatter(String name, Function<T, Geometry> toGeometry) { | ||
switch (name) { | ||
case GEOJSON: | ||
return geometries -> { | ||
final List<Object> objects = new ArrayList<>(geometries.size()); | ||
geometries.forEach((shape) -> objects.add(GeoJson.toMap(toGeometry.apply(shape)))); | ||
return objects; | ||
}; | ||
case WKT: | ||
return geometries -> { | ||
final List<Object> objects = new ArrayList<>(geometries.size()); | ||
geometries.forEach((shape) -> objects.add(WellKnownText.toWKT(toGeometry.apply(shape)))); | ||
return objects; | ||
}; | ||
default: throw new IllegalArgumentException("Unrecognized geometry format [" + name + "]."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
...atial/src/main/java/org/elasticsearch/xpack/spatial/common/CartesianFormatterFactory.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.