use of com.graphhopper.util.shapes.GHPoint3D in project graphhopper by graphhopper.
the class NearestResource method doGet.
@GET
public Response doGet(@QueryParam("point") GHPoint point, @QueryParam("elevation") @DefaultValue("false") boolean elevation) {
Snap snap = index.findClosest(point.lat, point.lon, EdgeFilter.ALL_EDGES);
if (snap.isValid()) {
GHPoint3D snappedPoint = snap.getSnappedPoint();
double[] coordinates = hasElevation && elevation ? new double[] { snappedPoint.lon, snappedPoint.lat, snappedPoint.ele } : new double[] { snappedPoint.lon, snappedPoint.lat };
return new Response(coordinates, calc.calcDist(point.lat, point.lon, snappedPoint.lat, snappedPoint.lon));
} else {
throw new WebApplicationException("Nearest point cannot be found!");
}
}
use of com.graphhopper.util.shapes.GHPoint3D in project graphhopper by graphhopper.
the class GpxConversions method createGPX.
public static String createGPX(InstructionList instructions, String trackName, long startTimeMillis, boolean includeElevation, boolean withRoute, boolean withTrack, boolean withWayPoints, String version, Translation tr) {
DateFormat formatter = Helper.createFormatter();
DecimalFormat decimalFormat = new DecimalFormat("#", DecimalFormatSymbols.getInstance(Locale.ROOT));
decimalFormat.setMinimumFractionDigits(1);
decimalFormat.setMaximumFractionDigits(6);
decimalFormat.setMinimumIntegerDigits(1);
String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>" + "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " creator=\"Graphhopper version " + version + "\" version=\"1.1\"" + // Use a separate namespace for custom extensions to make basecamp happy.
" xmlns:gh=\"https://graphhopper.com/public/schema/gpx/1.1\">" + "\n<metadata>" + "<copyright author=\"OpenStreetMap contributors\"/>" + "<link href=\"http://graphhopper.com\">" + "<text>GraphHopper GPX</text>" + "</link>" + "<time>" + formatter.format(startTimeMillis) + "</time>" + "</metadata>";
StringBuilder gpxOutput = new StringBuilder(header);
if (!instructions.isEmpty()) {
if (withWayPoints) {
// Start
createWayPointBlock(gpxOutput, instructions.get(0), decimalFormat, tr);
for (Instruction currInstr : instructions) {
if (// Via
(currInstr.getSign() == Instruction.REACHED_VIA) || // End
(currInstr.getSign() == Instruction.FINISH)) {
createWayPointBlock(gpxOutput, currInstr, decimalFormat, tr);
}
}
}
if (withRoute) {
gpxOutput.append("\n<rte>");
Instruction nextInstr = null;
for (Instruction currInstr : instructions) {
if (null != nextInstr)
createRteptBlock(gpxOutput, nextInstr, currInstr, decimalFormat, tr);
nextInstr = currInstr;
}
createRteptBlock(gpxOutput, nextInstr, null, decimalFormat, tr);
gpxOutput.append("\n</rte>");
}
}
if (withTrack) {
gpxOutput.append("\n<trk><name>").append(trackName).append("</name>");
gpxOutput.append("<trkseg>");
for (GPXEntry entry : createGPXList(instructions)) {
gpxOutput.append("\n<trkpt lat=\"").append(decimalFormat.format(entry.getPoint().getLat()));
gpxOutput.append("\" lon=\"").append(decimalFormat.format(entry.getPoint().getLon())).append("\">");
if (includeElevation)
gpxOutput.append("<ele>").append(Helper.round2(((GHPoint3D) entry.getPoint()).getEle())).append("</ele>");
if (entry.getTime() != null)
gpxOutput.append("<time>").append(formatter.format(startTimeMillis + entry.getTime())).append("</time>");
gpxOutput.append("</trkpt>");
}
gpxOutput.append("\n</trkseg>");
gpxOutput.append("\n</trk>");
}
// we could now use 'wpt' for via points
gpxOutput.append("\n</gpx>");
return gpxOutput.toString();
}
use of com.graphhopper.util.shapes.GHPoint3D in project graphhopper by graphhopper.
the class OSMNodeData method addCopyOfNode.
/**
* Creates a copy of the coordinates stored for the given node ID
*
* @return the (artificial) OSM node ID created for the copied node and the associated ID
*/
SegmentNode addCopyOfNode(SegmentNode node) {
GHPoint3D point = getCoordinates(node.id);
if (point == null)
throw new IllegalStateException("Cannot copy node : " + node.osmNodeId + ", because it is missing");
final long newOsmId = nextArtificialOSMNodeId++;
if (idsByOsmNodeIds.put(newOsmId, INTERMEDIATE_NODE) != EMPTY_NODE)
throw new IllegalStateException("Artificial osm node id already exists: " + newOsmId);
int id = addPillarNode(newOsmId, point.getLat(), point.getLon(), point.getEle());
return new SegmentNode(newOsmId, id);
}
use of com.graphhopper.util.shapes.GHPoint3D in project graphhopper by graphhopper.
the class GraphHopperTest method testSRTMWithLongEdgeSampling.
@Test
public void testSRTMWithLongEdgeSampling() {
final String profile = "profile";
final String vehicle = "foot";
final String weighting = "shortest";
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setStoreOnFlush(true).setProfiles(new Profile("profile").setVehicle(vehicle).setWeighting(weighting));
hopper.getRouterConfig().setElevationWayPointMaxDistance(1.);
hopper.getReaderConfig().setElevationMaxWayPointDistance(1.).setLongEdgeSamplingDistance(30);
SRTMProvider elevationProvider = new SRTMProvider(DIR);
elevationProvider.setInterpolate(true);
hopper.setElevationProvider(elevationProvider);
hopper.importOrLoad();
GHResponse rsp = hopper.route(new GHRequest(43.730729, 7.421288, 43.727697, 7.419199).setAlgorithm(ASTAR).setProfile(profile));
ResponsePath arsp = rsp.getBest();
assertEquals(1569.7, arsp.getDistance(), .1);
assertEquals(60, arsp.getPoints().size());
assertTrue(arsp.getPoints().is3D());
InstructionList il = arsp.getInstructions();
assertEquals(12, il.size());
assertTrue(il.get(0).getPoints().is3D());
String str = arsp.getPoints().toString();
assertEquals(23.8, arsp.getAscend(), 1e-1);
assertEquals(67.4, arsp.getDescend(), 1e-1);
assertEquals(60, arsp.getPoints().size());
assertEquals(new GHPoint3D(43.73068455771767, 7.421283689825812, 55.82900047302246), arsp.getPoints().get(0));
assertEquals(new GHPoint3D(43.727679637988224, 7.419198521975086, 12.274499893188477), arsp.getPoints().get(arsp.getPoints().size() - 1));
assertEquals(55.83, arsp.getPoints().get(0).getEle(), 1e-2);
assertEquals(57.78, arsp.getPoints().get(1).getEle(), 1e-2);
assertEquals(52.43, arsp.getPoints().get(10).getEle(), 1e-2);
}
Aggregations