/** * Constructs a point from its latitude and longitude information * @param latitude * @param longitude * @return */ public static final Geoshape point(final double latitude, final double longitude) { return point((float)latitude,(float)longitude); }
/** * Constructs a circle from a given center point and a radius in kilometer * @param latitude * @param longitude * @param radiusInKM * @return */ public static final Geoshape circle(final double latitude, final double longitude, final double radiusInKM) { return circle((float)latitude,(float)longitude,(float)radiusInKM); }
/** * Constructs a new box shape which is identified by its south-west and north-east corner points * @param southWestLatitude * @param southWestLongitude * @param northEastLatitude * @param northEastLongitude * @return */ public static final Geoshape box(final double southWestLatitude, final double southWestLongitude, final double northEastLatitude, final double northEastLongitude) { return box((float)southWestLatitude,(float)southWestLongitude,(float)northEastLatitude,(float)northEastLongitude); }
/** * {@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()); } } }
/** * Constructs a point from its latitude and longitude information * @param latitude * @param longitude * @return */ public static final Geoshape point(final float latitude, final float longitude) { Preconditions.checkArgument(isValidCoordinate(latitude,longitude),"Invalid coordinate provided"); return new Geoshape(new float[][]{ new float[]{latitude}, new float[]{longitude}}); }
/** * Returns the point at the given position. The position must be smaller than {@link #size()}. * * @param position * @return */ public Point getPoint(int position) { if (position<0 || position>=size()) throw new ArrayIndexOutOfBoundsException("Invalid position: " + position); return new Point(coordinates[0][position],coordinates[1][position]); }
@Override public boolean evaluateRaw(String value, String regex) { for (String token : tokenize(value.toLowerCase())) { if (REGEX.evaluateRaw(token,regex)) return true; } return false; }
@Override public boolean evaluateRaw(String value, String prefix) { for (String token : tokenize(value.toLowerCase())) { if (PREFIX.evaluateRaw(token,prefix.toLowerCase())) return true; } return false; }
@Override public boolean test(Object value, Object condition) { this.preevaluate(value,condition); if (value == null) return false; return evaluateRaw(value.toString(),(String)condition); }
@Override public boolean test(Object value, Object condition) { this.preevaluate(value,condition); if (value == null) return false; return evaluateRaw(value.toString(),(String)condition); }
@Override public boolean test(Object value, Object condition) { this.preevaluate(value,condition); if (value == null) return false; return evaluateRaw(value.toString(),(String)condition); }
public boolean intersect(Geoshape other) { SpatialRelation r = getSpatialRelation(other); return r==SpatialRelation.INTERSECTS || r==SpatialRelation.CONTAINS || r==SpatialRelation.WITHIN; }
@Override public Geoshape deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { // move the parser forward jsonParser.nextToken(); float[][] f = jsonParser.readValueAs(float[][].class); jsonParser.nextToken(); return new Geoshape(f); } }
@Override public boolean test(Object value, Object condition) { Preconditions.checkArgument(condition instanceof Geoshape); if (value == null) return false; Preconditions.checkArgument(value instanceof Geoshape); return ((Geoshape) value).intersect((Geoshape) condition); }
@Override public boolean test(Object value, Object condition) { Preconditions.checkArgument(condition instanceof Geoshape); if (value == null) return false; Preconditions.checkArgument(value instanceof Geoshape); return ((Geoshape) value).within((Geoshape) condition); }
@Override public boolean test(Object value, Object condition) { Preconditions.checkArgument(condition instanceof Geoshape); if (value == null) return false; Preconditions.checkArgument(value instanceof Geoshape); return ((Geoshape) value).disjoint((Geoshape) condition); }
/** * Constructs a circle from a given center point and a radius in kilometer * @param latitude * @param longitude * @param radiusInKM * @return */ public static final Geoshape circle(final float latitude, final float longitude, final float radiusInKM) { Preconditions.checkArgument(isValidCoordinate(latitude,longitude),"Invalid coordinate provided"); Preconditions.checkArgument(radiusInKM>0,"Invalid radius provided [%s]",radiusInKM); return new Geoshape(new float[][]{ new float[]{latitude, Float.NaN}, new float[]{longitude, radiusInKM}}); }
public boolean disjoint(Geoshape other) { return getSpatialRelation(other)==SpatialRelation.DISJOINT; }
@Override public Geoshape read(Kryo kryo, Input input, Class<Geoshape> aClass) { long l = input.readLong(); assert l>0 && l<Integer.MAX_VALUE; int length = (int)l; float[][] coordinates = new float[2][]; for (int i = 0; i < 2; i++) { coordinates[i] = input.readFloats(length); } return new Geoshape(coordinates); } }
public boolean within(Geoshape outer) { return getSpatialRelation(outer)==SpatialRelation.WITHIN; }