Last active
October 4, 2018 09:09
-
-
Save bhugueney/0bd3f63792267072892999a88422c2c4 to your computer and use it in GitHub Desktop.
reading vertices and edges data from URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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