use of org.locationtech.spatial4j.shape.Point in project crate by crate.
the class GeoPointTypeTest method testConversionFromObjectArrayOfIntegers.
@Test
public void testConversionFromObjectArrayOfIntegers() throws Exception {
Point value = DataTypes.GEO_POINT.implicitCast(new Object[] { 1, 2 });
assertThat(value.getX(), is(1.0));
assertThat(value.getY(), is(2.0));
}
use of org.locationtech.spatial4j.shape.Point in project ddf by codice.
the class GeoNamesWebService method getCountryCode.
@Override
public Optional<String> getCountryCode(String locationWkt, int radius) {
notNull(locationWkt, "argument locationWkt may not be null");
Point wktCenterPoint = createPointFromWkt(locationWkt);
String urlStr = String.format("%s://%s/countryCode?lat=%f&lng=%f&radius=%d&type=JSON&username=%s", GEONAMES_PROTOCOL, GEONAMES_API_ADDRESS, wktCenterPoint.getY(), wktCenterPoint.getX(), radius, USERNAME);
Object result = webQuery(urlStr);
if (result instanceof JSONObject) {
JSONObject jsonResult = (JSONObject) result;
Object countryCode = jsonResult.get(GEONAMES_COUNTRYCODE);
if (countryCode != null) {
String alpha2CountryCode = (String) countryCode;
if (StringUtils.isNotEmpty(alpha2CountryCode)) {
try {
String alpha3CountryCode = new Locale(Locale.ENGLISH.getLanguage(), alpha2CountryCode).getISO3Country();
return Optional.of(alpha3CountryCode);
} catch (MissingResourceException e) {
LOGGER.debug("Failed to convert country code {} to alpha-3 format. Returning " + "empty value", alpha2CountryCode);
}
}
}
}
return Optional.empty();
}
use of org.locationtech.spatial4j.shape.Point in project ddf by codice.
the class NearbyLocationImplTest method testNearbyLocationImpl.
@Test
public void testNearbyLocationImpl() {
final Point source = new PointImpl(50, 50, SpatialContext.GEO);
final Point nearby = new PointImpl(50.5, 50.5, SpatialContext.GEO);
final NearbyLocation nearbyLocation = new NearbyLocationImpl(source, nearby, "Nearby");
assertThat(nearbyLocation.getCardinalDirection(), is("SW"));
// This distance value was obtained from http://www.movable-type.co.uk/scripts/latlong.html
String expected = NumberFormat.getNumberInstance(Locale.getDefault()).format(65.99);
assertThat(String.format("%.2f", nearbyLocation.getDistance()), is(expected));
assertThat(nearbyLocation.getName(), is("Nearby"));
}
use of org.locationtech.spatial4j.shape.Point in project elasticsearch by elastic.
the class GeoDistanceQueryBuilderTests method doCreateTestQueryBuilder.
@Override
protected GeoDistanceQueryBuilder doCreateTestQueryBuilder() {
GeoDistanceQueryBuilder qb = new GeoDistanceQueryBuilder(GEO_POINT_FIELD_NAME);
String distance = "" + randomDouble();
if (randomBoolean()) {
DistanceUnit unit = randomFrom(DistanceUnit.values());
distance = distance + unit.toString();
}
int selector = randomIntBetween(0, 2);
switch(selector) {
case 0:
qb.distance(randomDouble(), randomFrom(DistanceUnit.values()));
break;
case 1:
qb.distance(distance, randomFrom(DistanceUnit.values()));
break;
case 2:
qb.distance(distance);
break;
}
Point p = RandomShapeGenerator.xRandomPoint(random());
qb.point(new GeoPoint(p.getY(), p.getX()));
if (randomBoolean()) {
qb.setValidationMethod(randomFrom(GeoValidationMethod.values()));
}
if (randomBoolean()) {
qb.geoDistance(randomFrom(GeoDistance.values()));
}
if (randomBoolean()) {
qb.ignoreUnmapped(randomBoolean());
}
return qb;
}
use of org.locationtech.spatial4j.shape.Point in project elasticsearch by elastic.
the class ShapeBuilderTests method testNewPoint.
public void testNewPoint() {
Point point = ShapeBuilders.newPoint(-100, 45).build();
assertEquals(-100D, point.getX(), 0.0d);
assertEquals(45D, point.getY(), 0.0d);
}
Aggregations