use of org.locationtech.spatial4j.shape.jts.JtsGeometry in project elasticsearch by elastic.
the class GeoShapeFieldMapper method parse.
@Override
public Mapper parse(ParseContext context) throws IOException {
try {
Shape shape = context.parseExternalValue(Shape.class);
if (shape == null) {
ShapeBuilder shapeBuilder = ShapeBuilder.parse(context.parser(), this);
if (shapeBuilder == null) {
return null;
}
shape = shapeBuilder.build();
}
if (fieldType().pointsOnly() && !(shape instanceof Point)) {
throw new MapperParsingException("[{" + fieldType().name() + "}] is configured for points only but a " + ((shape instanceof JtsGeometry) ? ((JtsGeometry) shape).getGeom().getGeometryType() : shape.getClass()) + " was found");
}
Field[] fields = fieldType().defaultStrategy().createIndexableFields(shape);
if (fields == null || fields.length == 0) {
return null;
}
for (Field field : fields) {
if (!customBoost() && fieldType.boost() != 1f && Version.indexCreated(context.indexSettings()).before(Version.V_5_0_0_alpha1)) {
field.setBoost(fieldType().boost());
}
context.doc().add(field);
}
} catch (Exception e) {
throw new MapperParsingException("failed to parse [" + fieldType().name() + "]", e);
}
return null;
}
use of org.locationtech.spatial4j.shape.jts.JtsGeometry in project elasticsearch by elastic.
the class GeoPolygonQueryBuilderTests method randomPolygon.
private static List<GeoPoint> randomPolygon() {
ShapeBuilder shapeBuilder = null;
// in this case keep trying until we successfully generate one
while (shapeBuilder == null) {
shapeBuilder = RandomShapeGenerator.createShapeWithin(random(), null, ShapeType.POLYGON);
}
JtsGeometry shape = (JtsGeometry) shapeBuilder.build();
Coordinate[] coordinates = shape.getGeom().getCoordinates();
ArrayList<GeoPoint> polygonPoints = new ArrayList<>();
for (Coordinate coord : coordinates) {
polygonPoints.add(new GeoPoint(coord.y, coord.x));
}
return polygonPoints;
}
Aggregations