Skip to content

Instantly share code, notes, and snippets.

@bhugueney
Last active October 4, 2018 09:09
Show Gist options
  • Save bhugueney/0bd3f63792267072892999a88422c2c4 to your computer and use it in GitHub Desktop.
Save bhugueney/0bd3f63792267072892999a88422c2c4 to your computer and use it in GitHub Desktop.
reading vertices and edges data from URL
public static GeoPoint[] read(String vUrl, String eUrl)throws IOException {
List<GeoPoint> res= new SingleLinkedList<GeoPoint>();
try(BufferedReader vBr = new BufferedReader(new InputStreamReader(new URL(vUrl).openStream()));
BufferedReader eBr = new BufferedReader(new InputStreamReader(new URL(eUrl).openStream()))) {
for(String line= vBr.readLine(); line != null; line= vBr.readLine()){
String[] coords= line.split(" ");//latitude, longitude
res.add(new GeoPoint(Double.parseDouble(coords[0]), Double.parseDouble(coords[1])));
}
for(String line= eBr.readLine(); line != null; line= eBr.readLine()){
String[] data= line.split(" ");//start end nbDirs Duration Length
GeoPoint start= res.get(Integer.parseInt(data[0]));
GeoPoint end= res.get(Integer.parseInt(data[1]));
Integer length= Integer.parseInt(data[4]);
start.neighborToDistance.put(end, length);
if(data[2].equals("2")){
end.neighborToDistance.put(start, length);
}
}
}catch (Exception e){
System.err.println(e);
}
return res.toArray(new GeoPoint[res.size()]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment