use of org.opensearch.geometry.Point in project OpenSearch by opensearch-project.
the class WellKnownText method parsePoint.
private Point parsePoint(StreamTokenizer stream) throws IOException, ParseException {
if (nextEmptyOrOpen(stream).equals(EMPTY)) {
return Point.EMPTY;
}
double lon = nextNumber(stream);
double lat = nextNumber(stream);
Point pt;
if (isNumberNext(stream)) {
pt = new Point(lon, lat, nextNumber(stream));
} else {
pt = new Point(lon, lat);
}
nextCloser(stream);
return pt;
}
use of org.opensearch.geometry.Point in project OpenSearch by opensearch-project.
the class WellKnownText method parseMultiPoint.
private MultiPoint parseMultiPoint(StreamTokenizer stream) throws IOException, ParseException {
String token = nextEmptyOrOpen(stream);
if (token.equals(EMPTY)) {
return MultiPoint.EMPTY;
}
ArrayList<Double> lats = new ArrayList<>();
ArrayList<Double> lons = new ArrayList<>();
ArrayList<Double> alts = new ArrayList<>();
ArrayList<Point> points = new ArrayList<>();
parseCoordinates(stream, lats, lons, alts);
for (int i = 0; i < lats.size(); i++) {
if (alts.isEmpty()) {
points.add(new Point(lons.get(i), lats.get(i)));
} else {
points.add(new Point(lons.get(i), lats.get(i), alts.get(i)));
}
}
return new MultiPoint(Collections.unmodifiableList(points));
}
use of org.opensearch.geometry.Point in project OpenSearch by opensearch-project.
the class Geohash method toBoundingBox.
/**
* Computes the bounding box coordinates from a given geohash
*
* @param geohash Geohash of the defined cell
* @return GeoRect rectangle defining the bounding box
*/
public static Rectangle toBoundingBox(final String geohash) {
// bottom left is the coordinate
Point bottomLeft = toPoint(geohash);
int len = Math.min(12, geohash.length());
long ghLong = longEncode(geohash, len);
// shift away the level
ghLong >>>= 4;
// deinterleave
long lon = BitUtil.deinterleave(ghLong >>> 1);
long lat = BitUtil.deinterleave(ghLong);
final int shift = (12 - len) * 5 + 2;
if (lat < MAX_LAT_BITS) {
// add 1 to lat and lon to get topRight
ghLong = BitUtil.interleave((int) (lat + 1), (int) (lon + 1)) << 4 | len;
final long mortonHash = BitUtil.flipFlop((ghLong >>> 4) << shift);
Point topRight = new Point(decodeLongitude(mortonHash), decodeLatitude(mortonHash));
return new Rectangle(bottomLeft.getX(), topRight.getX(), topRight.getY(), bottomLeft.getY());
} else {
// We cannot go north of north pole, so just using 90 degrees instead of calculating it using
// add 1 to lon to get lon of topRight, we are going to use 90 for lat
ghLong = BitUtil.interleave((int) lat, (int) (lon + 1)) << 4 | len;
final long mortonHash = BitUtil.flipFlop((ghLong >>> 4) << shift);
Point topRight = new Point(decodeLongitude(mortonHash), decodeLatitude(mortonHash));
return new Rectangle(bottomLeft.getX(), topRight.getX(), 90D, bottomLeft.getY());
}
}
use of org.opensearch.geometry.Point in project OpenSearch by opensearch-project.
the class GeoJsonParserTests method testParsePoint.
@Override
public void testParsePoint() throws IOException {
XContentBuilder pointGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Point").startArray("coordinates").value(100.0).value(0.0).endArray().endObject();
Point expected = new Point(100.0, 0.0);
assertGeometryEquals(expected, pointGeoJson);
}
use of org.opensearch.geometry.Point in project OpenSearch by opensearch-project.
the class GeoJsonParserTests method testThatParserExtractsCorrectTypeAndCoordinatesFromArbitraryJson.
public void testThatParserExtractsCorrectTypeAndCoordinatesFromArbitraryJson() throws IOException, ParseException {
XContentBuilder pointGeoJson = XContentFactory.jsonBuilder().startObject().startObject("crs").field("type", "name").startObject("properties").field("name", "urn:ogc:def:crs:OGC:1.3:CRS84").endObject().endObject().field("bbox", "foobar").field("type", "point").field("bubu", "foobar").startArray("coordinates").value(100.0).value(0.0).endArray().startObject("nested").startArray("coordinates").value(200.0).value(0.0).endArray().endObject().startObject("lala").field("type", "NotAPoint").endObject().endObject();
Point expectedPt = new Point(100, 0);
assertGeometryEquals(expectedPt, pointGeoJson, false);
}
Aggregations