mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-19 16:59:51 +00:00
scan stations nearby given station (rather than just lat/lon)
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@169 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
6ba4ad8395
commit
9f5e011511
9 changed files with 208 additions and 32 deletions
|
@ -81,22 +81,62 @@ public class RmvProvider implements NetworkProvider
|
|||
private final static Pattern P_NEARBY_STATIONS = Pattern.compile("<a href=\"/auskunft/bin/jp/stboard.exe/dox.+?input=(\\d+).*?\">\\n"
|
||||
+ "(.+?)\\s*\\((\\d+) m/[A-Z]+\\)\\n</a>", Pattern.DOTALL);
|
||||
|
||||
public List<Station> nearbyStations(final double lat, final double lon, final int maxDistance, final int maxStations) throws IOException
|
||||
{
|
||||
final String url = "http://www.rmv.de/auskunft/bin/jp/stboard.exe/dox?input=" + lat + "%20" + lon;
|
||||
final CharSequence page = ParserUtils.scrape(url);
|
||||
private final String NEARBY_URI = "http://www.rmv.de/auskunft/bin/jp/stboard.exe/dn?L=vs_rmv&distance=50&near&input=%d";
|
||||
private final static Pattern P_NEARBY_COARSE = Pattern.compile("<tr class=\"zebracol-\\d\">(.*?)</tr>", Pattern.DOTALL);
|
||||
private final static Pattern P_NEARBY_FINE = Pattern.compile(".*?auskunft/bin/jp/stboard\\.exe/dn\\?L=vs_rmv&input=(\\d+).*?"
|
||||
+ "&REQMapRoute0\\.Location0\\.X=(-?\\d+)&REQMapRoute0\\.Location0\\.Y=(-?\\d+)" //
|
||||
+ "&REQMapRoute0\\.Location0\\.Name=(.*?)\">.*?", Pattern.DOTALL);
|
||||
|
||||
public List<Station> nearbyStations(final String stationId, final double lat, final double lon, final int maxDistance, final int maxStations)
|
||||
throws IOException
|
||||
{
|
||||
final List<Station> stations = new ArrayList<Station>();
|
||||
|
||||
final Matcher m = P_NEARBY_STATIONS.matcher(page);
|
||||
while (m.find())
|
||||
if (lat != 0 || lon != 0)
|
||||
{
|
||||
final int sId = Integer.parseInt(m.group(1));
|
||||
final String sName = ParserUtils.resolveEntities(m.group(2));
|
||||
final int sDist = Integer.parseInt(m.group(3));
|
||||
final String url = "http://www.rmv.de/auskunft/bin/jp/stboard.exe/dox?input=" + lat + "%20" + lon;
|
||||
final CharSequence page = ParserUtils.scrape(url);
|
||||
|
||||
final Station station = new Station(sId, sName, 0, 0, sDist, null, null);
|
||||
stations.add(station);
|
||||
final Matcher m = P_NEARBY_STATIONS.matcher(page);
|
||||
while (m.find())
|
||||
{
|
||||
final int sId = Integer.parseInt(m.group(1));
|
||||
final String sName = ParserUtils.resolveEntities(m.group(2));
|
||||
final int sDist = Integer.parseInt(m.group(3));
|
||||
|
||||
final Station station = new Station(sId, sName, 0, 0, sDist, null, null);
|
||||
stations.add(station);
|
||||
}
|
||||
}
|
||||
else if (stationId != null)
|
||||
{
|
||||
final String uri = String.format(NEARBY_URI, stationId);
|
||||
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mCoarse = P_NEARBY_COARSE.matcher(page);
|
||||
while (mCoarse.find())
|
||||
{
|
||||
final Matcher mFine = P_NEARBY_FINE.matcher(mCoarse.group(1));
|
||||
if (mFine.matches())
|
||||
{
|
||||
final int parsedId = Integer.parseInt(mFine.group(1));
|
||||
final double parsedLon = latLonToDouble(Integer.parseInt(mFine.group(2)));
|
||||
final double parsedLat = latLonToDouble(Integer.parseInt(mFine.group(3)));
|
||||
final String parsedName = ParserUtils.resolveEntities(mFine.group(4));
|
||||
|
||||
final Station station = new Station(parsedId, parsedName, parsedLat, parsedLon, 0, null, null);
|
||||
stations.add(station);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot parse '" + mCoarse.group(1) + "' on " + uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("at least one of stationId or lat/lon must be given");
|
||||
}
|
||||
|
||||
if (maxStations == 0 || maxStations >= stations.size())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue