java.lang.Object
org.jgrapht.osm.OsmCsvGraphLoader
Loads a headerless weighted edge-list CSV (the format produced by
GpkgRoadGraphPreprocessor) into a target Graph. The actual parsing is
delegated to CSVImporter from jgrapht-io; this class only adds gzip
support and the conventional Integer-vertex factory.
CSV schema (one directed edge per line, no header):
src,dst,weight_m
Vertices are created on demand from the CSV tokens via Integer::valueOf.
Callers that need a different vertex type can build their own CSVImporter
directly; this class is a convenience for the OSM road-graph case.
- Author:
- Shai Eilat
-
Method Summary
Modifier and TypeMethodDescriptionstatic Graph<Integer, DefaultWeightedEdge> loadGzipped(InputStream gzippedCsv) Loads the gzipped edges stream into a freshly createdSimpleDirectedWeightedGraph<Integer, DefaultWeightedEdge>.static Graph<Integer, DefaultWeightedEdge> loadGzippedFile(Path path) Loads the gzipped edges file into a freshly createdSimpleDirectedWeightedGraph<Integer, DefaultWeightedEdge>.static voidloadGzippedInto(InputStream gzippedCsv, Graph<Integer, DefaultWeightedEdge> graph) Loads the gzipped edges stream into the caller-supplied graph.static Graph<Integer, DefaultWeightedEdge> loadGzippedResource(Class<?> anchor, String resource) Loads the gzipped edges resource into a freshly createdSimpleDirectedWeightedGraph<Integer, DefaultWeightedEdge>.
-
Method Details
-
loadGzippedResource
public static Graph<Integer,DefaultWeightedEdge> loadGzippedResource(Class<?> anchor, String resource) throws IOException Loads the gzipped edges resource into a freshly createdSimpleDirectedWeightedGraph<Integer, DefaultWeightedEdge>. Reads directly from a classpath resource looked up relative to the given anchor class.- Parameters:
anchor- anchor class forClass.getResourceAsStream(java.lang.String)resource- resource path (must point at a gzipped CSV)- Returns:
- the loaded graph
- Throws:
IOException- on missing resource or parse error
-
loadGzippedFile
Loads the gzipped edges file into a freshly createdSimpleDirectedWeightedGraph<Integer, DefaultWeightedEdge>.- Parameters:
path- file path (must point at a gzipped CSV)- Returns:
- the loaded graph
- Throws:
IOException- on parse error
-
loadGzipped
public static Graph<Integer,DefaultWeightedEdge> loadGzipped(InputStream gzippedCsv) throws IOException Loads the gzipped edges stream into a freshly createdSimpleDirectedWeightedGraph<Integer, DefaultWeightedEdge>. The caller closes the stream.- Parameters:
gzippedCsv- gzipped CSV input stream- Returns:
- the loaded graph
- Throws:
IOException- on parse error
-
loadGzippedInto
public static void loadGzippedInto(InputStream gzippedCsv, Graph<Integer, DefaultWeightedEdge> graph) throws IOExceptionLoads the gzipped edges stream into the caller-supplied graph. Useful when the caller has pre-added vertices in a specific order, or wants a different graph concrete type (e.g. a directed multigraph).- Parameters:
gzippedCsv- gzipped CSV input stream (caller closes)graph- the destination graph- Throws:
IOException- on parse error
-