use of org.locationtech.spatial4j.shape.Point in project janusgraph by JanusGraph.
the class GeoshapeHelper method getPoint.
@SuppressWarnings("unchecked")
public Geoshape.Point getPoint(Geoshape geoshape, int position) {
final Shape shape = geoshape.getShape();
final Point p;
if (position < 0 || position >= size(shape))
throw new ArrayIndexOutOfBoundsException("Invalid position: " + position);
switch(getType(shape)) {
case POINT:
case CIRCLE:
return geoshape.getPoint();
case BOX:
if (position == 0)
return new Geoshape.Point(shape.getBoundingBox().getMinY(), shape.getBoundingBox().getMinX());
else
return new Geoshape.Point(shape.getBoundingBox().getMaxY(), shape.getBoundingBox().getMaxX());
case LINE:
p = ((BufferedLineString) shape).getPoints().get(position);
break;
case MULTIPOINT:
p = ((ShapeCollection<Point>) shape).getShapes().get(position);
break;
case MULTILINESTRING:
p = ((ShapeCollection<BufferedLineString>) shape).getShapes().stream().flatMap(line -> line.getPoints().stream()).skip(position).findFirst().orElse(null);
break;
case GEOMETRYCOLLECTION:
return ((ShapeCollection<Shape>) shape).getShapes().stream().flatMap(internShape -> IntStream.range(0, size(internShape)).mapToObj(i -> new AbstractMap.SimpleImmutableEntry<>(internShape, i))).skip(position).findFirst().map(entry -> getPoint(new Geoshape(entry.getKey()), entry.getValue())).orElse(null);
default:
throw new IllegalStateException("getPoint(int) not supported for type: " + getType(shape));
}
if (p == null)
throw new ArrayIndexOutOfBoundsException("Invalid position: " + position);
return new Geoshape.Point(p.getY(), p.getX());
}
use of org.locationtech.spatial4j.shape.Point in project crate by crate.
the class GeoPointTypeTest method testStreaming.
@Test
public void testStreaming() throws Throwable {
Point p1 = new PointImpl(41.2, -37.4, JtsSpatialContext.GEO);
BytesStreamOutput out = new BytesStreamOutput();
DataTypes.GEO_POINT.writeValueTo(out, p1);
StreamInput in = out.bytes().streamInput();
Point p2 = DataTypes.GEO_POINT.readValueFrom(in);
assertThat(p1, equalTo(p2));
}
use of org.locationtech.spatial4j.shape.Point in project crate by crate.
the class GeoPointTypeTest method test_sanitize_list_of_doubles_value.
@Test
public void test_sanitize_list_of_doubles_value() {
Point value = DataTypes.GEO_POINT.sanitizeValue(List.of(1d, 2d));
assertThat(value.getX(), is(1.0d));
assertThat(value.getY(), is(2.0d));
}
use of org.locationtech.spatial4j.shape.Point in project crate by crate.
the class GeoPointTypeTest method testWktToGeoPointValue.
@Test
public void testWktToGeoPointValue() throws Exception {
Point value = DataTypes.GEO_POINT.implicitCast("POINT(1 2)");
assertThat(value.getX(), is(1.0d));
assertThat(value.getY(), is(2.0d));
}
use of org.locationtech.spatial4j.shape.Point in project crate by crate.
the class GeoPointTypeTest method testConversionFromIntegerArray.
@Test
public void testConversionFromIntegerArray() throws Exception {
Point value = DataTypes.GEO_POINT.implicitCast(new Integer[] { 1, 2 });
assertThat(value.getX(), is(1.0));
assertThat(value.getY(), is(2.0));
}
Aggregations