/** * Returns the radius in kilometers of this circle. Only applicable to circle shapes. * @return */ public float getRadius() { Preconditions.checkArgument(getType()==Type.CIRCLE,"This shape is not a circle"); return coordinates[1][1]; }
/** * Returns the number of points comprising this geoshape. A point and circle have only one point (center of cricle), * a box has two points (the south-west and north-east corners) and a polygon has a variable number of points (>=3). * * @return */ public int size() { switch(getType()) { case POINT: return 1; case CIRCLE: return 1; case BOX: return 2; case POLYGON: return coordinates[0].length; default: throw new IllegalStateException("Unrecognized type: " + getType()); } }
/** * {@link com.thinkaurelius.titan.core.attribute.Geoshape} stores Points in the String format: point[X.0,Y.0]. * Solr needs it to be in Well-Known Text format: POINT(X.0 Y.0) */ public static String convertToWktString(Geoshape fieldValue) throws BackendException { if (fieldValue.getType() == Geoshape.Type.POINT) { Geoshape.Point point = fieldValue.getPoint(); return "POINT(" + point.getLongitude() + " " + point.getLatitude() + ")"; } else { throw new PermanentBackendException("Cannot index " + fieldValue.getType()); } } }
private static Object convertToEsType(Object value) { if (value instanceof Number) { if (AttributeUtil.isWholeNumber((Number) value)) { return ((Number) value).longValue(); } else { //double or float return ((Number) value).doubleValue(); } } else if (AttributeUtil.isString(value)) { return value; } else if (value instanceof Geoshape) { Geoshape shape = (Geoshape) value; if (shape.getType() == Geoshape.Type.POINT) { Geoshape.Point p = shape.getPoint(); return new double[]{p.getLongitude(), p.getLatitude()}; } else throw new UnsupportedOperationException("Geo type is not supported: " + shape.getType()); } else if (value instanceof Date || value instanceof Instant) { return value; } else if (value instanceof Boolean) { return value; } else if (value instanceof UUID) { return value.toString(); } else throw new IllegalArgumentException("Unsupported type: " + value.getClass() + " (value: " + value + ")"); }
jgen.writeFieldName(FIELD_TYPE); switch(value.getType()) { case POLYGON: throw new UnsupportedOperationException("Polygons are not supported");
@Override public String toString() { Type type = getType(); StringBuilder s = new StringBuilder(); s.append(type.toString().toLowerCase()); switch (type) { case POINT: s.append(getPoint().toString()); break; case CIRCLE: s.append(getPoint().toString()).append(":").append(getRadius()); break; default: s.append("["); for (int i=0;i<size();i++) { if (i>0) s.append(","); s.append(getPoint(i)); } s.append("]"); } return s.toString(); }
/** * Converts this shape into its equivalent Spatial4j {@link Shape}. * @return */ public Shape convert2Spatial4j() { switch(getType()) { case POINT: return getPoint().getSpatial4jPoint(); case CIRCLE: return CTX.makeCircle(getPoint(0).getSpatial4jPoint(), DistanceUtils.dist2Degrees(getRadius(), DistanceUtils.EARTH_MEAN_RADIUS_KM)); case BOX: return CTX.makeRectangle(getPoint(0).getSpatial4jPoint(),getPoint(1).getSpatial4jPoint()); case POLYGON: throw new UnsupportedOperationException("Not yet supported"); default: throw new IllegalStateException("Unrecognized type: " + getType()); } }
if (geo.getType() == Geoshape.Type.CIRCLE) { Geoshape.Point center = geo.getPoint(); return ("{!geofilt sfield=" + key + " pt=" + center.getLatitude() + "," + center.getLongitude() + " d=" + geo.getRadius() + "} distErrPct=0"); //distance in kilometers } else if (geo.getType() == Geoshape.Type.BOX) { Geoshape.Point southwest = geo.getPoint(0); Geoshape.Point northeast = geo.getPoint(1); return (key + ":[" + southwest.getLatitude() + "," + southwest.getLongitude() + " TO " + northeast.getLatitude() + "," + northeast.getLongitude() + "]"); } else if (geo.getType() == Geoshape.Type.POLYGON) { List<Geoshape.Point> coordinates = getPolygonPoints(geo); StringBuilder poly = new StringBuilder(key + ":\"IsWithin(POLYGON((");
Preconditions.checkArgument(titanPredicate == Geo.WITHIN, "Relation is not supported for geo value: " + titanPredicate); Geoshape shape = (Geoshape) value; if (shape.getType() == Geoshape.Type.CIRCLE) { Geoshape.Point center = shape.getPoint(); return FilterBuilders.geoDistanceFilter(key).lat(center.getLatitude()).lon(center.getLongitude()).distance(shape.getRadius(), DistanceUnit.KILOMETERS); } else if (shape.getType() == Geoshape.Type.BOX) { Geoshape.Point southwest = shape.getPoint(0); Geoshape.Point northeast = shape.getPoint(1); return FilterBuilders.geoBoundingBoxFilter(key).bottomRight(southwest.getLatitude(), northeast.getLongitude()).topLeft(northeast.getLatitude(), southwest.getLongitude()); } else throw new IllegalArgumentException("Unsupported or invalid search shape type: " + shape.getType()); } else if (value instanceof Date || value instanceof Instant) { Preconditions.checkArgument(titanPredicate instanceof Cmp, "Relation not supported on date types: " + titanPredicate);
/** * Returns the radius in kilometers of this circle. Only applicable to circle shapes. * @return */ public float getRadius() { Preconditions.checkArgument(getType()==Type.CIRCLE,"This shape is not a circle"); return coordinates[1][1]; }
/** * Returns the number of points comprising this geoshape. A point and circle have only one point (center of cricle), * a box has two points (the south-west and north-east corners) and a polygon has a variable number of points (>=3). * * @return */ public int size() { switch(getType()) { case POINT: return 1; case CIRCLE: return 1; case BOX: return 2; case POLYGON: return coordinates[0].length; default: throw new IllegalStateException("Unrecognized type: " + getType()); } }
/** * Returns the number of points comprising this geoshape. A point and circle have only one point (center of cricle), * a box has two points (the south-west and north-east corners) and a polygon has a variable number of points (>=3). * * @return */ public int size() { switch(getType()) { case POINT: return 1; case CIRCLE: return 1; case BOX: return 2; case POLYGON: return coordinates[0].length; default: throw new IllegalStateException("Unrecognized type: " + getType()); } }
/** * Returns the radius in kilometers of this circle. Only applicable to circle shapes. * @return */ public float getRadius() { Preconditions.checkArgument(getType()==Type.CIRCLE,"This shape is not a circle"); return coordinates[1][1]; }
/** * {@link com.thinkaurelius.titan.core.attribute.Geoshape} stores Points in the String format: point[X.0,Y.0]. * Solr needs it to be in Well-Known Text format: POINT(X.0 Y.0) */ static String convertToWktString(Geoshape fieldValue) throws BackendException { if (fieldValue.getType() == Geoshape.Type.POINT) { Geoshape.Point point = fieldValue.getPoint(); return "POINT(" + point.getLongitude() + " " + point.getLatitude() + ")"; } else { throw new PermanentBackendException("Cannot index " + fieldValue.getType()); } } }
/** * {@link com.thinkaurelius.titan.core.attribute.Geoshape} stores Points in the String format: point[X.0,Y.0]. * Solr needs it to be in Well-Known Text format: POINT(X.0 Y.0) */ static String convertToWktString(Geoshape fieldValue) throws BackendException { if (fieldValue.getType() == Geoshape.Type.POINT) { Geoshape.Point point = fieldValue.getPoint(); return "POINT(" + point.getLongitude() + " " + point.getLatitude() + ")"; } else { throw new PermanentBackendException("Cannot index " + fieldValue.getType()); } } }
@Override public String toString() { Type type = getType(); StringBuilder s = new StringBuilder(); s.append(type.toString().toLowerCase()); switch (type) { case POINT: s.append(getPoint().toString()); break; case CIRCLE: s.append(getPoint().toString()).append(":").append(getRadius()); break; default: s.append("["); for (int i=0;i<size();i++) { if (i>0) s.append(","); s.append(getPoint(i)); } s.append("]"); } return s.toString(); }
@Override public String toString() { Type type = getType(); StringBuilder s = new StringBuilder(); s.append(type.toString().toLowerCase()); switch (type) { case POINT: s.append(getPoint().toString()); break; case CIRCLE: s.append(getPoint().toString()).append(":").append(getRadius()); break; default: s.append("["); for (int i=0;i<size();i++) { if (i>0) s.append(","); s.append(getPoint(i)); } s.append("]"); } return s.toString(); }
/** * Converts this shape into its equivalent Spatial4j {@link Shape}. * @return */ public Shape convert2Spatial4j() { switch(getType()) { case POINT: return getPoint().getSpatial4jPoint(); case CIRCLE: return CTX.makeCircle(getPoint(0).getSpatial4jPoint(), DistanceUtils.dist2Degrees(getRadius(), DistanceUtils.EARTH_MEAN_RADIUS_KM)); case BOX: return CTX.makeRectangle(getPoint(0).getSpatial4jPoint(),getPoint(1).getSpatial4jPoint()); case POLYGON: throw new UnsupportedOperationException("Not yet supported"); default: throw new IllegalStateException("Unrecognized type: " + getType()); } }
/** * Converts this shape into its equivalent Spatial4j {@link Shape}. * @return */ public Shape convert2Spatial4j() { switch(getType()) { case POINT: return getPoint().getSpatial4jPoint(); case CIRCLE: return CTX.makeCircle(getPoint(0).getSpatial4jPoint(), DistanceUtils.dist2Degrees(getRadius(), DistanceUtils.EARTH_MEAN_RADIUS_KM)); case BOX: return CTX.makeRectangle(getPoint(0).getSpatial4jPoint(),getPoint(1).getSpatial4jPoint()); case POLYGON: throw new UnsupportedOperationException("Not yet supported"); default: throw new IllegalStateException("Unrecognized type: " + getType()); } }
} else if (add.value instanceof Geoshape) { Geoshape shape = (Geoshape) add.value; if (shape.getType() == Geoshape.Type.POINT) { Geoshape.Point p = shape.getPoint(); builder.field(add.key, new double[]{p.getLongitude(), p.getLatitude()}); } else throw new UnsupportedOperationException("Geo type is not supported: " + shape.getType());