mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-19 00:39:58 +00:00
make 0/0 coordinates valid even if using non-WGS84 ellipsoid
This commit is contained in:
parent
871b08f13a
commit
aaa2a6c810
2 changed files with 68 additions and 29 deletions
|
@ -534,22 +534,25 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
final String place = !"loc".equals(anyType) ? normalizeLocationName(pp.getAttributeValue(null, "locality")) : null;
|
||||
final String name = normalizeLocationName(pp.getAttributeValue(null, "objectName"));
|
||||
|
||||
final String mapName = pp.getAttributeValue(null, "mapName");
|
||||
final String mapName = XmlPullUtil.optAttr(pp, "mapName", null);
|
||||
final float x = XmlPullUtil.optFloatAttr(pp, "x", 0);
|
||||
final float y = XmlPullUtil.optFloatAttr(pp, "y", 0);
|
||||
|
||||
final int lat;
|
||||
final int lon;
|
||||
if (mapName == null || mapName.length() == 0)
|
||||
if (mapName == null || (x == 0 && y == 0))
|
||||
{
|
||||
lat = 0;
|
||||
lon = 0;
|
||||
}
|
||||
else if ("WGS84".equals(mapName))
|
||||
{
|
||||
lat = Math.round(XmlPullUtil.floatAttr(pp, "y"));
|
||||
lon = Math.round(XmlPullUtil.floatAttr(pp, "x"));
|
||||
lat = Math.round(y);
|
||||
lon = Math.round(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("unknown mapName: " + mapName);
|
||||
throw new IllegalStateException("unknown mapName=" + mapName + " x=" + x + " y=" + y);
|
||||
}
|
||||
|
||||
LocationType type;
|
||||
|
@ -611,22 +614,25 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
{
|
||||
final int id = Integer.parseInt(pp.getAttributeValue(null, "stopID"));
|
||||
|
||||
final String mapName = pp.getAttributeValue(null, "mapName");
|
||||
final String mapName = XmlPullUtil.optAttr(pp, "mapName", null);
|
||||
final float x = XmlPullUtil.optFloatAttr(pp, "x", 0);
|
||||
final float y = XmlPullUtil.optFloatAttr(pp, "y", 0);
|
||||
|
||||
final int lat;
|
||||
final int lon;
|
||||
if (mapName == null || mapName.length() == 0)
|
||||
if (mapName == null || (x == 0 && y == 0))
|
||||
{
|
||||
lat = 0;
|
||||
lon = 0;
|
||||
}
|
||||
else if ("WGS84".equals(mapName))
|
||||
{
|
||||
lat = Math.round(XmlPullUtil.floatAttr(pp, "y"));
|
||||
lon = Math.round(XmlPullUtil.floatAttr(pp, "x"));
|
||||
lat = Math.round(y);
|
||||
lon = Math.round(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("unknown mapName: " + mapName);
|
||||
throw new IllegalStateException("unknown mapName=" + mapName + " x=" + x + " y=" + y);
|
||||
}
|
||||
|
||||
final String place = normalizeLocationName(XmlPullUtil.attr(pp, "place"));
|
||||
|
@ -701,21 +707,24 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
XmlPullUtil.enter(pp, "itdOdvAssignedStops");
|
||||
while (XmlPullUtil.test(pp, "itdOdvAssignedStop"))
|
||||
{
|
||||
final String parsedMapName = pp.getAttributeValue(null, "mapName");
|
||||
if (parsedMapName != null && parsedMapName.length() != 0)
|
||||
final String mapName = pp.getAttributeValue(null, "mapName");
|
||||
final float x = XmlPullUtil.optFloatAttr(pp, "x", 0);
|
||||
final float y = XmlPullUtil.optFloatAttr(pp, "y", 0);
|
||||
|
||||
if (!(mapName == null || mapName.length() == 0 || (x == 0 && y == 0)))
|
||||
{
|
||||
final int parsedLocationId = XmlPullUtil.intAttr(pp, "stopID");
|
||||
// final String parsedLongName = normalizeLocationName(XmlPullUtil.attr(pp,
|
||||
// "nameWithPlace"));
|
||||
final String parsedPlace = normalizeLocationName(XmlPullUtil.attr(pp, "place"));
|
||||
final int parsedLon = Math.round(XmlPullUtil.floatAttr(pp, "x"));
|
||||
final int parsedLat = Math.round(XmlPullUtil.floatAttr(pp, "y"));
|
||||
final int parsedLat = Math.round(y);
|
||||
final int parsedLon = Math.round(x);
|
||||
XmlPullUtil.enter(pp, "itdOdvAssignedStop");
|
||||
final String parsedName = normalizeLocationName(pp.getText());
|
||||
XmlPullUtil.exit(pp, "itdOdvAssignedStop");
|
||||
|
||||
if (!"WGS84".equals(parsedMapName))
|
||||
throw new IllegalStateException("unknown mapName: " + parsedMapName);
|
||||
if (!"WGS84".equals(mapName))
|
||||
throw new IllegalStateException("unknown mapName=" + mapName + " x=" + x + " y=" + y);
|
||||
|
||||
final Location newStation = new Location(LocationType.STATION, parsedLocationId, parsedLat, parsedLon, parsedPlace,
|
||||
parsedName);
|
||||
|
@ -1279,24 +1288,27 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
StationDepartures assignedStationDepartures = findStationDepartures(result.stationDepartures, assignedStopId);
|
||||
if (assignedStationDepartures == null)
|
||||
{
|
||||
final String mapName = pp.getAttributeValue(null, "mapName");
|
||||
final String mapName = XmlPullUtil.optAttr(pp, "mapName", null);
|
||||
final float x = XmlPullUtil.optFloatAttr(pp, "x", 0);
|
||||
final float y = XmlPullUtil.optFloatAttr(pp, "y", 0);
|
||||
|
||||
final int lat;
|
||||
final int lon;
|
||||
|
||||
if (mapName == null || mapName.length() == 0)
|
||||
if (mapName == null || (x == 0 && y == 0))
|
||||
{
|
||||
lat = 0;
|
||||
lon = 0;
|
||||
}
|
||||
else if ("WGS84".equals(mapName))
|
||||
{
|
||||
lat = Math.round(XmlPullUtil.floatAttr(pp, "y"));
|
||||
lon = Math.round(XmlPullUtil.floatAttr(pp, "x"));
|
||||
lat = Math.round(y);
|
||||
lon = Math.round(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("unknown mapName: " + mapName);
|
||||
throw new IllegalStateException("unknown mapName=" + mapName + " x=" + x + " y=" + y);
|
||||
}
|
||||
|
||||
// final String name = normalizeLocationName(XmlPullUtil.attr(pp, "nameWO"));
|
||||
|
||||
assignedStationDepartures = new StationDepartures(new Location(LocationType.STATION, assignedStopId, lat, lon),
|
||||
|
@ -1389,22 +1401,25 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
if (name == null)
|
||||
name = normalizeLocationName(pp.getAttributeValue(null, "name"));
|
||||
|
||||
final String mapName = pp.getAttributeValue(null, "mapName");
|
||||
final String mapName = XmlPullUtil.optAttr(pp, "mapName", null);
|
||||
final float x = XmlPullUtil.optFloatAttr(pp, "x", 0);
|
||||
final float y = XmlPullUtil.optFloatAttr(pp, "y", 0);
|
||||
|
||||
final int lat;
|
||||
final int lon;
|
||||
if (mapName == null || mapName.length() == 0)
|
||||
if (mapName == null || (x == 0 && y == 0))
|
||||
{
|
||||
lat = 0;
|
||||
lon = 0;
|
||||
}
|
||||
else if ("WGS84".equals(mapName))
|
||||
{
|
||||
lat = Math.round(XmlPullUtil.floatAttr(pp, "y"));
|
||||
lon = Math.round(XmlPullUtil.floatAttr(pp, "x"));
|
||||
lat = Math.round(y);
|
||||
lon = Math.round(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("unknown mapName: " + mapName);
|
||||
throw new IllegalStateException("unknown mapName=" + mapName + " x=" + x + " y=" + y);
|
||||
}
|
||||
|
||||
return new Location(LocationType.STATION, id, lat, lon, place, name);
|
||||
|
|
|
@ -102,6 +102,21 @@ public final class XmlPullUtil
|
|||
return pp.getAttributeValue(null, attrName).trim();
|
||||
}
|
||||
|
||||
public static String optAttr(final XmlPullParser pp, final String attrName, final String defaultValue)
|
||||
{
|
||||
final String attr = pp.getAttributeValue(null, attrName);
|
||||
|
||||
if (attr != null)
|
||||
{
|
||||
final String trimmedAttr = attr.trim();
|
||||
|
||||
if (trimmedAttr.length() > 0)
|
||||
return trimmedAttr;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static int intAttr(final XmlPullParser pp, final String attrName)
|
||||
{
|
||||
return Integer.parseInt(pp.getAttributeValue(null, attrName).trim());
|
||||
|
@ -109,9 +124,9 @@ public final class XmlPullUtil
|
|||
|
||||
public static int optIntAttr(final XmlPullParser pp, final String attrName, final int defaultValue)
|
||||
{
|
||||
final String attr = pp.getAttributeValue(null, attrName);
|
||||
final String attr = optAttr(pp, attrName, null);
|
||||
if (attr != null)
|
||||
return Integer.parseInt(attr.trim());
|
||||
return Integer.parseInt(attr);
|
||||
else
|
||||
return defaultValue;
|
||||
}
|
||||
|
@ -121,6 +136,15 @@ public final class XmlPullUtil
|
|||
return Float.parseFloat(pp.getAttributeValue(null, attrName).trim());
|
||||
}
|
||||
|
||||
public static float optFloatAttr(final XmlPullParser pp, final String attrName, final float defaultValue)
|
||||
{
|
||||
final String attr = optAttr(pp, attrName, null);
|
||||
if (attr != null)
|
||||
return Float.parseFloat(attr);
|
||||
else
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static void requireAttr(final XmlPullParser pp, final String attrName, final String requiredValue)
|
||||
{
|
||||
if (!requiredValue.equals(attr(pp, attrName)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue