use of org.locationtech.spatial4j.shape.impl.PointImpl in project ddf by codice.
the class GazetteerQueryCatalog method transformMetacardToNearbyLocation.
private NearbyLocation transformMetacardToNearbyLocation(String location, Metacard metacard) {
String metacardLocation = getStringAttributeFromMetacard(metacard, Core.LOCATION);
String name = getStringAttributeFromMetacard(metacard, Core.TITLE);
if (StringUtils.isEmpty(metacardLocation) || StringUtils.isEmpty(name)) {
LOGGER.debug("GeoEntry metacard does not contain required attribute.");
return null;
}
Double lat;
Double lon;
PointImpl centerPoint;
try {
Geometry geometry = WKT_READER_THREAD_LOCAL.get().read(metacardLocation);
Coordinate coordinate = geometry.getCoordinate();
lat = coordinate.x;
lon = coordinate.y;
Point center = WKT_READER_THREAD_LOCAL.get().read(location).getCentroid();
centerPoint = new PointImpl(center.getY(), center.getX(), SPATIAL_CONTEXT);
} catch (org.locationtech.jts.io.ParseException e) {
LOGGER.debug("GeoEntry metacard does not contain location attribute.");
return null;
}
return new NearbyLocationImpl(centerPoint, new PointImpl(lon, lat, SPATIAL_CONTEXT), name);
}
use of org.locationtech.spatial4j.shape.impl.PointImpl 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.impl.PointImpl in project crate by crate.
the class PointType method decodeUTF8Text.
@Override
Point decodeUTF8Text(byte[] bytes) {
String value = new String(bytes, StandardCharsets.UTF_8);
StringTokenizer tokenizer = new StringTokenizer(value, ",()");
double x;
double y;
if (tokenizer.hasMoreTokens()) {
x = Double.parseDouble(tokenizer.nextToken());
} else {
throw new IllegalArgumentException("Cannot parse input as point: " + value + " expected a point in format: (x, y)");
}
if (tokenizer.hasMoreTokens()) {
y = Double.parseDouble(tokenizer.nextToken());
} else {
throw new IllegalArgumentException("Cannot parse input as point: " + value + " expected a point in format: (x, y)");
}
return new PointImpl(x, y, JtsSpatialContext.GEO);
}
Aggregations