Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 102 additions & 3 deletions core/src/main/java/com/graphhopper/routing/matrix/GHMatrixRequest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.graphhopper.routing.matrix;

import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.graphhopper.util.CustomModel;
import com.graphhopper.util.Helper;
import com.graphhopper.util.PMap;
import com.graphhopper.util.Parameters;
Expand All @@ -17,8 +20,14 @@ public class GHMatrixRequest {
private String profile = "";
private final List<GHPoint> origins = new ArrayList<>();
private final List<GHPoint> destinations = new ArrayList<>();
private final List<String> originPointHints = new ArrayList<>();
private final List<String> destinationPointHints = new ArrayList<>();
private List<String> snapPreventions = new ArrayList<>();
private List<String> originCurbsides = new ArrayList<>();
private List<String> destinationCurbsides = new ArrayList<>();
private final PMap hints = new PMap();
private boolean failFast = true;
private CustomModel customModel;

/**
* One or more locations to use as the starting point for calculating travel distance and time.
Expand All @@ -27,8 +36,10 @@ public List<GHPoint> getOrigins() {
return origins;
}

public void setOrigins(List<GHPoint> origins) {
@JsonProperty("from_points")
public GHMatrixRequest setOrigins(List<GHPoint> origins) {
this.origins.addAll(origins);
return this;
}

/**
Expand All @@ -38,8 +49,16 @@ public List<GHPoint> getDestinations() {
return destinations;
}

public void setDestinations(List<GHPoint> destinations) {
@JsonProperty("to_points")
public GHMatrixRequest setDestinations(List<GHPoint> destinations) {
this.destinations.addAll(destinations);
return this;
}

public GHMatrixRequest setPoints(List<GHPoint> origins) {
this.setOrigins(origins);
this.setDestinations(origins);
return this;
}

public String getAlgorithm() {
Expand All @@ -65,6 +84,14 @@ public PMap getHints() {
return hints;
}

/**
* This method sets a key value pair in the hints and is unrelated to the setPointHints method.
* It is mainly used for deserialization with Jackson.
*
* @see #setPointHints(List)
*/
// a good trick to serialize unknown properties into the HintsMap
@JsonAnySetter
public GHMatrixRequest putHint(String fieldName, Object value) {
this.hints.putObject(fieldName, value);
return this;
Expand All @@ -74,7 +101,79 @@ public boolean isFailFast() {
return failFast;
}

public void setFailFast(boolean failFast) {
public GHMatrixRequest setFailFast(boolean failFast) {
this.failFast = failFast;
return this;
}

public List<String> getOriginPointHints() {
return originPointHints;
}

@JsonProperty("from_point_hints")
public GHMatrixRequest setOriginPointHints(List<String> pointHints) {
this.originPointHints.addAll(pointHints);
return this;
}

public List<String> getDestinationPointHints() {
return destinationPointHints;
}

@JsonProperty("to_point_hints")
public GHMatrixRequest setDestinationPointHints(List<String> pointHints) {
this.destinationPointHints.addAll(pointHints);
return this;
}

@JsonProperty("point_hints")
public GHMatrixRequest setPointHints(List<String> pointHints) {
this.originPointHints.addAll(pointHints);
this.destinationPointHints.addAll(pointHints);
return this;
}

public List<String> getSnapPreventions() {
return snapPreventions;
}

public GHMatrixRequest setSnapPreventions(List<String> snapPreventions) {
this.snapPreventions.addAll(snapPreventions);
return this;
}

public List<String> getOriginCurbsides() {
return originCurbsides;
}

@JsonProperty("from_curbsides")
public GHMatrixRequest setOriginCurbsides(List<String> curbsides) {
this.originCurbsides.addAll(curbsides);
return this;
}

public List<String> getDestinationCurbsides() {
return destinationCurbsides;
}

@JsonProperty("to_curbside")
public GHMatrixRequest setDestinationCurbsides(List<String> curbsides) {
this.destinationCurbsides.addAll(curbsides);
return this;
}

public GHMatrixRequest setCurbsides(List<String> curbsides) {
this.destinationCurbsides.addAll(curbsides);
this.originCurbsides.addAll(curbsides);
return this;
}

public CustomModel getCustomModel() {
return customModel;
}

public GHMatrixRequest setCustomModel(CustomModel customModel) {
this.customModel = customModel;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public RouterMatrix(BaseGraph graph, EncodingManager encodingManager, LocationIn

public GHMatrixResponse matrix(GHMatrixRequest request) {

if (!request.getOriginPointHints().isEmpty() && !request.getDestinationPointHints().isEmpty())
throw new IllegalArgumentException("Point hints are not supported for Matrix");

if (!request.getSnapPreventions().isEmpty())
throw new IllegalArgumentException("SnapPreventions are not supported for Matrix " + request.getSnapPreventions().toString());

if (!request.getOriginCurbsides().isEmpty() && !request.getDestinationCurbsides().isEmpty())
throw new IllegalArgumentException("Curbsides are not supported for Matrix");

if (request.getCustomModel() != null)
throw new IllegalArgumentException("CustomModel not supported for Matrix: " + request.getCustomModel().toString());

Profile profile = profilesByName.get(request.getProfile());
RoutingCHGraph chGraph = chGraphs.get(profile.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ protected void configure() {
environment.jersey().register(MVTResource.class);
environment.jersey().register(NearestResource.class);
environment.jersey().register(RouteResource.class);
environment.jersey().register(MatrixResource.class);
environment.jersey().register(IsochroneResource.class);
environment.jersey().register(MapMatchingResource.class);
if (configuration.getGraphHopperConfiguration().has("gtfs.file")) {
Expand Down
Loading