/** * Whether this geometry contains the given geometry. * @param outer * @return */ public boolean contains(Geoshape outer) { return getSpatialRelation(outer)==SpatialRelation.CONTAINS; }
/** * Returns the GeoJSON representation of the shape. * @return */ public String toGeoJson() { return GeoshapeGsonSerializerV2d0.toGeoJson(this); }
/** * Returns the point at the given position. The position must be smaller than {@link #size()}. * * @param position * @return */ public Point getPoint(int position) { return HELPER.getPoint(this, position); }
@Override public void serialize(Geoshape value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { switch(value.getType()) { case POINT: jgen.writeStartObject(); jgen.writeFieldName(FIELD_TYPE); jgen.writeString(Type.POINT.toString()); jgen.writeFieldName(FIELD_COORDINATES); jgen.writeStartArray(); jgen.writeNumber(value.getPoint().getLongitude()); jgen.writeNumber(value.getPoint().getLatitude()); jgen.writeEndArray(); jgen.writeEndObject(); break; default: jgen.writeRawValue(toGeoJson(value)); break; } }
public void write(DataOutputStream dataOutput, Geoshape attribute) throws IOException { if (isJts(attribute.getShape())) { dataOutput.writeByte(0); // note geometries written with writeJtsGeom cannot be deserialized with readShape so to maintain backwards // compatibility with previously written geometries must maintain read/writeJtsGeom for the JtsGeometry case binaryCodec.writeJtsGeom(dataOutput, attribute.getShape()); } else { dataOutput.writeByte(1); binaryCodec.writeShape(dataOutput, attribute.getShape()); } }
@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; }
/** * Create Geoshape from WKT representation. * @param wkt * @return * @throws ParseException */ public static Geoshape fromWkt(String wkt) throws ParseException { return new Geoshape(HELPER.getWktReader().parse(wkt)); }
/** * Returns the {@link Type} of this geoshape. * * @return */ public Type getType() { return HELPER.getType(shape); }
/** * Constructs a Geoshape from a spatial4j {@link Shape}. * @param shape * @return */ public static Geoshape geoshape(Shape shape) { return new Geoshape(shape); }
/** * Returns the number of points comprising this geoshape. A point and circle have only one point (center of circle), * a box has two points (the south-west and north-east corners). Lines and polygons have a variable number of points. * * @return */ public int size() { return HELPER.size(shape); }
/** * Constructs a polygon from list of coordinates * @param coordinates Coordinate (lon,lat) pairs * @return */ public static Geoshape polygon(List<double[]> coordinates) { return HELPER.polygon(coordinates); }
public static SpatialContext getSpatialContext() { return HELPER.getContext(); }
@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).disjoint((Geoshape) condition); }
/** * Returns the WKT representation of the shape. * @return */ @Override public String toString() { return HELPER.getWktWriter().toString(shape); }
/** * Whether this geometry is within the given geometry. * @param outer * @return */ public boolean within(Geoshape outer) { return getSpatialRelation(outer)==SpatialRelation.WITHIN; }
/** * Whether this geometry has any points in common with the given geometry. * @param other * @return */ public boolean intersect(Geoshape other) { SpatialRelation r = getSpatialRelation(other); return r==SpatialRelation.INTERSECTS || r==SpatialRelation.CONTAINS || r==SpatialRelation.WITHIN; }
/** * Whether this geometry has no points in common with the given geometry. * @param other * @return */ public boolean disjoint(Geoshape other) { return getSpatialRelation(other)==SpatialRelation.DISJOINT; }