Obtain snapped location data outside of matrix

I am passing lats and longs to the matrix endpoint, not for the purpose of obtaining a distance and duration matrix, but only because I want the information regarding the nearest public road.

For example, if I were to call the matrix function with “locations”: [152.683188, -27.307704] it would give me a result of
“location”: [152.682561, -27.306692],
“name”: “Northbrook Parkway, 31, 9”,
“snapped_distance”: 128.49

However I am limited when using this function. Because it calculates a full matrix, I can only send a few hundred records at a time. I’d love to instead provide a list of, let’s say 100000 lats and longs and retrieve a list of {location, name, snapped_distance} records in response. Or at least something that’s O(N).

Is there any way to do this without source code changes?

To any poor sod who finds this lonely post. I ended up creating a new endpoint for “Snapped” in the source code. The key function is this:

    public SnappedResult computeSnapped(SnappedRequest req) throws Exception {
        GraphHopper gh = getGraphhopper();
        String encoderName = RoutingProfileType.getEncoderName(req.getProfileType());
        FlagEncoder flagEncoder = gh.getEncodingManager().getEncoder(encoderName);
        PMap hintsMap = new PMap();
        int weightingMethod = req.getWeightingMethod() == WeightingMethod.UNKNOWN ? WeightingMethod.RECOMMENDED : req.getWeightingMethod();
        setWeightingMethod(hintsMap, weightingMethod, req.getProfileType(), false);
        setWeighting(hintsMap, weightingMethod, req.getProfileType(), false);
        String CHProfileName = makeProfileName(encoderName, hintsMap.getString("weighting", ""), false);
        String profileName = CHProfileName;
        RoutingCHGraph routingCHGraph = gh.getGraphHopperStorage().getRoutingCHGraph(profileName);
        MatrixSearchContextBuilder builder = new MatrixSearchContextBuilder(gh.getGraphHopperStorage(), gh.getLocationIndex(), AccessFilter.allEdges(flagEncoder.getAccessEnc()), true);
        MatrixSearchContext mtxSearchCntx = builder.create(routingCHGraph.getBaseGraph(), routingCHGraph, routingCHGraph.getWeighting(), profileName, req.getLocations(), req.getLocations(), MatrixServiceSettings.getMaximumSearchRadius());
        SnappedResult mtxResult = new SnappedResult(mtxSearchCntx.getSources().getLocations());
        return mtxResult;

Add this to openrouteservice/src/main/java/org/heigit/ors/routing/RoutingProfile.java and create/change the 15 necessary files for this to be exposed as its own web service.

Sorry for the long waiting time and thank you very much for sharing your code!
We are planning to integrate it into one of our next releases. The corresponding github issue is here:

Best regards