Merge pull request #14482 from cbuescher/remove-internal-linestring-builder
Remove InternalLineStringBuilder and InternalPolygonBuilder
This commit is contained in:
commit
aa1507d349
|
@ -23,7 +23,6 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.spatial4j.core.shape.ShapeCollection;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import com.spatial4j.core.shape.Shape;
|
||||
|
@ -34,11 +33,7 @@ import com.vividsolutions.jts.geom.LineString;
|
|||
|
||||
public abstract class BaseLineStringBuilder<E extends BaseLineStringBuilder<E>> extends PointCollection<E> {
|
||||
|
||||
protected BaseLineStringBuilder() {
|
||||
this(new ArrayList<Coordinate>());
|
||||
}
|
||||
|
||||
protected BaseLineStringBuilder(ArrayList<Coordinate> points) {
|
||||
public BaseLineStringBuilder(ArrayList<Coordinate> points) {
|
||||
super(points);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,11 +51,11 @@ public abstract class BasePolygonBuilder<E extends BasePolygonBuilder<E>> extend
|
|||
|
||||
public static final GeoShapeType TYPE = GeoShapeType.POLYGON;
|
||||
|
||||
// Linear ring defining the shell of the polygon
|
||||
protected Ring<E> shell;
|
||||
// line string defining the shell of the polygon
|
||||
protected LineStringBuilder shell;
|
||||
|
||||
// List of linear rings defining the holes of the polygon
|
||||
protected final ArrayList<BaseLineStringBuilder<?>> holes = new ArrayList<>();
|
||||
// List of line strings defining the holes of the polygon
|
||||
protected final ArrayList<LineStringBuilder> holes = new ArrayList<>();
|
||||
|
||||
public BasePolygonBuilder(Orientation orientation) {
|
||||
super(orientation);
|
||||
|
@ -96,27 +96,17 @@ public abstract class BasePolygonBuilder<E extends BasePolygonBuilder<E>> extend
|
|||
* @param hole linear ring defining the hole
|
||||
* @return this
|
||||
*/
|
||||
public E hole(BaseLineStringBuilder<?> hole) {
|
||||
public E hole(LineStringBuilder hole) {
|
||||
holes.add(hole);
|
||||
return thisRef();
|
||||
}
|
||||
|
||||
/**
|
||||
* build new hole to the polygon
|
||||
* @return this
|
||||
*/
|
||||
public Ring<E> hole() {
|
||||
Ring<E> hole = new Ring<>(thisRef());
|
||||
this.holes.add(hole);
|
||||
return hole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the shell of the polygon
|
||||
* @return parent
|
||||
*/
|
||||
public ShapeBuilder close() {
|
||||
return shell.close();
|
||||
public BasePolygonBuilder close() {
|
||||
shell.close();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,7 +162,7 @@ public abstract class BasePolygonBuilder<E extends BasePolygonBuilder<E>> extend
|
|||
|
||||
protected XContentBuilder coordinatesArray(XContentBuilder builder, Params params) throws IOException {
|
||||
shell.coordinatesToXcontent(builder, true);
|
||||
for(BaseLineStringBuilder<?> hole : holes) {
|
||||
for(BaseLineStringBuilder hole : holes) {
|
||||
hole.coordinatesToXcontent(builder, true);
|
||||
}
|
||||
return builder;
|
||||
|
@ -207,7 +197,7 @@ public abstract class BasePolygonBuilder<E extends BasePolygonBuilder<E>> extend
|
|||
protected Polygon toPolygon(GeometryFactory factory) {
|
||||
final LinearRing shell = linearRing(factory, this.shell.points);
|
||||
final LinearRing[] holes = new LinearRing[this.holes.size()];
|
||||
Iterator<BaseLineStringBuilder<?>> iterator = this.holes.iterator();
|
||||
Iterator<LineStringBuilder> iterator = this.holes.iterator();
|
||||
for (int i = 0; iterator.hasNext(); i++) {
|
||||
holes[i] = linearRing(factory, iterator.next().points);
|
||||
}
|
||||
|
@ -516,8 +506,8 @@ public abstract class BasePolygonBuilder<E extends BasePolygonBuilder<E>> extend
|
|||
}
|
||||
}
|
||||
|
||||
private static int createEdges(int component, Orientation orientation, BaseLineStringBuilder<?> shell,
|
||||
BaseLineStringBuilder<?> hole,
|
||||
private static int createEdges(int component, Orientation orientation, BaseLineStringBuilder shell,
|
||||
BaseLineStringBuilder hole,
|
||||
Edge[] edges, int offset) {
|
||||
// inner rings (holes) have an opposite direction than the outer rings
|
||||
// XOR will invert the orientation for outer ring cases (Truth Table:, T/T = F, T/F = T, F/T = T, F/F = F)
|
||||
|
@ -527,32 +517,4 @@ public abstract class BasePolygonBuilder<E extends BasePolygonBuilder<E>> extend
|
|||
Edge.ring(component, direction, orientation == Orientation.LEFT, shell, points, 0, edges, offset, points.length-1);
|
||||
return points.length-1;
|
||||
}
|
||||
|
||||
public static class Ring<P extends ShapeBuilder> extends BaseLineStringBuilder<Ring<P>> {
|
||||
|
||||
private final P parent;
|
||||
|
||||
protected Ring(P parent) {
|
||||
this(parent, new ArrayList<Coordinate>());
|
||||
}
|
||||
|
||||
protected Ring(P parent, ArrayList<Coordinate> points) {
|
||||
super(points);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public P close() {
|
||||
Coordinate start = points.get(0);
|
||||
Coordinate end = points.get(points.size()-1);
|
||||
if(start.x != end.x || start.y != end.y) {
|
||||
points.add(start);
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeoShapeType type() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class GeometryCollectionBuilder extends ShapeBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public GeometryCollectionBuilder line(BaseLineStringBuilder<?> line) {
|
||||
public GeometryCollectionBuilder line(BaseLineStringBuilder line) {
|
||||
this.shapes.add(line);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,23 @@
|
|||
|
||||
package org.elasticsearch.common.geo.builders;
|
||||
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LineStringBuilder extends BaseLineStringBuilder<LineStringBuilder> {
|
||||
|
||||
public LineStringBuilder() {
|
||||
this(new ArrayList<Coordinate>());
|
||||
}
|
||||
|
||||
public LineStringBuilder(ArrayList<Coordinate> points) {
|
||||
super(points);
|
||||
}
|
||||
|
||||
public static final GeoShapeType TYPE = GeoShapeType.LINESTRING;
|
||||
|
||||
@Override
|
||||
|
@ -42,4 +53,16 @@ public class LineStringBuilder extends BaseLineStringBuilder<LineStringBuilder>
|
|||
return TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the current lineString by adding the starting point as the end point
|
||||
*/
|
||||
public LineStringBuilder close() {
|
||||
Coordinate start = points.get(0);
|
||||
Coordinate end = points.get(points.size()-1);
|
||||
if(start.x != end.x || start.y != end.y) {
|
||||
points.add(start);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.common.geo.builders;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import com.spatial4j.core.shape.Shape;
|
||||
import com.spatial4j.core.shape.jts.JtsGeometry;
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.LineString;
|
||||
|
@ -35,15 +34,9 @@ public class MultiLineStringBuilder extends ShapeBuilder {
|
|||
|
||||
public static final GeoShapeType TYPE = GeoShapeType.MULTILINESTRING;
|
||||
|
||||
private final ArrayList<BaseLineStringBuilder<?>> lines = new ArrayList<>();
|
||||
private final ArrayList<LineStringBuilder> lines = new ArrayList<>();
|
||||
|
||||
public InternalLineStringBuilder linestring() {
|
||||
InternalLineStringBuilder line = new InternalLineStringBuilder(this);
|
||||
this.lines.add(line);
|
||||
return line;
|
||||
}
|
||||
|
||||
public MultiLineStringBuilder linestring(BaseLineStringBuilder<?> line) {
|
||||
public MultiLineStringBuilder linestring(LineStringBuilder line) {
|
||||
this.lines.add(line);
|
||||
return this;
|
||||
}
|
||||
|
@ -67,7 +60,7 @@ public class MultiLineStringBuilder extends ShapeBuilder {
|
|||
builder.field(FIELD_TYPE, TYPE.shapename);
|
||||
builder.field(FIELD_COORDINATES);
|
||||
builder.startArray();
|
||||
for(BaseLineStringBuilder<?> line : lines) {
|
||||
for(BaseLineStringBuilder line : lines) {
|
||||
line.coordinatesToXcontent(builder, false);
|
||||
}
|
||||
builder.endArray();
|
||||
|
@ -80,7 +73,7 @@ public class MultiLineStringBuilder extends ShapeBuilder {
|
|||
final Geometry geometry;
|
||||
if(wrapdateline) {
|
||||
ArrayList<LineString> parts = new ArrayList<>();
|
||||
for (BaseLineStringBuilder<?> line : lines) {
|
||||
for (BaseLineStringBuilder line : lines) {
|
||||
BaseLineStringBuilder.decompose(FACTORY, line.coordinates(false), parts);
|
||||
}
|
||||
if(parts.size() == 1) {
|
||||
|
@ -91,7 +84,7 @@ public class MultiLineStringBuilder extends ShapeBuilder {
|
|||
}
|
||||
} else {
|
||||
LineString[] lineStrings = new LineString[lines.size()];
|
||||
Iterator<BaseLineStringBuilder<?>> iterator = lines.iterator();
|
||||
Iterator<LineStringBuilder> iterator = lines.iterator();
|
||||
for (int i = 0; iterator.hasNext(); i++) {
|
||||
lineStrings[i] = FACTORY.createLineString(iterator.next().coordinates(false));
|
||||
}
|
||||
|
@ -99,27 +92,4 @@ public class MultiLineStringBuilder extends ShapeBuilder {
|
|||
}
|
||||
return jtsGeometry(geometry);
|
||||
}
|
||||
|
||||
public static class InternalLineStringBuilder extends BaseLineStringBuilder<InternalLineStringBuilder> {
|
||||
|
||||
private final MultiLineStringBuilder collection;
|
||||
|
||||
public InternalLineStringBuilder(MultiLineStringBuilder collection) {
|
||||
super();
|
||||
this.collection = collection;
|
||||
}
|
||||
|
||||
public MultiLineStringBuilder end() {
|
||||
return collection;
|
||||
}
|
||||
|
||||
public Coordinate[] coordinates() {
|
||||
return super.coordinates(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeoShapeType type() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,16 +48,6 @@ public class MultiPolygonBuilder extends ShapeBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public InternalPolygonBuilder polygon() {
|
||||
return polygon(Orientation.RIGHT);
|
||||
}
|
||||
|
||||
public InternalPolygonBuilder polygon(Orientation orientation) {
|
||||
InternalPolygonBuilder polygon = new InternalPolygonBuilder(this, orientation);
|
||||
this.polygon(polygon);
|
||||
return polygon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
|
@ -100,20 +90,5 @@ public class MultiPolygonBuilder extends ShapeBuilder {
|
|||
//note: ShapeCollection is probably faster than a Multi* geom.
|
||||
}
|
||||
|
||||
public static class InternalPolygonBuilder extends BasePolygonBuilder<InternalPolygonBuilder> {
|
||||
|
||||
private final MultiPolygonBuilder collection;
|
||||
|
||||
private InternalPolygonBuilder(MultiPolygonBuilder collection, Orientation orientation) {
|
||||
super(orientation);
|
||||
this.collection = collection;
|
||||
this.shell = new Ring<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiPolygonBuilder close() {
|
||||
super.close();
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class PolygonBuilder extends BasePolygonBuilder<PolygonBuilder> {
|
|||
|
||||
protected PolygonBuilder(ArrayList<Coordinate> points, Orientation orientation) {
|
||||
super(orientation);
|
||||
this.shell = new Ring<>(this, points);
|
||||
this.shell = new LineStringBuilder(points);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -444,7 +444,7 @@ public abstract class ShapeBuilder extends ToXContentToBytes {
|
|||
* number of points
|
||||
* @return Array of edges
|
||||
*/
|
||||
protected static Edge[] ring(int component, boolean direction, boolean handedness, BaseLineStringBuilder<?> shell,
|
||||
protected static Edge[] ring(int component, boolean direction, boolean handedness, BaseLineStringBuilder shell,
|
||||
Coordinate[] points, int offset, Edge[] edges, int toffset, int length) {
|
||||
// calculate the direction of the points:
|
||||
// find the point a the top of the set and check its
|
||||
|
|
|
@ -29,14 +29,12 @@ import org.apache.lucene.search.Query;
|
|||
import org.apache.lucene.search.Scorer;
|
||||
import org.apache.lucene.search.TwoPhaseIterator;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.util.Bits;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.geo.GeoDistance;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.unit.DistanceUnit;
|
||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||
import org.elasticsearch.index.fielddata.MultiGeoPointValues;
|
||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
|
||||
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapperLegacy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.vividsolutions.jts.geom.Coordinate;
|
|||
import com.vividsolutions.jts.geom.LineString;
|
||||
import com.vividsolutions.jts.geom.Polygon;
|
||||
|
||||
import org.elasticsearch.common.geo.builders.LineStringBuilder;
|
||||
import org.elasticsearch.common.geo.builders.PolygonBuilder;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilders;
|
||||
|
@ -141,35 +142,34 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
|
||||
public void testMultiLineString() {
|
||||
ShapeBuilders.newMultiLinestring()
|
||||
.linestring()
|
||||
.linestring(new LineStringBuilder()
|
||||
.point(-100.0, 50.0)
|
||||
.point(50.0, 50.0)
|
||||
.point(50.0, 20.0)
|
||||
.point(-100.0, 20.0)
|
||||
.end()
|
||||
.linestring()
|
||||
)
|
||||
.linestring(new LineStringBuilder()
|
||||
.point(-100.0, 20.0)
|
||||
.point(50.0, 20.0)
|
||||
.point(50.0, 0.0)
|
||||
.point(-100.0, 0.0)
|
||||
.end()
|
||||
)
|
||||
.build();
|
||||
|
||||
|
||||
// LineString that needs to be wrappped
|
||||
ShapeBuilders.newMultiLinestring()
|
||||
.linestring()
|
||||
.linestring(new LineStringBuilder()
|
||||
.point(150.0, 60.0)
|
||||
.point(200.0, 60.0)
|
||||
.point(200.0, 40.0)
|
||||
.point(150.0, 40.0)
|
||||
.end()
|
||||
.linestring()
|
||||
)
|
||||
.linestring(new LineStringBuilder()
|
||||
.point(150.0, 20.0)
|
||||
.point(200.0, 20.0)
|
||||
.point(200.0, 0.0)
|
||||
.point(150.0, 0.0)
|
||||
.end()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(174,0);
|
||||
|
||||
// 3/4 of an embedded 'c', crossing dateline once
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(175, 1)
|
||||
.point(175, 7)
|
||||
.point(-178, 7)
|
||||
|
@ -260,15 +260,15 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(176, 2)
|
||||
.point(179, 2)
|
||||
.point(179,1)
|
||||
.point(175, 1);
|
||||
.point(175, 1));
|
||||
|
||||
// embedded hole right of the dateline
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(-179, 1)
|
||||
.point(-179, 2)
|
||||
.point(-177, 2)
|
||||
.point(-177,1)
|
||||
.point(-179,1);
|
||||
.point(-179,1));
|
||||
|
||||
Shape shape = builder.close().build();
|
||||
assertMultiPolygon(shape);
|
||||
|
@ -292,7 +292,7 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(-186,0);
|
||||
|
||||
// 3/4 of an embedded 'c', crossing dateline once
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(-185,1)
|
||||
.point(-181,1)
|
||||
.point(-181,2)
|
||||
|
@ -301,15 +301,15 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(-178,6)
|
||||
.point(-178,7)
|
||||
.point(-185,7)
|
||||
.point(-185,1);
|
||||
.point(-185,1));
|
||||
|
||||
// embedded hole right of the dateline
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(-179,1)
|
||||
.point(-177,1)
|
||||
.point(-177,2)
|
||||
.point(-179,2)
|
||||
.point(-179,1);
|
||||
.point(-179,1));
|
||||
|
||||
Shape shape = builder.close().build();
|
||||
assertMultiPolygon(shape);
|
||||
|
@ -356,7 +356,7 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(-85.0016455,37.1310491)
|
||||
.point(-85.0018514,37.1311314);
|
||||
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(-85.0000002,37.1317672)
|
||||
.point(-85.0001983,37.1317538)
|
||||
.point(-85.0003378,37.1317582)
|
||||
|
@ -382,7 +382,7 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(-84.9993527,37.1317788)
|
||||
.point(-84.9994931,37.1318061)
|
||||
.point(-84.9996815,37.1317979)
|
||||
.point(-85.0000002,37.1317672);
|
||||
.point(-85.0000002,37.1317672));
|
||||
|
||||
Shape shape = builder.close().build();
|
||||
assertPolygon(shape);
|
||||
|
@ -398,12 +398,12 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(-6, 0)
|
||||
.point(-4, 2);
|
||||
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(4, 1)
|
||||
.point(4, -1)
|
||||
.point(-4, -1)
|
||||
.point(-4, 1)
|
||||
.point(4, 1);
|
||||
.point(4, 1));
|
||||
|
||||
Shape shape = builder.close().build();
|
||||
assertPolygon(shape);
|
||||
|
@ -451,12 +451,12 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(176, -15)
|
||||
.point(-177, -10)
|
||||
.point(-177, 10);
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(176, 10)
|
||||
.point(180, 5)
|
||||
.point(180, -5)
|
||||
.point(176, -10)
|
||||
.point(176, 10);
|
||||
.point(176, 10));
|
||||
Shape shape = builder.close().build();
|
||||
assertMultiPolygon(shape);
|
||||
|
||||
|
@ -467,12 +467,12 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(179, -10)
|
||||
.point(-176, -15)
|
||||
.point(-172, 0);
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(-176, 10)
|
||||
.point(-176, -10)
|
||||
.point(-180, -5)
|
||||
.point(-180, 5)
|
||||
.point(-176, 10);
|
||||
.point(-176, 10));
|
||||
shape = builder.close().build();
|
||||
assertMultiPolygon(shape);
|
||||
}
|
||||
|
@ -486,12 +486,12 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(166, -15)
|
||||
.point(179, -10)
|
||||
.point(179, 10);
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(-177, 10)
|
||||
.point(-178, -10)
|
||||
.point(-180, -5)
|
||||
.point(-180, 5)
|
||||
.point(-177, 10);
|
||||
.point(-177, 10));
|
||||
Shape shape = builder.close().build();
|
||||
assertMultiPolygon(shape);
|
||||
}
|
||||
|
@ -505,12 +505,12 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(166, -15)
|
||||
.point(179, -10)
|
||||
.point(179, 10);
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(164, 0)
|
||||
.point(175, 10)
|
||||
.point(175, 5)
|
||||
.point(179, -10)
|
||||
.point(164, 0);
|
||||
.point(164, 0));
|
||||
try {
|
||||
builder.close().build();
|
||||
fail("Expected InvalidShapeException");
|
||||
|
@ -528,17 +528,17 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(176, -15)
|
||||
.point(-177, -10)
|
||||
.point(-177, 10);
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(-177, 10)
|
||||
.point(-178, -10)
|
||||
.point(-180, -5)
|
||||
.point(-180, 5)
|
||||
.point(-177, 10);
|
||||
builder.hole()
|
||||
.point(-177, 10));
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(172, 0)
|
||||
.point(176, 10)
|
||||
.point(176, -5)
|
||||
.point(172, 0);
|
||||
.point(172, 0));
|
||||
Shape shape = builder.close().build();
|
||||
assertMultiPolygon(shape);
|
||||
}
|
||||
|
@ -552,12 +552,12 @@ public class ShapeBuilderTests extends ESTestCase {
|
|||
.point(176, -15)
|
||||
.point(-177, -10)
|
||||
.point(-177, 10);
|
||||
builder.hole()
|
||||
builder.hole(new LineStringBuilder()
|
||||
.point(-177, 10)
|
||||
.point(172, 0)
|
||||
.point(180, -5)
|
||||
.point(176, -10)
|
||||
.point(-177, 10);
|
||||
.point(-177, 10));
|
||||
try {
|
||||
builder.close().build();
|
||||
fail("Expected InvalidShapeException");
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.elasticsearch.common.Priority;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.geo.GeoUtils;
|
||||
import org.elasticsearch.common.geo.builders.LineStringBuilder;
|
||||
import org.elasticsearch.common.geo.builders.MultiPolygonBuilder;
|
||||
import org.elasticsearch.common.geo.builders.PolygonBuilder;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilders;
|
||||
|
@ -129,17 +129,17 @@ public class GeoFilterIT extends ESIntegTestCase {
|
|||
// polygon with hole
|
||||
ShapeBuilders.newPolygon()
|
||||
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10)
|
||||
.hole()
|
||||
.hole(new LineStringBuilder()
|
||||
.point(-5, -5).point(-5, 5).point(5, 5).point(5, -5)
|
||||
.close().close().build();
|
||||
.close()).close().build();
|
||||
|
||||
try {
|
||||
// polygon with overlapping hole
|
||||
ShapeBuilders.newPolygon()
|
||||
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10)
|
||||
.hole()
|
||||
.hole(new LineStringBuilder()
|
||||
.point(-5, -5).point(-5, 11).point(5, 11).point(5, -5)
|
||||
.close().close().build();
|
||||
.close()).close().build();
|
||||
|
||||
fail("Self intersection not detected");
|
||||
} catch (InvalidShapeException e) {
|
||||
|
@ -149,12 +149,12 @@ public class GeoFilterIT extends ESIntegTestCase {
|
|||
// polygon with intersection holes
|
||||
ShapeBuilders.newPolygon()
|
||||
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10)
|
||||
.hole()
|
||||
.hole(new LineStringBuilder()
|
||||
.point(-5, -5).point(-5, 5).point(5, 5).point(5, -5)
|
||||
.close()
|
||||
.hole()
|
||||
.close())
|
||||
.hole(new LineStringBuilder()
|
||||
.point(-5, -6).point(5, -6).point(5, -4).point(-5, -4)
|
||||
.close()
|
||||
.close())
|
||||
.close().build();
|
||||
fail("Intersection of holes not detected");
|
||||
} catch (InvalidShapeException e) {
|
||||
|
@ -175,52 +175,27 @@ public class GeoFilterIT extends ESIntegTestCase {
|
|||
} catch (InvalidShapeException e) {
|
||||
}
|
||||
|
||||
// Not specified
|
||||
// try {
|
||||
// // two overlapping polygons within a multipolygon
|
||||
// ShapeBuilder.newMultiPolygon()
|
||||
// .polygon()
|
||||
// .point(-10, -10)
|
||||
// .point(-10, 10)
|
||||
// .point(10, 10)
|
||||
// .point(10, -10)
|
||||
// .close()
|
||||
// .polygon()
|
||||
// .point(-5, -5).point(-5, 5).point(5, 5).point(5, -5)
|
||||
// .close().build();
|
||||
// fail("Polygon intersection not detected";
|
||||
// } catch (InvalidShapeException e) {}
|
||||
|
||||
// Multipolygon: polygon with hole and polygon within the whole
|
||||
ShapeBuilders.newMultiPolygon()
|
||||
.polygon()
|
||||
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10)
|
||||
.hole()
|
||||
.point(-5, -5).point(-5, 5).point(5, 5).point(5, -5)
|
||||
.close()
|
||||
.close()
|
||||
.polygon()
|
||||
.point(-4, -4).point(-4, 4).point(4, 4).point(4, -4)
|
||||
.close()
|
||||
ShapeBuilders
|
||||
.newMultiPolygon()
|
||||
.polygon(new PolygonBuilder()
|
||||
.point(-10, -10)
|
||||
.point(-10, 10)
|
||||
.point(10, 10)
|
||||
.point(10, -10)
|
||||
.hole(new LineStringBuilder().point(-5, -5)
|
||||
.point(-5, 5)
|
||||
.point(5, 5)
|
||||
.point(5, -5)
|
||||
.close())
|
||||
.close())
|
||||
.polygon(new PolygonBuilder()
|
||||
.point(-4, -4)
|
||||
.point(-4, 4)
|
||||
.point(4, 4)
|
||||
.point(4, -4)
|
||||
.close())
|
||||
.build();
|
||||
|
||||
// Not supported
|
||||
// try {
|
||||
// // Multipolygon: polygon with hole and polygon within the hole but overlapping
|
||||
// ShapeBuilder.newMultiPolygon()
|
||||
// .polygon()
|
||||
// .point(-10, -10).point(-10, 10).point(10, 10).point(10, -10)
|
||||
// .hole()
|
||||
// .point(-5, -5).point(-5, 5).point(5, 5).point(5, -5)
|
||||
// .close()
|
||||
// .close()
|
||||
// .polygon()
|
||||
// .point(-4, -4).point(-4, 6).point(4, 6).point(4, -4)
|
||||
// .close()
|
||||
// .build();
|
||||
// fail("Polygon intersection not detected";
|
||||
// } catch (InvalidShapeException e) {}
|
||||
|
||||
}
|
||||
|
||||
public void testShapeRelations() throws Exception {
|
||||
|
@ -248,15 +223,13 @@ public class GeoFilterIT extends ESIntegTestCase {
|
|||
// with a hole of size 5x5 equidistant from all sides. This hole in turn contains
|
||||
// the second polygon of size 4x4 equidistant from all sites
|
||||
MultiPolygonBuilder polygon = ShapeBuilders.newMultiPolygon()
|
||||
.polygon()
|
||||
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10)
|
||||
.hole()
|
||||
.point(-5, -5).point(-5, 5).point(5, 5).point(5, -5)
|
||||
.close()
|
||||
.close()
|
||||
.polygon()
|
||||
.point(-4, -4).point(-4, 4).point(4, 4).point(4, -4)
|
||||
.close();
|
||||
.polygon(new PolygonBuilder()
|
||||
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10)
|
||||
.hole(new LineStringBuilder()
|
||||
.point(-5, -5).point(-5, 5).point(5, 5).point(5, -5).close())
|
||||
.close())
|
||||
.polygon(new PolygonBuilder()
|
||||
.point(-4, -4).point(-4, 4).point(4, 4).point(4, -4).close());
|
||||
|
||||
BytesReference data = jsonBuilder().startObject().field("area", polygon).endObject().bytes();
|
||||
|
||||
|
@ -318,9 +291,8 @@ public class GeoFilterIT extends ESIntegTestCase {
|
|||
// Create a polygon that fills the empty area of the polygon defined above
|
||||
PolygonBuilder inverse = ShapeBuilders.newPolygon()
|
||||
.point(-5, -5).point(-5, 5).point(5, 5).point(5, -5)
|
||||
.hole()
|
||||
.point(-4, -4).point(-4, 4).point(4, 4).point(4, -4)
|
||||
.close()
|
||||
.hole(new LineStringBuilder()
|
||||
.point(-4, -4).point(-4, 4).point(4, 4).point(4, -4).close())
|
||||
.close();
|
||||
|
||||
data = jsonBuilder().startObject().field("area", inverse).endObject().bytes();
|
||||
|
@ -338,9 +310,8 @@ public class GeoFilterIT extends ESIntegTestCase {
|
|||
// Create Polygon with hole and common edge
|
||||
PolygonBuilder builder = ShapeBuilders.newPolygon()
|
||||
.point(-10, -10).point(-10, 10).point(10, 10).point(10, -10)
|
||||
.hole()
|
||||
.point(-5, -5).point(-5, 5).point(10, 5).point(10, -5)
|
||||
.close()
|
||||
.hole(new LineStringBuilder()
|
||||
.point(-5, -5).point(-5, 5).point(10, 5).point(10, -5).close())
|
||||
.close();
|
||||
|
||||
if (withinSupport) {
|
||||
|
@ -367,7 +338,7 @@ public class GeoFilterIT extends ESIntegTestCase {
|
|||
// Create a polygon crossing longitude 180 with hole.
|
||||
builder = ShapeBuilders.newPolygon()
|
||||
.point(170, -10).point(190, -10).point(190, 10).point(170, 10)
|
||||
.hole().point(175, -5).point(185, -5).point(185, 5).point(175, 5).close()
|
||||
.hole(new LineStringBuilder().point(175, -5).point(185, -5).point(185, 5).point(175, 5).close())
|
||||
.close();
|
||||
|
||||
data = jsonBuilder().startObject().field("area", builder).endObject().bytes();
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.action.search.SearchResponse;
|
|||
import org.elasticsearch.common.geo.ShapeRelation;
|
||||
import org.elasticsearch.common.geo.builders.EnvelopeBuilder;
|
||||
import org.elasticsearch.common.geo.builders.GeometryCollectionBuilder;
|
||||
import org.elasticsearch.common.geo.builders.LineStringBuilder;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilders;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -193,7 +194,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
|
|||
public void testReusableBuilder() throws IOException {
|
||||
ShapeBuilder polygon = ShapeBuilders.newPolygon()
|
||||
.point(170, -10).point(190, -10).point(190, 10).point(170, 10)
|
||||
.hole().point(175, -5).point(185, -5).point(185, 5).point(175, 5).close()
|
||||
.hole(new LineStringBuilder().point(175, -5).point(185, -5).point(185, 5).point(175, 5).close())
|
||||
.close();
|
||||
assertUnmodified(polygon);
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ import com.vividsolutions.jts.geom.Coordinate;
|
|||
import com.vividsolutions.jts.geom.Geometry;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.geo.builders.BaseLineStringBuilder;
|
||||
import org.elasticsearch.common.geo.builders.GeometryCollectionBuilder;
|
||||
import org.elasticsearch.common.geo.builders.LineStringBuilder;
|
||||
import org.elasticsearch.common.geo.builders.MultiLineStringBuilder;
|
||||
|
@ -198,7 +197,7 @@ public class RandomShapeGenerator extends RandomGeoGenerator {
|
|||
case MULTILINESTRING:
|
||||
MultiLineStringBuilder mlsb = new MultiLineStringBuilder();
|
||||
for (int i=0; i<RandomInts.randomIntBetween(r, 1, 10); ++i) {
|
||||
mlsb.linestring((BaseLineStringBuilder) createShape(r, nearPoint, within, ShapeType.LINESTRING, false));
|
||||
mlsb.linestring((LineStringBuilder) createShape(r, nearPoint, within, ShapeType.LINESTRING, false));
|
||||
}
|
||||
return mlsb;
|
||||
case POLYGON:
|
||||
|
|
Loading…
Reference in New Issue