Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ android/libs/graphhopper-*-android.jar
.idea/
*iml
debug.sh
*.pbf
web/src/main/webapp/js/options_prod.js
!/core/src/test/resources/com/graphhopper/reader/*.pbf
*.pbf
!/reader-osm/src/test/resources/com/graphhopper/reader/osm/*.pbf
*.dem
*.log
core/TODO*.txt
Expand Down
10 changes: 1 addition & 9 deletions android/app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,10 @@
<dependencies>
<dependency>
<groupId>com.graphhopper</groupId>
<artifactId>graphhopper</artifactId>
<artifactId>graphhopper-core</artifactId>
<version>${project.parent.version}</version>
<type>jar</type>
<exclusions>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</exclusion>
<exclusion>
<groupId>org.openstreetmap.osmosis</groupId>
<artifactId>osmosis-osm-binary</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>xmlgraphics-commons</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions core/files/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.8
all properties with prefix "osmreader." changed to "datareader." and osmreader.osm changed to datareader.file
maven/gradle dependency graphhopper is now splitted into graphhopper-core and graphhopper-reader-osm, i.e. if you previouls depend on 'graphhopper' artificat you should now use graphhopper-reader-osm except environments like Android where you just load the graph and do no import
use GraphHopperOSM as base class instead of GraphHopper
OSM reader separated from core
0.7
added snapped points to output JSON for every path
the foot routing is now much smoother and only considers safe paths, to use beautiful roads (i.e. prefer hiking routes etc) use the new 'hike' profiles, see #633
Expand Down
15 changes: 2 additions & 13 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.graphhopper</groupId>
<artifactId>graphhopper</artifactId>
<artifactId>graphhopper-core</artifactId>
<name>GraphHopper</name>
<version>0.8-SNAPSHOT</version>
<packaging>jar</packaging>
Expand Down Expand Up @@ -80,18 +80,7 @@
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>xmlgraphics-commons</artifactId>
<version>2.1</version>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.openstreetmap.osmosis</groupId>
<artifactId>osmosis-osm-binary</artifactId>
<version>0.44.1</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
Expand All @@ -116,7 +105,7 @@
</configuration>
</plugin>

<!-- create jar with test classes to be reused in other projects -->
<!-- create jar with test classes to be reused in other projects like external or our reader-osm -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
89 changes: 49 additions & 40 deletions core/src/main/java/com/graphhopper/GraphHopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.graphhopper;

import com.graphhopper.reader.DataReader;
import com.graphhopper.reader.OSMReader;
import com.graphhopper.reader.dem.CGIARProvider;
import com.graphhopper.reader.dem.ElevationProvider;
import com.graphhopper.reader.dem.SRTMProvider;
Expand Down Expand Up @@ -86,10 +85,10 @@ public class GraphHopper implements GraphHopperAPI
private int minOneWayNetworkSize = 0;
// for CH prepare
private final CHAlgoFactoryDecorator chFactoryDecorator = new CHAlgoFactoryDecorator();
// for OSM import
private String osmFile;
private double osmReaderWayPointMaxDistance = 1;
private int workerThreads = -1;
// for data reader
private String dataReaderFile;
private double dataReaderWayPointMaxDistance = 1;
private int dataReaderWorkerThreads = -1;
private boolean calcPoints = true;
// utils
private final TranslationMap trMap = new TranslationMap().doImport();
Expand Down Expand Up @@ -153,20 +152,25 @@ public GraphHopper setElevationProvider( ElevationProvider eleProvider )
return this;
}

public ElevationProvider getElevationProvider()
{
return eleProvider;
}

/**
* Threads for data reading.
*/
protected int getWorkerThreads()
{
return workerThreads;
return dataReaderWorkerThreads;
}

/**
* Return maximum distance (in meter) to reduce points via douglas peucker while OSM import.
*/
protected double getWayPointMaxDistance()
{
return osmReaderWayPointMaxDistance;
return dataReaderWayPointMaxDistance;
}

/**
Expand All @@ -175,7 +179,7 @@ protected double getWayPointMaxDistance()
*/
public GraphHopper setWayPointMaxDistance( double wayPointMaxDistance )
{
this.osmReaderWayPointMaxDistance = wayPointMaxDistance;
this.dataReaderWayPointMaxDistance = wayPointMaxDistance;
return this;
}

Expand Down Expand Up @@ -423,6 +427,11 @@ public GraphHopper setEnableInstructions( boolean b )
return this;
}

public boolean isEnableInstructions()
{
return enableInstructions;
}

/**
* This method specifies the preferred language for way names during import.
* <p>
Expand Down Expand Up @@ -487,22 +496,22 @@ public String getGraphHopperLocation()
}

/**
* This file can be an osm xml (.osm), a compressed xml (.osm.zip or .osm.gz) or a protobuf file
* (.pbf).
* This file can be any file type supported by the DataReader. E.g. for the OSMReader it is the
* OSM xml (.osm), a compressed xml (.osm.zip or .osm.gz) or a protobuf file (.pbf)
*/
public GraphHopper setOSMFile( String osmFileStr )
public GraphHopper setDataReaderFile( String dataReaderFileStr )
{
ensureNotLoaded();
if (Helper.isEmpty(osmFileStr))
throw new IllegalArgumentException("OSM file cannot be empty.");
if (Helper.isEmpty(dataReaderFileStr))
throw new IllegalArgumentException("Data reader file cannot be empty.");

osmFile = osmFileStr;
dataReaderFile = dataReaderFileStr;
return this;
}

public String getOSMFile()
public String getDataReaderFile()
{
return osmFile;
return dataReaderFile;
}

/**
Expand Down Expand Up @@ -586,17 +595,17 @@ public GraphHopper setFlagEncoderFactory( FlagEncoderFactory factory )
public GraphHopper init( CmdArgs args )
{
args = CmdArgs.readFromConfigAndMerge(args, "config", "graphhopper.config");
String tmpOsmFile = args.get("osmreader.osm", "");
String tmpOsmFile = args.get("datareader.file", "");
if (!Helper.isEmpty(tmpOsmFile))
osmFile = tmpOsmFile;
dataReaderFile = tmpOsmFile;

String graphHopperFolder = args.get("graph.location", "");
if (Helper.isEmpty(graphHopperFolder) && Helper.isEmpty(ghLocation))
{
if (Helper.isEmpty(osmFile))
if (Helper.isEmpty(dataReaderFile))
throw new IllegalArgumentException("You need to specify an OSM file.");

graphHopperFolder = Helper.pruneFileEnd(osmFile) + "-gh";
graphHopperFolder = Helper.pruneFileEnd(dataReaderFile) + "-gh";
}

// graph
Expand Down Expand Up @@ -661,11 +670,11 @@ public GraphHopper init( CmdArgs args )
chFactoryDecorator.init(args);

// osm import
osmReaderWayPointMaxDistance = args.getDouble(Routing.INIT_WAY_POINT_MAX_DISTANCE, osmReaderWayPointMaxDistance);
dataReaderWayPointMaxDistance = args.getDouble(Routing.INIT_WAY_POINT_MAX_DISTANCE, dataReaderWayPointMaxDistance);

workerThreads = args.getInt("osmreader.worker_threads", workerThreads);
enableInstructions = args.getBool("osmreader.instructions", enableInstructions);
preferredLanguage = args.get("osmreader.preferred_language", preferredLanguage);
dataReaderWorkerThreads = args.getInt("datareader.worker_threads", dataReaderWorkerThreads);
enableInstructions = args.getBool("datareader.instructions", enableInstructions);
preferredLanguage = args.get("datareader.preferred_language", preferredLanguage);

// index
preciseIndexResolution = args.getInt("index.high_resolution", preciseIndexResolution);
Expand Down Expand Up @@ -724,12 +733,12 @@ private GraphHopper process( String graphHopperLocation )
{
DataReader reader = importData();
DateFormat f = Helper.createFormatter();
ghStorage.getProperties().put("osmreader.import.date", f.format(new Date()));
ghStorage.getProperties().put("datareader.import.date", f.format(new Date()));
if (reader.getDataDate() != null)
ghStorage.getProperties().put("osmreader.data.date", f.format(reader.getDataDate()));
ghStorage.getProperties().put("datareader.data.date", f.format(reader.getDataDate()));
} catch (IOException ex)
{
throw new RuntimeException("Cannot parse OSM file " + getOSMFile(), ex);
throw new RuntimeException("Cannot read file " + getDataReaderFile(), ex);
}
cleanUp();
postProcessing();
Expand All @@ -748,9 +757,9 @@ protected DataReader importData() throws IOException
if (ghStorage == null)
throw new IllegalStateException("Load graph before importing OSM data");

if (osmFile == null)
if (dataReaderFile == null)
throw new IllegalStateException("Couldn't load from existing folder: " + ghLocation
+ " but also cannot import from OSM file as it wasn't specified!");
+ " but also cannot use file for DataReader as it wasn't specified!");

encodingManager.setEnableInstructions(enableInstructions);
encodingManager.setPreferredLanguage(preferredLanguage);
Expand All @@ -762,21 +771,21 @@ protected DataReader importData() throws IOException

protected DataReader createReader( GraphHopperStorage ghStorage )
{
return initOSMReader(new OSMReader(ghStorage));
throw new UnsupportedOperationException("Cannot create DataReader. Solutions: avoid import via calling load directly, "
+ "provide a DataReader or use e.g. GraphHopperOSM or a different subclass");
}

protected OSMReader initOSMReader( OSMReader reader )
protected DataReader initDataReader( DataReader reader )
{
if (osmFile == null)
throw new IllegalArgumentException("No OSM file specified");
if (dataReaderFile == null)
throw new IllegalArgumentException("No file for DataReader specified");

logger.info("start creating graph from " + osmFile);
File osmTmpFile = new File(osmFile);
return reader.setOSMFile(osmTmpFile).
logger.info("start creating graph from " + dataReaderFile);
return reader.setFile(new File(dataReaderFile)).
setElevationProvider(eleProvider).
setWorkerThreads(workerThreads).
setWorkerThreads(dataReaderWorkerThreads).
setEncodingManager(encodingManager).
setWayPointMaxDistance(osmReaderWayPointMaxDistance);
setWayPointMaxDistance(dataReaderWayPointMaxDistance);
}

/**
Expand Down Expand Up @@ -923,7 +932,7 @@ protected void createCHPreparations()
/**
* Does the preparation and creates the location index
*/
protected void postProcessing()
public void postProcessing()
{
// Later: move this into the GraphStorage.optimize method
// Or: Doing it after preparation to optimize shortcuts too. But not possible yet #12
Expand Down Expand Up @@ -1004,7 +1013,7 @@ public GHResponse route( GHRequest request )
return response;
}

protected List<Path> calcPaths( GHRequest request, GHResponse ghRsp )
public List<Path> calcPaths( GHRequest request, GHResponse ghRsp )
{
if (ghStorage == null || !fullyLoaded)
throw new IllegalStateException("Do a successful call to load or importOrLoad before routing");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to GraphHopper GmbH under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* GraphHopper GmbH licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.graphhopper.reader;

/**
*
* @author Peter Karich
*/
public interface ConditionalTagInspector
{
boolean isRestrictedWayConditionallyPermitted( ReaderWay way );

boolean isPermittedWayConditionallyRestricted( ReaderWay way );
}
13 changes: 13 additions & 0 deletions core/src/main/java/com/graphhopper/reader/DataReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
package com.graphhopper.reader;

import com.graphhopper.reader.dem.ElevationProvider;
import com.graphhopper.routing.util.EncodingManager;
import java.io.File;
import java.io.IOException;
import java.util.Date;

Expand All @@ -25,6 +28,16 @@
*/
public interface DataReader
{
DataReader setFile( File file );

DataReader setElevationProvider( ElevationProvider ep );

DataReader setWorkerThreads( int workerThreads );

DataReader setEncodingManager( EncodingManager em );

DataReader setWayPointMaxDistance( double wayPointMaxDistance );

/**
* This method triggers reading the underlying data to create a graph
*/
Expand Down
Loading