mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-21 01:39:51 +00:00
Introduce location type for plain coordinates.
This commit is contained in:
parent
71d88fcd18
commit
4b65f0145c
70 changed files with 186 additions and 174 deletions
|
@ -470,7 +470,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
else if ("poi".equals(ty))
|
||||
type = LocationType.POI;
|
||||
else if ("loc".equals(ty))
|
||||
type = LocationType.ADDRESS;
|
||||
type = LocationType.COORD;
|
||||
else if ("street".equals(ty))
|
||||
type = LocationType.ADDRESS;
|
||||
else if ("singlehouse".equals(ty))
|
||||
|
@ -833,6 +833,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
final String buildingName = XmlPullUtil.optAttr(pp, "buildingName", null);
|
||||
final String buildingNumber = XmlPullUtil.optAttr(pp, "buildingNumber", null);
|
||||
final String postCode = XmlPullUtil.optAttr(pp, "postCode", null);
|
||||
final String streetName = XmlPullUtil.optAttr(pp, "streetName", null);
|
||||
final Point coord = processCoordAttr(pp);
|
||||
|
||||
final String nameElem = normalizeLocationName(XmlPullUtil.valueTag(pp, "odvNameElem"));
|
||||
|
@ -844,42 +845,53 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
if ("stop".equals(type))
|
||||
{
|
||||
locationType = LocationType.STATION;
|
||||
place = locality;
|
||||
name = objectName;
|
||||
place = locality != null ? locality : defaultPlace;
|
||||
name = objectName != null ? objectName : nameElem;
|
||||
}
|
||||
else if ("poi".equals(type))
|
||||
{
|
||||
locationType = LocationType.POI;
|
||||
place = locality;
|
||||
name = objectName;
|
||||
place = locality != null ? locality : defaultPlace;
|
||||
name = objectName != null ? objectName : nameElem;
|
||||
}
|
||||
else if ("loc".equals(type))
|
||||
{
|
||||
return null;
|
||||
if (coord != null)
|
||||
{
|
||||
locationType = LocationType.COORD;
|
||||
place = null;
|
||||
name = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
locationType = LocationType.ADDRESS;
|
||||
place = null;
|
||||
name = locality;
|
||||
}
|
||||
}
|
||||
else if ("address".equals(type) || "singlehouse".equals(type))
|
||||
{
|
||||
locationType = LocationType.ADDRESS;
|
||||
place = locality;
|
||||
place = locality != null ? locality : defaultPlace;
|
||||
name = objectName + (buildingNumber != null ? " " + buildingNumber : "");
|
||||
}
|
||||
else if ("street".equals(type) || "crossing".equals(type))
|
||||
{
|
||||
locationType = LocationType.ADDRESS;
|
||||
place = locality;
|
||||
name = objectName;
|
||||
place = locality != null ? locality : defaultPlace;
|
||||
name = objectName != null ? objectName : nameElem;
|
||||
}
|
||||
else if ("postcode".equals(type))
|
||||
{
|
||||
locationType = LocationType.ADDRESS;
|
||||
place = locality;
|
||||
place = locality != null ? locality : defaultPlace;
|
||||
name = postCode;
|
||||
}
|
||||
else if ("buildingname".equals(type))
|
||||
{
|
||||
locationType = LocationType.ADDRESS;
|
||||
place = locality;
|
||||
name = buildingName;
|
||||
place = locality != null ? locality : defaultPlace;
|
||||
name = buildingName != null ? buildingName : streetName;
|
||||
}
|
||||
else if ("coord".equals(type))
|
||||
{
|
||||
|
@ -892,7 +904,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
throw new IllegalArgumentException("unknown type/anyType: " + type);
|
||||
}
|
||||
|
||||
return new Location(locationType, id, coord, place != null ? place : defaultPlace, name != null ? name : nameElem);
|
||||
return new Location(locationType, id, coord, place, name);
|
||||
}
|
||||
|
||||
private Location processItdOdvAssignedStop(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||
|
@ -3271,7 +3283,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
|
||||
private void appendLocation(final StringBuilder uri, final Location location, final String paramSuffix)
|
||||
{
|
||||
if (location.type == LocationType.ADDRESS && location.hasLocation())
|
||||
if ((location.type == LocationType.ADDRESS || location.type == LocationType.COORD) && location.hasLocation())
|
||||
{
|
||||
uri.append("&type_").append(paramSuffix).append("=coord");
|
||||
uri.append("&name_").append(paramSuffix).append("=")
|
||||
|
@ -3291,6 +3303,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
return "stop";
|
||||
if (type == LocationType.ADDRESS)
|
||||
return "any"; // strange, matches with anyObjFilter
|
||||
if (type == LocationType.COORD)
|
||||
return "coord";
|
||||
if (type == LocationType.POI)
|
||||
return "poi";
|
||||
if (type == LocationType.ANY)
|
||||
|
|
|
@ -1316,6 +1316,8 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
else if (location.type == LocationType.ADDRESS && location.hasLocation())
|
||||
return "<Address type=\"WGS84\" x=\"" + location.lon + "\" y=\"" + location.lat + "\" name=\""
|
||||
+ (location.place != null ? location.place + ", " : "") + location.name + "\" />";
|
||||
else if (location.type == LocationType.COORD && location.hasLocation())
|
||||
return "<Coord type=\"WGS84\" x=\"" + location.lon + "\" y=\"" + location.lat + "\" />";
|
||||
else
|
||||
throw new IllegalArgumentException("cannot handle: " + location);
|
||||
}
|
||||
|
@ -1354,7 +1356,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
return 1;
|
||||
if (type == LocationType.POI)
|
||||
return 4;
|
||||
if (type == LocationType.ADDRESS && location.hasLocation())
|
||||
if (type == LocationType.COORD || (type == LocationType.ADDRESS && location.hasLocation()))
|
||||
return 16;
|
||||
if (type == LocationType.ADDRESS && location.name != null)
|
||||
return 2;
|
||||
|
|
|
@ -791,7 +791,7 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider
|
|||
|
||||
// Build query uri depending of location type.
|
||||
final String queryUriType;
|
||||
if (location.type == LocationType.ADDRESS || location.type == LocationType.ANY)
|
||||
if (location.type == LocationType.COORD || location.type == LocationType.ADDRESS || location.type == LocationType.ANY)
|
||||
{
|
||||
if (!location.hasLocation())
|
||||
{
|
||||
|
|
|
@ -53,6 +53,11 @@ public final class Location implements Serializable
|
|||
|
||||
checkArgument(id == null || id.length() > 0, "ID cannot be the empty string");
|
||||
checkArgument(place == null || name != null, "place '%s' without name cannot exist", place);
|
||||
if (type == LocationType.COORD)
|
||||
{
|
||||
checkArgument(hasLocation(), "coordinates missing");
|
||||
checkArgument(place == null && name == null, "coordinates cannot have place or name");
|
||||
}
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final String id, final Point coord, final String place, final String name)
|
||||
|
@ -62,24 +67,12 @@ public final class Location implements Serializable
|
|||
|
||||
public Location(final LocationType type, final String id, final String place, final String name)
|
||||
{
|
||||
this.type = checkNotNull(type);
|
||||
this.id = id;
|
||||
this.lat = 0;
|
||||
this.lon = 0;
|
||||
this.place = place;
|
||||
this.name = name;
|
||||
|
||||
checkArgument(place == null || name != null, "place '%s' without name cannot exist", place);
|
||||
this(type, id, 0, 0, place, name);
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final String id, final int lat, final int lon)
|
||||
{
|
||||
this.type = checkNotNull(type);
|
||||
this.id = id;
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
this.place = null;
|
||||
this.name = null;
|
||||
this(type, id, lat, lon, null, null);
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final String id, final Point coord)
|
||||
|
@ -89,27 +82,17 @@ public final class Location implements Serializable
|
|||
|
||||
public Location(final LocationType type, final String id)
|
||||
{
|
||||
this.type = checkNotNull(type);
|
||||
this.id = id;
|
||||
this.lat = 0;
|
||||
this.lon = 0;
|
||||
this.place = null;
|
||||
this.name = null;
|
||||
this(type, id, null, null);
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final int lat, final int lon)
|
||||
public static Location coord(final int lat, final int lon)
|
||||
{
|
||||
this.type = checkNotNull(type);
|
||||
this.id = null;
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
this.place = null;
|
||||
this.name = null;
|
||||
return new Location(LocationType.COORD, null, lat, lon);
|
||||
}
|
||||
|
||||
public Location(final LocationType type, final Point coord)
|
||||
public static Location coord(final Point coord)
|
||||
{
|
||||
this(type, coord != null ? coord.lat : 0, coord != null ? coord.lon : 0);
|
||||
return new Location(LocationType.COORD, null, coord.lat, coord.lon);
|
||||
}
|
||||
|
||||
public final boolean hasId()
|
||||
|
@ -135,7 +118,7 @@ public final class Location implements Serializable
|
|||
if (type == LocationType.POI)
|
||||
return true;
|
||||
|
||||
if (type == LocationType.ADDRESS)
|
||||
if (type == LocationType.ADDRESS || type == LocationType.COORD)
|
||||
return hasLocation();
|
||||
|
||||
return false;
|
||||
|
@ -196,7 +179,7 @@ public final class Location implements Serializable
|
|||
public String toString()
|
||||
{
|
||||
final ToStringHelper helper = MoreObjects.toStringHelper(this).addValue(type).addValue(id);
|
||||
if (lat != 0 || lon != 0)
|
||||
if (hasLocation())
|
||||
helper.addValue(lat + "/" + lon);
|
||||
return helper.add("place", place).add("name", name).omitNullValues().toString();
|
||||
}
|
||||
|
|
|
@ -22,5 +22,14 @@ package de.schildbach.pte.dto;
|
|||
*/
|
||||
public enum LocationType
|
||||
{
|
||||
ANY, STATION, POI, ADDRESS
|
||||
/** Location can represent any of the below. Mainly meant for user input. */
|
||||
ANY,
|
||||
/** Location represents a station or stop. */
|
||||
STATION,
|
||||
/** Location represents a point of interest. */
|
||||
POI,
|
||||
/** Location represents a postal address. */
|
||||
ADDRESS,
|
||||
/** Location represents a just a plain coordinate, e.g. acquired by GPS. */
|
||||
COORD
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue