use of org.locationtech.spatial4j.shape.Point in project crate by crate.
the class WherePKIntegrationTest method testEmptyClusteredByExplicit.
@Test
public void testEmptyClusteredByExplicit() throws Exception {
// regression test that empty routing executes correctly
execute("create table explicit_routing (" + " location geo_point, " + " name string " + ") clustered by (name) with (number_of_replicas=0)");
ensureYellow();
execute("insert into explicit_routing (name, location) values (',', [36.567, 52.998]), ('Dornbirn', [54.45, 4.567])");
execute("refresh table explicit_routing");
execute("select * from explicit_routing where name=''");
assertThat(response.cols(), is(arrayContaining("location", "name")));
assertThat(response.rowCount(), is(0L));
execute("select * from explicit_routing where name=','");
assertThat(response.cols(), is(arrayContaining("location", "name")));
assertThat(response.rowCount(), is(1L));
Point point = (Point) response.rows()[0][0];
assertThat(point.getX(), Matchers.closeTo(36.567d, 0.01));
assertThat(point.getY(), Matchers.closeTo(52.998d, 0.01));
}
use of org.locationtech.spatial4j.shape.Point in project crate by crate.
the class ServerXContentExtension method getXContentWriters.
@Override
public Map<Class<?>, XContentBuilder.Writer> getXContentWriters() {
Map<Class<?>, XContentBuilder.Writer> writers = new HashMap<>();
// Fully-qualified here to reduce ambiguity around our (ES') Version class
writers.put(org.apache.lucene.util.Version.class, (b, v) -> b.value(Objects.toString(v)));
writers.put(DateTimeZone.class, (b, v) -> b.value(Objects.toString(v)));
writers.put(CachedDateTimeZone.class, (b, v) -> b.value(Objects.toString(v)));
writers.put(FixedDateTimeZone.class, (b, v) -> b.value(Objects.toString(v)));
writers.put(MutableDateTime.class, XContentBuilder::timeValue);
writers.put(DateTime.class, XContentBuilder::timeValue);
writers.put(TimeValue.class, (b, v) -> b.value(v.toString()));
writers.put(ZonedDateTime.class, XContentBuilder::timeValue);
writers.put(OffsetDateTime.class, XContentBuilder::timeValue);
writers.put(OffsetTime.class, XContentBuilder::timeValue);
writers.put(java.time.Instant.class, XContentBuilder::timeValue);
writers.put(LocalDateTime.class, XContentBuilder::timeValue);
writers.put(LocalDate.class, XContentBuilder::timeValue);
writers.put(LocalTime.class, XContentBuilder::timeValue);
writers.put(DayOfWeek.class, (b, v) -> b.value(v.toString()));
writers.put(Month.class, (b, v) -> b.value(v.toString()));
writers.put(MonthDay.class, (b, v) -> b.value(v.toString()));
writers.put(Year.class, (b, v) -> b.value(v.toString()));
writers.put(Duration.class, (b, v) -> b.value(v.toString()));
writers.put(Period.class, (b, v) -> b.value(v.toString()));
writers.put(org.joda.time.Period.class, (b, v) -> {
org.joda.time.Period period = (org.joda.time.Period) v;
b.value(IntervalType.PERIOD_FORMATTER.print(period));
});
writers.put(BytesReference.class, (b, v) -> {
if (v == null) {
b.nullValue();
} else {
BytesRef bytes = ((BytesReference) v).toBytesRef();
b.value(bytes.bytes, bytes.offset, bytes.length);
}
});
writers.put(BytesRef.class, (b, v) -> {
if (v == null) {
b.nullValue();
} else {
BytesRef bytes = (BytesRef) v;
b.value(bytes.bytes, bytes.offset, bytes.length);
}
});
writers.put(Regproc.class, (b, v) -> b.value(((Regproc) v).name()));
writers.put(Regclass.class, (b, v) -> b.value(((Regclass) v).oid()));
writers.put(PointImpl.class, (b, v) -> {
Point point = (Point) v;
b.startArray();
b.value(point.getX());
b.value(point.getY());
b.endArray();
});
writers.put(JtsPoint.class, (b, v) -> {
Point point = (Point) v;
b.startArray();
b.value(point.getX());
b.value(point.getY());
b.endArray();
});
writers.put(RowN.class, (b, v) -> {
RowN row = (RowN) v;
b.startArray();
for (int i = 0; i < row.numColumns(); i++) {
b.value(row.get(i));
}
b.endArray();
});
writers.put(TimeTZ.class, (b, v) -> {
TimeTZ timetz = (TimeTZ) v;
b.startArray();
b.value(timetz.getMicrosFromMidnight());
b.value(timetz.getSecondsFromUTC());
b.endArray();
});
writers.put(BitString.class, (b, v) -> {
BitString bitString = (BitString) v;
b.value(bitString.asBitString());
});
return writers;
}
use of org.locationtech.spatial4j.shape.Point in project ddf by codice.
the class GeoNamesWebService method getNearestCities.
@Override
public List<NearbyLocation> getNearestCities(String locationWkt, int radiusInKm, int maxResults) throws java.text.ParseException, GeoEntryQueryException {
notNull(locationWkt, "argument locationWkt may not be null");
Point wktCenterPoint = createPointFromWkt(locationWkt);
String urlStr = String.format("%s://%s/findNearbyPlaceNameJSON?lat=%f&lng=%f&maxRows=%d&radius=%d&username=%s&cities=cities5000", GEONAMES_PROTOCOL, GEONAMES_API_ADDRESS, wktCenterPoint.getY(), wktCenterPoint.getX(), limitMaxRows(maxResults), radiusInKm, USERNAME);
Object result = webQuery(urlStr);
if (result instanceof JSONObject) {
JSONObject jsonResult = (JSONObject) result;
JSONArray geoNames = (JSONArray) jsonResult.get(GEONAMES_KEY);
if (geoNames != null) {
return geoNames.stream().map(JSONObject.class::cast).map(obj -> {
double lat = Double.parseDouble((String) obj.get(LAT_KEY));
double lon = Double.parseDouble((String) obj.get(LON_KEY));
String cityName = (String) obj.get(PLACENAME_KEY);
Point cityPoint = new PointImpl(lon, lat, SpatialContext.GEO);
return new NearbyLocationImpl(wktCenterPoint, cityPoint, cityName);
}).collect(toList());
}
}
return Collections.emptyList();
}
use of org.locationtech.spatial4j.shape.Point 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.Point in project ddf by codice.
the class GeoNamesWebServiceTest method testCreateGeoPointFromWkt.
@Test
public void testCreateGeoPointFromWkt() {
String pointWkt = CREATE_POINT_FROM_WKT_POINT;
Point p = webService.createPointFromWkt(pointWkt);
assertThat(p, notNullValue());
assertThat(p.getX(), equalTo(-1.0));
assertThat(p.getY(), equalTo(22.0));
String polygonWkt = CREATE_POINT_FROM_WKT_POLYGON;
p = webService.createPointFromWkt(polygonWkt);
assertThat(p, notNullValue());
}
Aggregations