use of org.locationtech.spatial4j.shape.Shape in project ddf by codice.
the class GeoNamesQueryLuceneDirectoryIndex method getCountryCode.
@Override
public Optional<String> getCountryCode(String wktLocation, int radius) throws GeoEntryQueryException, ParseException {
final Directory directory = openDirectoryAndCheckForIndex();
Shape shape = getShape(wktLocation);
String countryCode = doGetCountryCode(shape, radius, directory);
return Optional.ofNullable(countryCode);
}
use of org.locationtech.spatial4j.shape.Shape in project ddf by codice.
the class GeoNamesWebService method createPointFromWkt.
Point createPointFromWkt(String wkt) {
try {
JtsSpatialContextFactory contextFactory = new JtsSpatialContextFactory();
contextFactory.allowMultiOverlap = true;
SpatialContext spatialContext = contextFactory.newSpatialContext();
Shape shape = (Shape) spatialContext.readShapeFromWkt(wkt);
Point center = shape.getCenter();
return center;
} catch (java.text.ParseException parseException) {
LOGGER.debug(parseException.getMessage(), parseException);
}
return null;
}
use of org.locationtech.spatial4j.shape.Shape in project ddf by codice.
the class TestGeoNamesQueryLuceneIndex method testDoGetCountryCodeNullShape.
@Test(expected = IllegalArgumentException.class)
public void testDoGetCountryCodeNullShape() throws GeoEntryQueryException {
Shape shape = null;
directoryIndex.doGetCountryCode(shape, 10, null);
}
use of org.locationtech.spatial4j.shape.Shape in project ddf by codice.
the class TestGeoNamesQueryLuceneIndex method testDoGetCountryCodeNullLuceneDirectory.
@Test(expected = IllegalArgumentException.class)
public void testDoGetCountryCodeNullLuceneDirectory() throws GeoEntryQueryException {
Shape shape = mock(Shape.class);
Directory directory = null;
directoryIndex.doGetCountryCode(shape, 10, directory);
}
use of org.locationtech.spatial4j.shape.Shape 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());
}
Aggregations