mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-19 00:39:58 +00:00
AbstractEfaProvider: Switch coordOutputFormat to floating point and enhance precision.
This commit is contained in:
parent
c9e7379a78
commit
7f62ab221e
2 changed files with 25 additions and 23 deletions
|
@ -94,6 +94,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
protected static final String DEFAULT_COORD_ENDPOINT = "XML_COORD_REQUEST";
|
protected static final String DEFAULT_COORD_ENDPOINT = "XML_COORD_REQUEST";
|
||||||
|
|
||||||
protected static final String SERVER_PRODUCT = "efa";
|
protected static final String SERVER_PRODUCT = "efa";
|
||||||
|
protected static final String COORD_FORMAT = "WGS84[DD.ddddddd]";
|
||||||
|
|
||||||
private final HttpUrl departureMonitorEndpoint;
|
private final HttpUrl departureMonitorEndpoint;
|
||||||
private final HttpUrl tripEndpoint;
|
private final HttpUrl tripEndpoint;
|
||||||
|
@ -236,7 +237,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
url.addEncodedQueryParameter("outputFormat", outputFormat);
|
url.addEncodedQueryParameter("outputFormat", outputFormat);
|
||||||
url.addEncodedQueryParameter("language", language);
|
url.addEncodedQueryParameter("language", language);
|
||||||
url.addEncodedQueryParameter("stateless", "1");
|
url.addEncodedQueryParameter("stateless", "1");
|
||||||
url.addEncodedQueryParameter("coordOutputFormat", "WGS84");
|
url.addEncodedQueryParameter("coordOutputFormat", COORD_FORMAT);
|
||||||
|
url.addEncodedQueryParameter("coordOutputFormatTail", "7");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SuggestLocationsResult jsonStopfinderRequest(final Location constraint) throws IOException {
|
protected SuggestLocationsResult jsonStopfinderRequest(final Location constraint) throws IOException {
|
||||||
|
@ -444,9 +446,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
private void appendXmlCoordRequestParameters(final HttpUrl.Builder url, final EnumSet<LocationType> types,
|
private void appendXmlCoordRequestParameters(final HttpUrl.Builder url, final EnumSet<LocationType> types,
|
||||||
final Point coord, final int maxDistance, final int maxLocations) {
|
final Point coord, final int maxDistance, final int maxLocations) {
|
||||||
appendCommonRequestParams(url, "XML");
|
appendCommonRequestParams(url, "XML");
|
||||||
url.addEncodedQueryParameter("coord", ParserUtils.urlEncode(
|
url.addEncodedQueryParameter("coord", ParserUtils.urlEncode(String.format(Locale.ENGLISH, "%.7f:%.7f:%s",
|
||||||
String.format(Locale.ENGLISH, "%2.6f:%2.6f:WGS84", coord.getLonAsDouble(), coord.getLatAsDouble()),
|
coord.getLonAsDouble(), coord.getLatAsDouble(), COORD_FORMAT), requestUrlEncoding));
|
||||||
requestUrlEncoding));
|
|
||||||
if (useStringCoordListOutputFormat)
|
if (useStringCoordListOutputFormat)
|
||||||
url.addEncodedQueryParameter("coordListOutputFormat", "STRING");
|
url.addEncodedQueryParameter("coordListOutputFormat", "STRING");
|
||||||
url.addEncodedQueryParameter("max", Integer.toString(maxLocations != 0 ? maxLocations : 50));
|
url.addEncodedQueryParameter("max", Integer.toString(maxLocations != 0 ? maxLocations : 50));
|
||||||
|
@ -2751,10 +2752,11 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
final Point coords;
|
final Point coords;
|
||||||
if (!"::".equals(coordPart)) {
|
if (!"::".equals(coordPart)) {
|
||||||
final String[] coordParts = coordPart.split(":");
|
final String[] coordParts = coordPart.split(":");
|
||||||
if ("WGS84".equals(coordParts[2])) {
|
final String mapName = coordParts[2];
|
||||||
final int lat = (int) Math.round(Double.parseDouble(coordParts[1]));
|
if (COORD_FORMAT.equals(mapName)) {
|
||||||
final int lon = (int) Math.round(Double.parseDouble(coordParts[0]));
|
final double lat = Double.parseDouble(coordParts[1]);
|
||||||
coords = Point.from1E6(lat, lon);
|
final double lon = Double.parseDouble(coordParts[0]);
|
||||||
|
coords = Point.fromDouble(lat, lon);
|
||||||
} else {
|
} else {
|
||||||
coords = null;
|
coords = null;
|
||||||
}
|
}
|
||||||
|
@ -2876,9 +2878,9 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
XmlPullUtil.enter(pp, "itdCoordinateBaseElemList");
|
XmlPullUtil.enter(pp, "itdCoordinateBaseElemList");
|
||||||
|
|
||||||
while (XmlPullUtil.optEnter(pp, "itdCoordinateBaseElem")) {
|
while (XmlPullUtil.optEnter(pp, "itdCoordinateBaseElem")) {
|
||||||
final int lon = (int) Math.round(Double.parseDouble(XmlPullUtil.valueTag(pp, "x")));
|
final double x = Double.parseDouble(XmlPullUtil.valueTag(pp, "x"));
|
||||||
final int lat = (int) Math.round(Double.parseDouble(XmlPullUtil.valueTag(pp, "y")));
|
final double y = Double.parseDouble(XmlPullUtil.valueTag(pp, "y"));
|
||||||
path.add(Point.from1E6(lat, lon));
|
path.add(Point.fromDouble(y, x));
|
||||||
|
|
||||||
XmlPullUtil.skipExit(pp, "itdCoordinateBaseElem");
|
XmlPullUtil.skipExit(pp, "itdCoordinateBaseElem");
|
||||||
}
|
}
|
||||||
|
@ -2893,23 +2895,23 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
final String[] parts = coordStr.split(",");
|
final String[] parts = coordStr.split(",");
|
||||||
final int lat = (int) Math.round(Double.parseDouble(parts[1]));
|
final double lat = Double.parseDouble(parts[1]);
|
||||||
final int lon = (int) Math.round(Double.parseDouble(parts[0]));
|
final double lon = Double.parseDouble(parts[0]);
|
||||||
return Point.from1E6(lat, lon);
|
return Point.fromDouble(lat, lon);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point processCoordAttr(final XmlPullParser pp) {
|
private Point processCoordAttr(final XmlPullParser pp) {
|
||||||
final String mapName = XmlPullUtil.optAttr(pp, "mapName", null);
|
final String mapName = XmlPullUtil.optAttr(pp, "mapName", null);
|
||||||
final int x = (int) Math.round(XmlPullUtil.optFloatAttr(pp, "x", 0));
|
final double x = XmlPullUtil.optFloatAttr(pp, "x", 0);
|
||||||
final int y = (int) Math.round(XmlPullUtil.optFloatAttr(pp, "y", 0));
|
final double y = XmlPullUtil.optFloatAttr(pp, "y", 0);
|
||||||
|
|
||||||
if (mapName == null || (x == 0 && y == 0))
|
if (mapName == null || (x == 0 && y == 0))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (!"WGS84".equals(mapName))
|
if (!COORD_FORMAT.equals(mapName))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return Point.from1E6(y, x);
|
return Point.fromDouble(y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Fare processItdGenericTicketGroup(final XmlPullParser pp, final String net, final Currency currency)
|
private Fare processItdGenericTicketGroup(final XmlPullParser pp, final String net, final Currency currency)
|
||||||
|
@ -2975,10 +2977,9 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider {
|
||||||
final String name = locationValue(location);
|
final String name = locationValue(location);
|
||||||
if ((location.type == LocationType.ADDRESS || location.type == LocationType.COORD) && location.hasCoord()) {
|
if ((location.type == LocationType.ADDRESS || location.type == LocationType.COORD) && location.hasCoord()) {
|
||||||
url.addEncodedQueryParameter("type_" + paramSuffix, "coord");
|
url.addEncodedQueryParameter("type_" + paramSuffix, "coord");
|
||||||
url.addEncodedQueryParameter("name_" + paramSuffix, ParserUtils.urlEncode(
|
url.addEncodedQueryParameter("name_" + paramSuffix,
|
||||||
String.format(Locale.ENGLISH, "%.6f:%.6f", location.getLonAsDouble(), location.getLatAsDouble())
|
ParserUtils.urlEncode(String.format(Locale.ENGLISH, "%.7f:%.7f:%s", location.getLonAsDouble(),
|
||||||
+ ":WGS84",
|
location.getLatAsDouble(), COORD_FORMAT), requestUrlEncoding));
|
||||||
requestUrlEncoding));
|
|
||||||
} else if (name != null) {
|
} else if (name != null) {
|
||||||
url.addEncodedQueryParameter("type_" + paramSuffix, locationTypeValue(location));
|
url.addEncodedQueryParameter("type_" + paramSuffix, locationTypeValue(location));
|
||||||
url.addEncodedQueryParameter("name_" + paramSuffix, ParserUtils.urlEncode(name, requestUrlEncoding));
|
url.addEncodedQueryParameter("name_" + paramSuffix, ParserUtils.urlEncode(name, requestUrlEncoding));
|
||||||
|
|
|
@ -52,7 +52,8 @@ public class BayernProviderLiveTest extends AbstractProviderLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nearbyStationsByCoordinate() throws Exception {
|
public void nearbyStationsByCoordinate() throws Exception {
|
||||||
final NearbyLocationsResult result = queryNearbyStations(Location.coord(48135232, 11560650));
|
final NearbyLocationsResult result = queryNearbyStations(
|
||||||
|
Location.coord(Point.fromDouble(48.1331686, 11.5580299))); // München, Beethovenplatz
|
||||||
print(result);
|
print(result);
|
||||||
assertTrue(result.locations.size() > 0);
|
assertTrue(result.locations.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue