@Override public ShapeCollection getBuffered(double distance, SpatialContext ctx) { List<Shape> bufColl = new ArrayList<Shape>(size()); for (Shape shape : shapes) { bufColl.add(shape.getBuffered(distance, ctx)); } return ctx.makeCollection(bufColl); }
/** * Parses the BUFFER operation applied to a parsed shape. * * <pre> * '(' shape ',' number ')' * </pre> * * Whereas 'number' is the distance to buffer the shape by. */ protected Shape parseBufferShape(State state) throws ParseException { state.nextExpect('('); Shape shape = shape(state); state.nextExpect(','); double distance = shapeFactory.normDist(state.nextDouble()); state.nextExpect(')'); return shape.getBuffered(distance, ctx); }
@Override public Shape getBuffered(double distance, SpatialContext ctx) { return s.getBuffered(distance, ctx); }
@Override public Shape buffer(Shape s, double distance) { return s.getBuffered(distance, SpatialSupport.getSpatialContext()); }
/** * Returns a buffered representation (TRIP_BUFFER_METERS) of a GTFS trip shape from shapes.txt for the given tripId, * or null if a shape doesn't exist for the given tripId. * <p> * * @param tripId the GTFS trip_id to retrieve a buffered trip shape for * @return a buffered representation (TRIP_BUFFER_METERS) of a GTFS trip shape from shapes.txt for the given tripId, * or null if a shape doesn't exist for the given trip. */ public Shape getBufferedTripShape(String tripId) { if (mTripShapes == null) { // No shapes at all return null; } Shape s = mTripShapes.get(tripId); if (s == null) { // No shape for this trip_id return null; } // Create the buffered version of the trip shape if it doesn't yet exist return mTripShapesBuffered.computeIfAbsent(tripId, k -> s.getBuffered(TRIP_BUFFER_DEGREES, s.getContext())); }
@Override public OSpatialQueryContext build(Map<String, Object> query) throws Exception { Shape shape = parseShape(query); SpatialStrategy strategy = manager.strategy(); Number distance = (Number) query.get("distance"); if (distance != null) { shape = shape.getBuffered(distance.doubleValue(), factory.context()); } if (isOnlyBB(strategy)) { shape = shape.getBoundingBox(); } SpatialArgs args1 = new SpatialArgs(SpatialOperation.Intersects, shape); Query filterQuery = strategy.makeQuery(args1); BooleanQuery q = new BooleanQuery.Builder().add(filterQuery, BooleanClause.Occur.MUST) .add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD).build(); return new OSpatialQueryContext(null, manager.searcher(), q); }
@Override public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 3) { throw new ValueExprEvaluationException( getURI() + " requires exactly 3 arguments, got " + args.length); } SpatialContext geoContext = SpatialSupport.getSpatialContext(); Shape geom = FunctionArguments.getShape(this, args[0], geoContext); double radiusUom = FunctionArguments.getDouble(this, args[1]); IRI units = FunctionArguments.getUnits(this, args[2]); double radiusDegs = FunctionArguments.convertToDegrees(radiusUom, units); Shape buffered = geom.getBuffered(radiusDegs, geoContext); String wkt; try { wkt = SpatialSupport.getWktWriter().toWkt(buffered); } catch (IOException ioe) { throw new ValueExprEvaluationException(ioe); } return valueFactory.createLiteral(wkt, GEO.WKT_LITERAL); } }