Merge pull request #6372 from osmandapp/xmd5a_branch

Add exits to stops
This commit is contained in:
vshcherb 2019-01-11 15:36:07 +01:00 committed by GitHub
commit 8939b84228
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1417 additions and 108 deletions

View file

@ -5,17 +5,20 @@ import gnu.trove.map.hash.TIntObjectHashMap;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.binary.OsmandOdb.TransportRouteSchedule;
import net.osmand.data.TransportSchedule;
import net.osmand.data.TransportStop;
import net.osmand.data.TransportStopExit;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.util.MapUtils;
import net.sf.junidecode.Junidecode;
import com.google.protobuf.ByteString;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.WireFormat;
@ -238,6 +241,11 @@ public class BinaryMapTransportReaderAdapter {
stringTable.putIfAbsent(i, "");
return ((char) i)+"";
}
private String regStr(TIntObjectHashMap<String> stringTable, int i) throws IOException{
stringTable.putIfAbsent(i, "");
return ((char) i)+"";
}
public net.osmand.data.TransportRoute getTransportRoute(int filePointer, TIntObjectHashMap<String> stringTable,
boolean onlyDescription) throws IOException {
@ -446,12 +454,26 @@ public class BinaryMapTransportReaderAdapter {
}
protected void initializeNames(TIntObjectHashMap<String> stringTable, TransportStop s) {
for (TransportStopExit exit : s.getExits()) {
if (exit.getRef().length() > 0) {
exit.setRef(stringTable.get(exit.getRef().charAt(0)));
}
}
if (s.getName().length() > 0) {
s.setName(stringTable.get(s.getName().charAt(0)));
}
if (s.getEnName(false).length() > 0) {
s.setEnName(stringTable.get(s.getEnName(false).charAt(0)));
}
Map<String, String> namesMap = new HashMap<>(s.getNamesMap(false));
if (!s.getNamesMap(false).isEmpty()) {
s.getNamesMap(false).clear();
}
Iterator<Map.Entry<String, String>> it = namesMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> e = it.next();
s.setName(stringTable.get(e.getKey().charAt(0)),stringTable.get(e.getValue().charAt(0)));
}
}
@ -517,6 +539,7 @@ public class BinaryMapTransportReaderAdapter {
TransportStop dataObject = new TransportStop();
dataObject.setLocation(BinaryMapIndexReader.TRANSPORT_STOP_ZOOM, x, y);
dataObject.setFileOffset(shift);
List<String> names = null;
while(true){
int t = codedIS.readTag();
tag = WireFormat.getTagFieldNumber(t);
@ -543,16 +566,76 @@ public class BinaryMapTransportReaderAdapter {
} else {
skipUnknownField(t);
}
break;
case OsmandOdb.TransportStop.ADDITIONALNAMEPAIRS_FIELD_NUMBER :
if (req.stringTable != null) {
int sizeL = codedIS.readRawVarint32();
int oldRef = codedIS.pushLimit(sizeL);
while (codedIS.getBytesUntilLimit() > 0) {
dataObject.setName(regStr(req.stringTable,codedIS.readRawVarint32()),
regStr(req.stringTable,codedIS.readRawVarint32()));
}
codedIS.popLimit(oldRef);
} else {
skipUnknownField(t);
}
break;
case OsmandOdb.TransportStop.ID_FIELD_NUMBER :
dataObject.setId(codedIS.readSInt64());
break;
case OsmandOdb.TransportStop.EXITS_FIELD_NUMBER :
int length = codedIS.readRawVarint32();
int oldLimit = codedIS.pushLimit(length);
TransportStopExit transportStopExit = readTransportStopExit(cleft, ctop, req);
dataObject.addExit(transportStopExit);
codedIS.popLimit(oldLimit);
break;
default:
skipUnknownField(t);
break;
}
}
}
private TransportStopExit readTransportStopExit(int cleft, int ctop, SearchRequest<TransportStop> req) throws IOException {
TransportStopExit dataObject = new TransportStopExit();
int x = 0;
int y = 0;
while (true) {
int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t);
switch (tag) {
case 0:
if (dataObject.getName("en").length() == 0) {
dataObject.setEnName(Junidecode.unidecode(dataObject.getName()));
}
if (x != 0 || y != 0) {
dataObject.setLocation(BinaryMapIndexReader.TRANSPORT_STOP_ZOOM, x, y);
}
return dataObject;
case OsmandOdb.TransportStopExit.REF_FIELD_NUMBER:
if (req.stringTable != null) {
dataObject.setRef(regStr(req.stringTable));
} else {
skipUnknownField(t);
}
break;
case OsmandOdb.TransportStopExit.DX_FIELD_NUMBER:
x = codedIS.readSInt32() + cleft;
break;
case OsmandOdb.TransportStopExit.DY_FIELD_NUMBER:
y = codedIS.readSInt32() + ctop;
break;
default:
skipUnknownField(t);
break;
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -77,6 +77,15 @@ public abstract class MapObject implements Comparable<MapObject> {
}
}
public void setNames(Map<String, String> name) {
if (name != null) {
if (names == null) {
names = new HashMap<String, String>();
}
names.putAll(name);
}
}
public Map<String, String> getNamesMap(boolean includeEn) {
if (!includeEn || Algorithms.isEmpty(enName)) {
if (names == null) {

View file

@ -2,13 +2,20 @@ package net.osmand.data;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TransportStop extends MapObject {
private int[] referencesToRoutes = null;
private Amenity amenity;
public int distance;
public int x31;
public int y31;
private List<TransportStopExit> exits;
private HashMap<String,String> names;
public TransportStop(){
}
@ -39,4 +46,35 @@ public class TransportStop extends MapObject {
y31 = dy << (31 - zoom);
setLocation(MapUtils.getLatitudeFromTile(zoom, dy), MapUtils.getLongitudeFromTile(zoom, dx));
}
public void addExit(TransportStopExit transportStopExit) {
if (exits == null) {
exits = new ArrayList<>();
}
exits.add(transportStopExit);
}
public List<TransportStopExit> getExits () {
if (exits == null) {
return Collections.emptyList();
}
return this.exits;
}
public String getExitsString () {
String exitsString = "";
String refString = "";
if (this.exits != null) {
int i = 1;
exitsString = exitsString + " Exits: [";
for (TransportStopExit e : this.exits ) {
if (e.getRef() != null) {
refString = " [ref:" + e.getRef() + "] ";
}
exitsString = exitsString + " " + i + ")" + refString + e.getName() + " " + e.getLocation() + " ]";
i++;
}
}
return exitsString;
}
}

View file

@ -0,0 +1,27 @@
package net.osmand.data;
import net.osmand.util.MapUtils;
public class TransportStopExit extends MapObject {
public int x31;
public int y31;
public String ref = null;
@Override
public void setLocation(double latitude, double longitude) {
super.setLocation(latitude, longitude);
}
public void setLocation(int zoom, int dx, int dy) {
x31 = dx << (31 - zoom);
y31 = dy << (31 - zoom);
setLocation(MapUtils.getLatitudeFromTile(zoom, dy), MapUtils.getLongitudeFromTile(zoom, dx));
}
public void setRef (String ref) {
this.ref = ref;
}
public String getRef() {
if (ref != null) {
return ref;
}
return "";
}
}

View file

@ -13,6 +13,7 @@ public class OSMSettings {
BOUNDARY("boundary"), //$NON-NLS-1$
POSTAL_CODE("postal_code"), //$NON-NLS-1$
RAILWAY("railway"), //$NON-NLS-1$
STATION("subway"), //$NON-NLS-1$
ONEWAY("oneway"), //$NON-NLS-1$
LAYER("layer"), //$NON-NLS-1$
BRIDGE("bridge"), //$NON-NLS-1$