Introduce id and restrictions

This commit is contained in:
Victor Shcherb 2012-06-07 01:10:19 +02:00
parent c5f2156e4a
commit 2c8117f738
6 changed files with 205 additions and 171 deletions

View file

@ -18222,7 +18222,7 @@ public final class OsmandOdb {
return net.osmand.binary.OsmandOdb.internal_static_IdTable_fieldAccessorTable; return net.osmand.binary.OsmandOdb.internal_static_IdTable_fieldAccessorTable;
} }
// repeated uint64 routeId = 1; // repeated sint64 routeId = 1;
public static final int ROUTEID_FIELD_NUMBER = 1; public static final int ROUTEID_FIELD_NUMBER = 1;
private java.util.List<java.lang.Long> routeId_ = private java.util.List<java.lang.Long> routeId_ =
java.util.Collections.emptyList(); java.util.Collections.emptyList();
@ -18234,7 +18234,7 @@ public final class OsmandOdb {
return routeId_.get(index); return routeId_.get(index);
} }
// repeated uint64 pointId = 2; // repeated sint64 pointId = 2;
public static final int POINTID_FIELD_NUMBER = 2; public static final int POINTID_FIELD_NUMBER = 2;
private java.util.List<java.lang.Long> pointId_ = private java.util.List<java.lang.Long> pointId_ =
java.util.Collections.emptyList(); java.util.Collections.emptyList();
@ -18258,10 +18258,10 @@ public final class OsmandOdb {
throws java.io.IOException { throws java.io.IOException {
getSerializedSize(); getSerializedSize();
for (long element : getRouteIdList()) { for (long element : getRouteIdList()) {
output.writeUInt64(1, element); output.writeSInt64(1, element);
} }
for (long element : getPointIdList()) { for (long element : getPointIdList()) {
output.writeUInt64(2, element); output.writeSInt64(2, element);
} }
getUnknownFields().writeTo(output); getUnknownFields().writeTo(output);
} }
@ -18277,7 +18277,7 @@ public final class OsmandOdb {
int dataSize = 0; int dataSize = 0;
for (long element : getRouteIdList()) { for (long element : getRouteIdList()) {
dataSize += com.google.protobuf.CodedOutputStream dataSize += com.google.protobuf.CodedOutputStream
.computeUInt64SizeNoTag(element); .computeSInt64SizeNoTag(element);
} }
size += dataSize; size += dataSize;
size += 1 * getRouteIdList().size(); size += 1 * getRouteIdList().size();
@ -18286,7 +18286,7 @@ public final class OsmandOdb {
int dataSize = 0; int dataSize = 0;
for (long element : getPointIdList()) { for (long element : getPointIdList()) {
dataSize += com.google.protobuf.CodedOutputStream dataSize += com.google.protobuf.CodedOutputStream
.computeUInt64SizeNoTag(element); .computeSInt64SizeNoTag(element);
} }
size += dataSize; size += dataSize;
size += 1 * getPointIdList().size(); size += 1 * getPointIdList().size();
@ -18507,27 +18507,27 @@ public final class OsmandOdb {
break; break;
} }
case 8: { case 8: {
addRouteId(input.readUInt64()); addRouteId(input.readSInt64());
break; break;
} }
case 10: { case 10: {
int length = input.readRawVarint32(); int length = input.readRawVarint32();
int limit = input.pushLimit(length); int limit = input.pushLimit(length);
while (input.getBytesUntilLimit() > 0) { while (input.getBytesUntilLimit() > 0) {
addRouteId(input.readUInt64()); addRouteId(input.readSInt64());
} }
input.popLimit(limit); input.popLimit(limit);
break; break;
} }
case 16: { case 16: {
addPointId(input.readUInt64()); addPointId(input.readSInt64());
break; break;
} }
case 18: { case 18: {
int length = input.readRawVarint32(); int length = input.readRawVarint32();
int limit = input.pushLimit(length); int limit = input.pushLimit(length);
while (input.getBytesUntilLimit() > 0) { while (input.getBytesUntilLimit() > 0) {
addPointId(input.readUInt64()); addPointId(input.readSInt64());
} }
input.popLimit(limit); input.popLimit(limit);
break; break;
@ -18537,7 +18537,7 @@ public final class OsmandOdb {
} }
// repeated uint64 routeId = 1; // repeated sint64 routeId = 1;
public java.util.List<java.lang.Long> getRouteIdList() { public java.util.List<java.lang.Long> getRouteIdList() {
return java.util.Collections.unmodifiableList(result.routeId_); return java.util.Collections.unmodifiableList(result.routeId_);
} }
@ -18571,7 +18571,7 @@ public final class OsmandOdb {
return this; return this;
} }
// repeated uint64 pointId = 2; // repeated sint64 pointId = 2;
public java.util.List<java.lang.Long> getPointIdList() { public java.util.List<java.lang.Long> getPointIdList() {
return java.util.Collections.unmodifiableList(result.pointId_); return java.util.Collections.unmodifiableList(result.pointId_);
} }
@ -20902,6 +20902,13 @@ public final class OsmandOdb {
public boolean hasIdTable() { return hasIdTable; } public boolean hasIdTable() { return hasIdTable; }
public net.osmand.binary.OsmandOdb.IdTable getIdTable() { return idTable_; } public net.osmand.binary.OsmandOdb.IdTable getIdTable() { return idTable_; }
// optional .StringTable stringTable = 8;
public static final int STRINGTABLE_FIELD_NUMBER = 8;
private boolean hasStringTable;
private net.osmand.binary.OsmandOdb.StringTable stringTable_;
public boolean hasStringTable() { return hasStringTable; }
public net.osmand.binary.OsmandOdb.StringTable getStringTable() { return stringTable_; }
// repeated .RouteData dataObjects = 6; // repeated .RouteData dataObjects = 6;
public static final int DATAOBJECTS_FIELD_NUMBER = 6; public static final int DATAOBJECTS_FIELD_NUMBER = 6;
private java.util.List<net.osmand.binary.OsmandOdb.RouteData> dataObjects_ = private java.util.List<net.osmand.binary.OsmandOdb.RouteData> dataObjects_ =
@ -20926,13 +20933,6 @@ public final class OsmandOdb {
return restrictions_.get(index); return restrictions_.get(index);
} }
// optional .StringTable stringTable = 8;
public static final int STRINGTABLE_FIELD_NUMBER = 8;
private boolean hasStringTable;
private net.osmand.binary.OsmandOdb.StringTable stringTable_;
public boolean hasStringTable() { return hasStringTable; }
public net.osmand.binary.OsmandOdb.StringTable getStringTable() { return stringTable_; }
private void initFields() { private void initFields() {
idTable_ = net.osmand.binary.OsmandOdb.IdTable.getDefaultInstance(); idTable_ = net.osmand.binary.OsmandOdb.IdTable.getDefaultInstance();
stringTable_ = net.osmand.binary.OsmandOdb.StringTable.getDefaultInstance(); stringTable_ = net.osmand.binary.OsmandOdb.StringTable.getDefaultInstance();
@ -21170,6 +21170,9 @@ public final class OsmandOdb {
if (other.hasIdTable()) { if (other.hasIdTable()) {
mergeIdTable(other.getIdTable()); mergeIdTable(other.getIdTable());
} }
if (other.hasStringTable()) {
mergeStringTable(other.getStringTable());
}
if (!other.dataObjects_.isEmpty()) { if (!other.dataObjects_.isEmpty()) {
if (result.dataObjects_.isEmpty()) { if (result.dataObjects_.isEmpty()) {
result.dataObjects_ = new java.util.ArrayList<net.osmand.binary.OsmandOdb.RouteData>(); result.dataObjects_ = new java.util.ArrayList<net.osmand.binary.OsmandOdb.RouteData>();
@ -21182,9 +21185,6 @@ public final class OsmandOdb {
} }
result.restrictions_.addAll(other.restrictions_); result.restrictions_.addAll(other.restrictions_);
} }
if (other.hasStringTable()) {
mergeStringTable(other.getStringTable());
}
this.mergeUnknownFields(other.getUnknownFields()); this.mergeUnknownFields(other.getUnknownFields());
return this; return this;
} }
@ -21283,6 +21283,43 @@ public final class OsmandOdb {
return this; return this;
} }
// optional .StringTable stringTable = 8;
public boolean hasStringTable() {
return result.hasStringTable();
}
public net.osmand.binary.OsmandOdb.StringTable getStringTable() {
return result.getStringTable();
}
public Builder setStringTable(net.osmand.binary.OsmandOdb.StringTable value) {
if (value == null) {
throw new NullPointerException();
}
result.hasStringTable = true;
result.stringTable_ = value;
return this;
}
public Builder setStringTable(net.osmand.binary.OsmandOdb.StringTable.Builder builderForValue) {
result.hasStringTable = true;
result.stringTable_ = builderForValue.build();
return this;
}
public Builder mergeStringTable(net.osmand.binary.OsmandOdb.StringTable value) {
if (result.hasStringTable() &&
result.stringTable_ != net.osmand.binary.OsmandOdb.StringTable.getDefaultInstance()) {
result.stringTable_ =
net.osmand.binary.OsmandOdb.StringTable.newBuilder(result.stringTable_).mergeFrom(value).buildPartial();
} else {
result.stringTable_ = value;
}
result.hasStringTable = true;
return this;
}
public Builder clearStringTable() {
result.hasStringTable = false;
result.stringTable_ = net.osmand.binary.OsmandOdb.StringTable.getDefaultInstance();
return this;
}
// repeated .RouteData dataObjects = 6; // repeated .RouteData dataObjects = 6;
public java.util.List<net.osmand.binary.OsmandOdb.RouteData> getDataObjectsList() { public java.util.List<net.osmand.binary.OsmandOdb.RouteData> getDataObjectsList() {
return java.util.Collections.unmodifiableList(result.dataObjects_); return java.util.Collections.unmodifiableList(result.dataObjects_);
@ -21385,43 +21422,6 @@ public final class OsmandOdb {
return this; return this;
} }
// optional .StringTable stringTable = 8;
public boolean hasStringTable() {
return result.hasStringTable();
}
public net.osmand.binary.OsmandOdb.StringTable getStringTable() {
return result.getStringTable();
}
public Builder setStringTable(net.osmand.binary.OsmandOdb.StringTable value) {
if (value == null) {
throw new NullPointerException();
}
result.hasStringTable = true;
result.stringTable_ = value;
return this;
}
public Builder setStringTable(net.osmand.binary.OsmandOdb.StringTable.Builder builderForValue) {
result.hasStringTable = true;
result.stringTable_ = builderForValue.build();
return this;
}
public Builder mergeStringTable(net.osmand.binary.OsmandOdb.StringTable value) {
if (result.hasStringTable() &&
result.stringTable_ != net.osmand.binary.OsmandOdb.StringTable.getDefaultInstance()) {
result.stringTable_ =
net.osmand.binary.OsmandOdb.StringTable.newBuilder(result.stringTable_).mergeFrom(value).buildPartial();
} else {
result.stringTable_ = value;
}
result.hasStringTable = true;
return this;
}
public Builder clearStringTable() {
result.hasStringTable = false;
result.stringTable_ = net.osmand.binary.OsmandOdb.StringTable.getDefaultInstance();
return this;
}
// @@protoc_insertion_point(builder_scope:OsmAndRoutingIndex.RouteDataBlock) // @@protoc_insertion_point(builder_scope:OsmAndRoutingIndex.RouteDataBlock)
} }
@ -22311,8 +22311,8 @@ public final class OsmandOdb {
"\022\n\ncategories\030\004 \003(\r\022\014\n\004name\030\006 \001(\t\022\016\n\006nam" + "\022\n\ncategories\030\004 \003(\r\022\014\n\004name\030\006 \001(\t\022\016\n\006nam" +
"eEn\030\007 \001(\t\022\n\n\002id\030\010 \001(\004\022\024\n\014openingHours\030\n " + "eEn\030\007 \001(\t\022\n\n\002id\030\010 \001(\004\022\024\n\014openingHours\030\n " +
"\001(\t\022\014\n\004site\030\013 \001(\t\022\r\n\005phone\030\014 \001(\t\022\014\n\004note", "\001(\t\022\014\n\004site\030\013 \001(\t\022\r\n\005phone\030\014 \001(\t\022\014\n\004note",
"\030\r \001(\t\"+\n\007IdTable\022\017\n\007routeId\030\001 \003(\004\022\017\n\007po" + "\030\r \001(\t\"+\n\007IdTable\022\017\n\007routeId\030\001 \003(\022\022\017\n\007po" +
"intId\030\002 \003(\004\"F\n\017RestrictionData\022\014\n\004type\030\001" + "intId\030\002 \003(\022\"F\n\017RestrictionData\022\014\n\004type\030\001" +
" \002(\005\022\014\n\004from\030\002 \002(\005\022\n\n\002to\030\003 \002(\005\022\013\n\003via\030\004 " + " \002(\005\022\014\n\004from\030\002 \002(\005\022\n\n\002to\030\003 \002(\005\022\013\n\003via\030\004 " +
"\001(\005\";\n\nRoutePoint\022\r\n\005point\030\001 \002(\014\022\017\n\007poin" + "\001(\005\";\n\nRoutePoint\022\r\n\005point\030\001 \002(\014\022\017\n\007poin" +
"tId\030\002 \001(\r\022\r\n\005types\030\004 \001(\014\"]\n\tRouteData\022\033\n" + "tId\030\002 \001(\r\022\r\n\005types\030\004 \001(\014\"]\n\tRouteData\022\033\n" +
@ -22329,9 +22329,9 @@ public final class OsmandOdb {
"ottom\030\004 \002(\021\022\023\n\013shiftToData\030\005 \001(\007\022/\n\005boxe" + "ottom\030\004 \002(\021\022\023\n\013shiftToData\030\005 \001(\007\022/\n\005boxe" +
"s\030\007 \003(\0132 .OsmAndRoutingIndex.RouteDataBo" + "s\030\007 \003(\0132 .OsmAndRoutingIndex.RouteDataBo" +
"x\032\227\001\n\016RouteDataBlock\022\031\n\007idTable\030\005 \001(\0132\010." + "x\032\227\001\n\016RouteDataBlock\022\031\n\007idTable\030\005 \001(\0132\010." +
"IdTable\022\037\n\013dataObjects\030\006 \003(\0132\n.RouteData" + "IdTable\022!\n\013stringTable\030\010 \001(\0132\014.StringTab" +
"\022&\n\014restrictions\030\007 \003(\0132\020.RestrictionData", "le\022\037\n\013dataObjects\030\006 \003(\0132\n.RouteData\022&\n\014r",
"\022!\n\013stringTable\030\010 \001(\0132\014.StringTableB\023\n\021n" + "estrictions\030\007 \003(\0132\020.RestrictionDataB\023\n\021n" +
"et.osmand.binary" "et.osmand.binary"
}; };
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
@ -22681,7 +22681,7 @@ public final class OsmandOdb {
internal_static_OsmAndRoutingIndex_RouteDataBlock_fieldAccessorTable = new internal_static_OsmAndRoutingIndex_RouteDataBlock_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable( com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_OsmAndRoutingIndex_RouteDataBlock_descriptor, internal_static_OsmAndRoutingIndex_RouteDataBlock_descriptor,
new java.lang.String[] { "IdTable", "DataObjects", "Restrictions", "StringTable", }, new java.lang.String[] { "IdTable", "StringTable", "DataObjects", "Restrictions", },
net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock.class, net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock.class,
net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock.Builder.class); net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock.Builder.class);
return null; return null;

View file

@ -208,9 +208,11 @@ public class BinaryMapIndexWriter {
int len = writeInt32Size(); int len = writeInt32Size();
log.info("- ROUTE TYPE SIZE SIZE " + BinaryMapIndexWriter.ROUTE_TYPES_SIZE ); //$NON-NLS-1$ log.info("- ROUTE TYPE SIZE SIZE " + BinaryMapIndexWriter.ROUTE_TYPES_SIZE ); //$NON-NLS-1$
log.info("- ROUTE COORDINATES SIZE " + BinaryMapIndexWriter.ROUTE_COORDINATES_SIZE + " COUNT " + BinaryMapIndexWriter.ROUTE_COORDINATES_COUNT); //$NON-NLS-1$ log.info("- ROUTE COORDINATES SIZE " + BinaryMapIndexWriter.ROUTE_COORDINATES_SIZE + " COUNT " + BinaryMapIndexWriter.ROUTE_COORDINATES_COUNT); //$NON-NLS-1$
log.info("- ROUTE POINTS SIZE " + BinaryMapIndexWriter.ROUTE_POINTS_SIZE);
log.info("- ROUTE ID SIZE " + BinaryMapIndexWriter.ROUTE_ID_SIZE); //$NON-NLS-1$ log.info("- ROUTE ID SIZE " + BinaryMapIndexWriter.ROUTE_ID_SIZE); //$NON-NLS-1$
log.info("-- ROUTE_DATA " + BinaryMapIndexWriter.ROUTE_DATA_SIZE); //$NON-NLS-1$ log.info("-- ROUTE_DATA " + BinaryMapIndexWriter.ROUTE_DATA_SIZE); //$NON-NLS-1$
ROUTE_TYPES_SIZE = ROUTE_DATA_SIZE = ROUTE_ID_SIZE = ROUTE_COORDINATES_COUNT = ROUTE_COORDINATES_SIZE = 0; ROUTE_TYPES_SIZE = ROUTE_DATA_SIZE = ROUTE_POINTS_SIZE = ROUTE_ID_SIZE =
ROUTE_COORDINATES_COUNT = ROUTE_COORDINATES_SIZE = 0;
log.info("ROUTE INDEX SIZE : " + len); log.info("ROUTE INDEX SIZE : " + len);
} }
@ -396,6 +398,7 @@ public class BinaryMapIndexWriter {
public static int ROUTE_TYPES_SIZE = 0; public static int ROUTE_TYPES_SIZE = 0;
public static int ROUTE_COORDINATES_SIZE = 0; public static int ROUTE_COORDINATES_SIZE = 0;
public static int ROUTE_COORDINATES_COUNT = 0; public static int ROUTE_COORDINATES_COUNT = 0;
public static int ROUTE_POINTS_SIZE = 0;
public static int ROUTE_DATA_SIZE = 0; public static int ROUTE_DATA_SIZE = 0;
public MapDataBlock.Builder createWriteMapDataBlock(long baseid) throws IOException { public MapDataBlock.Builder createWriteMapDataBlock(long baseid) throws IOException {
@ -408,17 +411,15 @@ public class BinaryMapIndexWriter {
throws IOException { throws IOException {
checkPeekState(ROUTE_INDEX_INIT); checkPeekState(ROUTE_INDEX_INIT);
StringTable.Builder bs = OsmandOdb.StringTable.newBuilder();
if (stringTable != null) { if (stringTable != null && stringTable.size() > 0) {
for (String s : stringTable.keySet()) { StringTable.Builder bs = OsmandOdb.StringTable.newBuilder();
bs.addS(s); StringTable st = bs.build();
} builder.setStringTable(st);
int size = st.getSerializedSize();
STRING_TABLE_SIZE += CodedOutputStream.computeTagSize(OsmandOdb.MapDataBlock.STRINGTABLE_FIELD_NUMBER)
+ CodedOutputStream.computeRawVarint32Size(size) + size;
} }
StringTable st = bs.build();
builder.setStringTable(st);
int size = st.getSerializedSize();
STRING_TABLE_SIZE += CodedOutputStream.computeTagSize(OsmandOdb.MapDataBlock.STRINGTABLE_FIELD_NUMBER)
+ CodedOutputStream.computeRawVarint32Size(size) + size;
codedOutStream.writeTag(OsmAndMapIndex.MapRootLevel.BLOCKS_FIELD_NUMBER, FieldType.MESSAGE.getWireType()); codedOutStream.writeTag(OsmAndMapIndex.MapRootLevel.BLOCKS_FIELD_NUMBER, FieldType.MESSAGE.getWireType());
@ -451,7 +452,7 @@ public class BinaryMapIndexWriter {
public RouteData writeRouteData(int diffId, int pleft, int ptop, int[] types, RoutePointToWrite[] points, public RouteData writeRouteData(int diffId, int pleft, int ptop, int[] types, RoutePointToWrite[] points,
Map<MapRouteType, String> names, Map<String, Integer> stringTable, RouteDataBlock.Builder dataBlock, Map<MapRouteType, String> names, Map<String, Integer> stringTable, RouteDataBlock.Builder dataBlock,
boolean allowCoordinateSimplification) boolean allowCoordinateSimplification, boolean writePointId)
throws IOException { throws IOException {
RouteData.Builder builder = RouteData.newBuilder(); RouteData.Builder builder = RouteData.newBuilder();
builder.setRouteId(diffId); builder.setRouteId(diffId);
@ -468,8 +469,9 @@ public class BinaryMapIndexWriter {
for(int k=0; k<points.length; k++) { for(int k=0; k<points.length; k++) {
ROUTE_COORDINATES_COUNT++; ROUTE_COORDINATES_COUNT++;
RoutePoint.Builder point = RoutePoint.newBuilder(); RoutePoint.Builder point = RoutePoint.newBuilder();
// not implemented correctly if(writePointId) {
// point.setPointId(points[j].id); point.setPointId(points[k].id);
}
mapDataBuf.clear(); mapDataBuf.clear();
int tx = (points[k].x >> SHIFT_COORDINATES) - pcalcx; int tx = (points[k].x >> SHIFT_COORDINATES) - pcalcx;
int ty = (points[k].y >> SHIFT_COORDINATES) - pcalcy; int ty = (points[k].y >> SHIFT_COORDINATES) - pcalcy;
@ -487,22 +489,27 @@ public class BinaryMapIndexWriter {
point.setTypes(ByteString.copyFrom(mapDataBuf.toArray())); point.setTypes(ByteString.copyFrom(mapDataBuf.toArray()));
ROUTE_TYPES_SIZE += CodedOutputStream.computeTagSize(RoutePoint.TYPES_FIELD_NUMBER) ROUTE_TYPES_SIZE += CodedOutputStream.computeTagSize(RoutePoint.TYPES_FIELD_NUMBER)
+ CodedOutputStream.computeRawVarint32Size(mapDataBuf.size()) + mapDataBuf.size(); + CodedOutputStream.computeRawVarint32Size(mapDataBuf.size()) + mapDataBuf.size();
builder.addPoints(point.build()); RoutePoint p = point.build();
ROUTE_POINTS_SIZE += p.getSerializedSize() + CodedOutputStream.computeTagSize(RouteData.POINTS_FIELD_NUMBER)
+CodedOutputStream.computeRawVarint32Size(p.getSerializedSize());
builder.addPoints(p);
} }
mapDataBuf.clear(); if (names.size() > 0) {
if (names != null) { mapDataBuf.clear();
for (Entry<MapRouteType, String> s : names.entrySet()) { if (names != null) {
writeRawVarint32(mapDataBuf, s.getKey().getTargetId()); for (Entry<MapRouteType, String> s : names.entrySet()) {
Integer ls = stringTable.get(s.getValue()); writeRawVarint32(mapDataBuf, s.getKey().getTargetId());
if (ls == null) { Integer ls = stringTable.get(s.getValue());
ls = stringTable.size(); if (ls == null) {
stringTable.put(s.getValue(), ls); ls = stringTable.size();
stringTable.put(s.getValue(), ls);
}
writeRawVarint32(mapDataBuf, ls);
} }
writeRawVarint32(mapDataBuf, ls);
} }
STRING_TABLE_SIZE += mapDataBuf.size();
builder.setStringNames(ByteString.copyFrom(mapDataBuf.toArray()));
} }
STRING_TABLE_SIZE += mapDataBuf.size();
builder.setStringNames(ByteString.copyFrom(mapDataBuf.toArray()));
return builder.build(); return builder.build();
} }
@ -638,7 +645,7 @@ public class BinaryMapIndexWriter {
public static class RoutePointToWrite { public static class RoutePointToWrite {
public TIntArrayList types = new TIntArrayList(); public TIntArrayList types = new TIntArrayList();
public long id; public int id;
public int x; public int x;
public int y; public int y;
} }

View file

@ -329,15 +329,13 @@ public class IndexCreator {
private void createDatabaseIndexesStructure() throws SQLException, IOException { private void createDatabaseIndexesStructure() throws SQLException, IOException {
// 2.1 create temporary sqlite database to put temporary results to it // 2.1 create temporary sqlite database to put temporary results to it
if (indexMap || indexAddress || indexTransport || indexPOI) { mapFile = new File(workingDir, getMapFileName());
mapFile = new File(workingDir, getMapFileName()); // to save space
// to save space mapFile.getParentFile().mkdirs();
mapFile.getParentFile().mkdirs(); File tempDBMapFile = new File(workingDir, getTempMapDBFileName());
File tempDBMapFile = new File(workingDir, getTempMapDBFileName()); mapDBDialect.removeDatabase(tempDBMapFile);
mapDBDialect.removeDatabase(tempDBMapFile); mapConnection = (Connection) getDatabaseConnection(tempDBMapFile.getAbsolutePath(), mapDBDialect);
mapConnection = (Connection) getDatabaseConnection(tempDBMapFile.getAbsolutePath(), mapDBDialect); mapConnection.setAutoCommit(false);
mapConnection.setAutoCommit(false);
}
// 2.2 create rtree map // 2.2 create rtree map
if (indexMap) { if (indexMap) {
@ -572,7 +570,6 @@ public class IndexCreator {
} }
// 3.3 MAIN iterate over all entities // 3.3 MAIN iterate over all entities
if (indexPOI || indexAddress || indexMap) {
progress.setGeneralProgress("[50 / 100]"); progress.setGeneralProgress("[50 / 100]");
progress.startTask(Messages.getString("IndexCreator.PROCESS_OSM_NODES"), accessor.getAllNodes()); progress.startTask(Messages.getString("IndexCreator.PROCESS_OSM_NODES"), accessor.getAllNodes());
accessor.iterateOverEntities(progress, EntityType.NODE, new OsmDbVisitor() { accessor.iterateOverEntities(progress, EntityType.NODE, new OsmDbVisitor() {
@ -589,7 +586,6 @@ public class IndexCreator {
iterateMainEntity(e, ctx); iterateMainEntity(e, ctx);
} }
}); });
}
progress.setGeneralProgress("[85 / 100]"); progress.setGeneralProgress("[85 / 100]");
progress.startTask(Messages.getString("IndexCreator.PROCESS_OSM_REL"), accessor.getAllRelations()); progress.startTask(Messages.getString("IndexCreator.PROCESS_OSM_REL"), accessor.getAllRelations());
accessor.iterateOverEntities(progress, EntityType.RELATION, new OsmDbVisitor() { accessor.iterateOverEntities(progress, EntityType.RELATION, new OsmDbVisitor() {
@ -631,7 +627,7 @@ public class IndexCreator {
} }
// 5. Writing binary file // 5. Writing binary file
if (indexMap || indexAddress || indexTransport || indexPOI) { if (indexMap || indexAddress || indexTransport || indexPOI || indexRouting) {
if (mapFile.exists()) { if (mapFile.exists()) {
mapFile.delete(); mapFile.delete();
} }
@ -737,9 +733,9 @@ public class IndexCreator {
public static void main(String[] args) throws IOException, SAXException, SQLException, InterruptedException { public static void main(String[] args) throws IOException, SAXException, SQLException, InterruptedException {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
IndexCreator creator = new IndexCreator(new File("/home/victor/projects/OsmAnd/data/osm-gen/")); //$NON-NLS-1$ IndexCreator creator = new IndexCreator(new File("/home/victor/projects/OsmAnd/data/osm-gen/")); //$NON-NLS-1$
creator.setIndexMap(true); creator.setIndexMap(false);
creator.setIndexAddress(true); creator.setIndexAddress(false);
creator.setIndexPOI(true); creator.setIndexPOI(false);
creator.setIndexTransport(false); creator.setIndexTransport(false);
creator.setIndexRouting(true); creator.setIndexRouting(true);

View file

@ -22,6 +22,7 @@ import java.util.Map;
import net.osmand.Algoritms; import net.osmand.Algoritms;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.binary.OsmandOdb.IdTable;
import net.osmand.binary.OsmandOdb.MapData; import net.osmand.binary.OsmandOdb.MapData;
import net.osmand.binary.OsmandOdb.MapDataBlock; import net.osmand.binary.OsmandOdb.MapDataBlock;
import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock; import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock;
@ -59,9 +60,10 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
private Connection mapConnection; private Connection mapConnection;
private final Log logMapDataWarn; private final Log logMapDataWarn;
private final static boolean WRITE_POINT_ID = false;
private RTree routeTree = null; private RTree routeTree = null;
private MapRoutingTypes routeTypes; private MapRoutingTypes routeTypes;
private TLongObjectHashMap<TLongArrayList> highwayRestrictions = new TLongObjectHashMap<TLongArrayList>(); private TLongObjectHashMap<TLongArrayList> highwayRestrictions = new TLongObjectHashMap<TLongArrayList>();
// local purpose to speed up processing cache allocation // local purpose to speed up processing cache allocation
@ -332,6 +334,15 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
} }
private int registerId(TLongArrayList ids, long id) {
for (int i = 0; i < ids.size(); i++) {
if (ids.getQuick(i) == id) {
return i;
}
}
ids.add(id);
return ids.size() - 1;
}
public void writeBinaryMapBlock(rtree.Node parent, Rect parentBounds, RTree r, BinaryMapIndexWriter writer, PreparedStatement selectData, public void writeBinaryMapBlock(rtree.Node parent, Rect parentBounds, RTree r, BinaryMapIndexWriter writer, PreparedStatement selectData,
TLongObjectHashMap<BinaryFileReference> bounds, Map<String, Integer> tempStringTable, Map<MapRouteType, String> tempNames) TLongObjectHashMap<BinaryFileReference> bounds, Map<String, Integer> tempStringTable, Map<MapRouteType, String> tempNames)
@ -340,6 +351,8 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
RouteDataBlock.Builder dataBlock = null; RouteDataBlock.Builder dataBlock = null;
BinaryFileReference ref = bounds.get(parent.getNodeIndex()); BinaryFileReference ref = bounds.get(parent.getNodeIndex());
TLongArrayList wayMapIds = new TLongArrayList();
TLongArrayList pointMapIds = new TLongArrayList();
for (int i = 0; i < parent.getTotalElements(); i++) { for (int i = 0; i < parent.getTotalElements(); i++) {
if (e[i].getElementType() == rtree.Node.LEAF_NODE) { if (e[i].getElementType() == rtree.Node.LEAF_NODE) {
long id = ((LeafElement) e[i]).getPtr(); long id = ((LeafElement) e[i]).getPtr();
@ -349,11 +362,13 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
ResultSet rs = selectData.executeQuery(); ResultSet rs = selectData.executeQuery();
if (rs.next()) { if (rs.next()) {
long cid = id;
if (dataBlock == null) { if (dataBlock == null) {
dataBlock = RouteDataBlock.newBuilder(); dataBlock = RouteDataBlock.newBuilder();
tempStringTable.clear(); tempStringTable.clear();
wayMapIds.clear();
pointMapIds.clear();
} }
int cid = registerId(wayMapIds, id);
tempNames.clear(); tempNames.clear();
decodeNames(rs.getString(5), tempNames); decodeNames(rs.getString(5), tempNames);
byte[] types = rs.getBytes(1); byte[] types = rs.getBytes(1);
@ -367,13 +382,13 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
byte[] pointCoordinates = rs.getBytes(4); byte[] pointCoordinates = rs.getBytes(4);
int typeInd = 0; int typeInd = 0;
RoutePointToWrite[] points = new RoutePointToWrite[pointCoordinates.length / 8]; RoutePointToWrite[] points = new RoutePointToWrite[pointCoordinates.length / 8];
TLongArrayList restrictions = highwayRestrictions.get(cid); TLongArrayList restrictions = highwayRestrictions.get(id);
if(restrictions != null){ if(restrictions != null){
Builder restriction = RestrictionData.newBuilder();
// TODO ids
for(int li = 0; li<restrictions.size(); li++){ for(int li = 0; li<restrictions.size(); li++){
restriction.setFrom((int) cid); Builder restriction = RestrictionData.newBuilder();
restriction.setTo((int) (restrictions.get(li) >> 3)); restriction.setFrom(cid);
int toId = registerId(wayMapIds, restrictions.get(li) >> 3);
restriction.setTo(toId);
restriction.setType((int) (restrictions.get(li) & 0x7)); restriction.setType((int) (restrictions.get(li) & 0x7));
dataBlock.addRestrictions(restriction.build()); dataBlock.addRestrictions(restriction.build());
} }
@ -382,7 +397,9 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
points[j] = new RoutePointToWrite(); points[j] = new RoutePointToWrite();
points[j].x = Algoritms.parseIntFromBytes(pointCoordinates, j * 8); points[j].x = Algoritms.parseIntFromBytes(pointCoordinates, j * 8);
points[j].y = Algoritms.parseIntFromBytes(pointCoordinates, j * 8 + 4); points[j].y = Algoritms.parseIntFromBytes(pointCoordinates, j * 8 + 4);
points[j].id = Algoritms.parseLongFromBytes(pointIds, j * 8); if(WRITE_POINT_ID) {
points[j].id = registerId(pointMapIds, Algoritms.parseLongFromBytes(pointIds, j * 8));
}
int type = 0; int type = 0;
do { do {
type = Algoritms.parseSmallIntFromBytes(pointTypes, typeInd); type = Algoritms.parseSmallIntFromBytes(pointTypes, typeInd);
@ -393,8 +410,8 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
} while (type != 0); } while (type != 0);
} }
RouteData routeData = writer.writeRouteData((int) cid, parentBounds.getMinX(), parentBounds.getMinY(), typeUse, points, RouteData routeData = writer.writeRouteData(cid, parentBounds.getMinX(), parentBounds.getMinY(), typeUse, points,
names, tempStringTable, dataBlock, true); names, tempStringTable, dataBlock, true, WRITE_POINT_ID);
if (routeData != null) { if (routeData != null) {
dataBlock.addDataObjects(routeData); dataBlock.addDataObjects(routeData);
} }
@ -404,6 +421,20 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
} }
} }
if (dataBlock != null) { if (dataBlock != null) {
IdTable.Builder idTable = IdTable.newBuilder();
long prev = 0;
for (int i = 0; i < wayMapIds.size(); i++) {
idTable.addRouteId(wayMapIds.getQuick(i) - prev);
prev = wayMapIds.getQuick(i);
}
if (WRITE_POINT_ID) {
prev = 0;
for (int i = 0; i < pointMapIds.size(); i++) {
idTable.addPointId(pointMapIds.getQuick(i) - prev);
prev = pointMapIds.getQuick(i);
}
}
dataBlock.setIdTable(idTable.build());
writer.writeRouteDataBlock(dataBlock, tempStringTable, ref); writer.writeRouteDataBlock(dataBlock, tempStringTable, ref);
} }
for (int i = 0; i < parent.getTotalElements(); i++) { for (int i = 0; i < parent.getTotalElements(); i++) {

View file

@ -459,13 +459,13 @@ message OsmAndPoiBoxDataAtom {
/** /**
* Id table 1-based. Map of sequential ids to real ids * Id table 1-based. Map of sequential ids to real ids
* [1,2,3....n] -> [a1, ... an] * [1,2,3....n] -> [a1, ... an]
* a1,.. an - sorted set of longs * a1,.. an - (ideally sorted) set of longs
*/ */
message IdTable { message IdTable {
// diff between 2 ids // diff between 2 ids
repeated uint64 routeId = 1; repeated sint64 routeId = 1;
// diff between 2 ids // diff between 2 ids
repeated uint64 pointId = 2; repeated sint64 pointId = 2;
} }
message RestrictionData { message RestrictionData {

View file

@ -4682,28 +4682,28 @@ class IdTable : public ::google::protobuf::Message {
// accessors ------------------------------------------------------- // accessors -------------------------------------------------------
// repeated uint64 routeId = 1; // repeated sint64 routeId = 1;
inline int routeid_size() const; inline int routeid_size() const;
inline void clear_routeid(); inline void clear_routeid();
static const int kRouteIdFieldNumber = 1; static const int kRouteIdFieldNumber = 1;
inline ::google::protobuf::uint64 routeid(int index) const; inline ::google::protobuf::int64 routeid(int index) const;
inline void set_routeid(int index, ::google::protobuf::uint64 value); inline void set_routeid(int index, ::google::protobuf::int64 value);
inline void add_routeid(::google::protobuf::uint64 value); inline void add_routeid(::google::protobuf::int64 value);
inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >&
routeid() const; routeid() const;
inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >*
mutable_routeid(); mutable_routeid();
// repeated uint64 pointId = 2; // repeated sint64 pointId = 2;
inline int pointid_size() const; inline int pointid_size() const;
inline void clear_pointid(); inline void clear_pointid();
static const int kPointIdFieldNumber = 2; static const int kPointIdFieldNumber = 2;
inline ::google::protobuf::uint64 pointid(int index) const; inline ::google::protobuf::int64 pointid(int index) const;
inline void set_pointid(int index, ::google::protobuf::uint64 value); inline void set_pointid(int index, ::google::protobuf::int64 value);
inline void add_pointid(::google::protobuf::uint64 value); inline void add_pointid(::google::protobuf::int64 value);
inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >&
pointid() const; pointid() const;
inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >*
mutable_pointid(); mutable_pointid();
// @@protoc_insertion_point(class_scope:IdTable) // @@protoc_insertion_point(class_scope:IdTable)
@ -4711,8 +4711,8 @@ class IdTable : public ::google::protobuf::Message {
::google::protobuf::UnknownFieldSet _unknown_fields_; ::google::protobuf::UnknownFieldSet _unknown_fields_;
mutable int _cached_size_; mutable int _cached_size_;
::google::protobuf::RepeatedField< ::google::protobuf::uint64 > routeid_; ::google::protobuf::RepeatedField< ::google::protobuf::int64 > routeid_;
::google::protobuf::RepeatedField< ::google::protobuf::uint64 > pointid_; ::google::protobuf::RepeatedField< ::google::protobuf::int64 > pointid_;
friend void protobuf_AddDesc_src_2fosmand_5fodb_2eproto(); friend void protobuf_AddDesc_src_2fosmand_5fodb_2eproto();
friend void protobuf_AssignDesc_src_2fosmand_5fodb_2eproto(); friend void protobuf_AssignDesc_src_2fosmand_5fodb_2eproto();
friend void protobuf_ShutdownFile_src_2fosmand_5fodb_2eproto(); friend void protobuf_ShutdownFile_src_2fosmand_5fodb_2eproto();
@ -5395,6 +5395,13 @@ class OsmAndRoutingIndex_RouteDataBlock : public ::google::protobuf::Message {
inline const ::IdTable& idtable() const; inline const ::IdTable& idtable() const;
inline ::IdTable* mutable_idtable(); inline ::IdTable* mutable_idtable();
// optional .StringTable stringTable = 8;
inline bool has_stringtable() const;
inline void clear_stringtable();
static const int kStringTableFieldNumber = 8;
inline const ::StringTable& stringtable() const;
inline ::StringTable* mutable_stringtable();
// repeated .RouteData dataObjects = 6; // repeated .RouteData dataObjects = 6;
inline int dataobjects_size() const; inline int dataobjects_size() const;
inline void clear_dataobjects(); inline void clear_dataobjects();
@ -5419,22 +5426,15 @@ class OsmAndRoutingIndex_RouteDataBlock : public ::google::protobuf::Message {
inline ::google::protobuf::RepeatedPtrField< ::RestrictionData >* inline ::google::protobuf::RepeatedPtrField< ::RestrictionData >*
mutable_restrictions(); mutable_restrictions();
// optional .StringTable stringTable = 8;
inline bool has_stringtable() const;
inline void clear_stringtable();
static const int kStringTableFieldNumber = 8;
inline const ::StringTable& stringtable() const;
inline ::StringTable* mutable_stringtable();
// @@protoc_insertion_point(class_scope:OsmAndRoutingIndex.RouteDataBlock) // @@protoc_insertion_point(class_scope:OsmAndRoutingIndex.RouteDataBlock)
private: private:
::google::protobuf::UnknownFieldSet _unknown_fields_; ::google::protobuf::UnknownFieldSet _unknown_fields_;
mutable int _cached_size_; mutable int _cached_size_;
::IdTable* idtable_; ::IdTable* idtable_;
::StringTable* stringtable_;
::google::protobuf::RepeatedPtrField< ::RouteData > dataobjects_; ::google::protobuf::RepeatedPtrField< ::RouteData > dataobjects_;
::google::protobuf::RepeatedPtrField< ::RestrictionData > restrictions_; ::google::protobuf::RepeatedPtrField< ::RestrictionData > restrictions_;
::StringTable* stringtable_;
friend void protobuf_AddDesc_src_2fosmand_5fodb_2eproto(); friend void protobuf_AddDesc_src_2fosmand_5fodb_2eproto();
friend void protobuf_AssignDesc_src_2fosmand_5fodb_2eproto(); friend void protobuf_AssignDesc_src_2fosmand_5fodb_2eproto();
friend void protobuf_ShutdownFile_src_2fosmand_5fodb_2eproto(); friend void protobuf_ShutdownFile_src_2fosmand_5fodb_2eproto();
@ -9794,52 +9794,52 @@ inline ::std::string* OsmAndPoiBoxDataAtom::mutable_note() {
// IdTable // IdTable
// repeated uint64 routeId = 1; // repeated sint64 routeId = 1;
inline int IdTable::routeid_size() const { inline int IdTable::routeid_size() const {
return routeid_.size(); return routeid_.size();
} }
inline void IdTable::clear_routeid() { inline void IdTable::clear_routeid() {
routeid_.Clear(); routeid_.Clear();
} }
inline ::google::protobuf::uint64 IdTable::routeid(int index) const { inline ::google::protobuf::int64 IdTable::routeid(int index) const {
return routeid_.Get(index); return routeid_.Get(index);
} }
inline void IdTable::set_routeid(int index, ::google::protobuf::uint64 value) { inline void IdTable::set_routeid(int index, ::google::protobuf::int64 value) {
routeid_.Set(index, value); routeid_.Set(index, value);
} }
inline void IdTable::add_routeid(::google::protobuf::uint64 value) { inline void IdTable::add_routeid(::google::protobuf::int64 value) {
routeid_.Add(value); routeid_.Add(value);
} }
inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >&
IdTable::routeid() const { IdTable::routeid() const {
return routeid_; return routeid_;
} }
inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >*
IdTable::mutable_routeid() { IdTable::mutable_routeid() {
return &routeid_; return &routeid_;
} }
// repeated uint64 pointId = 2; // repeated sint64 pointId = 2;
inline int IdTable::pointid_size() const { inline int IdTable::pointid_size() const {
return pointid_.size(); return pointid_.size();
} }
inline void IdTable::clear_pointid() { inline void IdTable::clear_pointid() {
pointid_.Clear(); pointid_.Clear();
} }
inline ::google::protobuf::uint64 IdTable::pointid(int index) const { inline ::google::protobuf::int64 IdTable::pointid(int index) const {
return pointid_.Get(index); return pointid_.Get(index);
} }
inline void IdTable::set_pointid(int index, ::google::protobuf::uint64 value) { inline void IdTable::set_pointid(int index, ::google::protobuf::int64 value) {
pointid_.Set(index, value); pointid_.Set(index, value);
} }
inline void IdTable::add_pointid(::google::protobuf::uint64 value) { inline void IdTable::add_pointid(::google::protobuf::int64 value) {
pointid_.Add(value); pointid_.Add(value);
} }
inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >& inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >&
IdTable::pointid() const { IdTable::pointid() const {
return pointid_; return pointid_;
} }
inline ::google::protobuf::RepeatedField< ::google::protobuf::uint64 >* inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >*
IdTable::mutable_pointid() { IdTable::mutable_pointid() {
return &pointid_; return &pointid_;
} }
@ -10379,6 +10379,23 @@ inline ::IdTable* OsmAndRoutingIndex_RouteDataBlock::mutable_idtable() {
return idtable_; return idtable_;
} }
// optional .StringTable stringTable = 8;
inline bool OsmAndRoutingIndex_RouteDataBlock::has_stringtable() const {
return _has_bit(1);
}
inline void OsmAndRoutingIndex_RouteDataBlock::clear_stringtable() {
if (stringtable_ != NULL) stringtable_->::StringTable::Clear();
_clear_bit(1);
}
inline const ::StringTable& OsmAndRoutingIndex_RouteDataBlock::stringtable() const {
return stringtable_ != NULL ? *stringtable_ : *default_instance_->stringtable_;
}
inline ::StringTable* OsmAndRoutingIndex_RouteDataBlock::mutable_stringtable() {
_set_bit(1);
if (stringtable_ == NULL) stringtable_ = new ::StringTable;
return stringtable_;
}
// repeated .RouteData dataObjects = 6; // repeated .RouteData dataObjects = 6;
inline int OsmAndRoutingIndex_RouteDataBlock::dataobjects_size() const { inline int OsmAndRoutingIndex_RouteDataBlock::dataobjects_size() const {
return dataobjects_.size(); return dataobjects_.size();
@ -10429,23 +10446,6 @@ OsmAndRoutingIndex_RouteDataBlock::mutable_restrictions() {
return &restrictions_; return &restrictions_;
} }
// optional .StringTable stringTable = 8;
inline bool OsmAndRoutingIndex_RouteDataBlock::has_stringtable() const {
return _has_bit(3);
}
inline void OsmAndRoutingIndex_RouteDataBlock::clear_stringtable() {
if (stringtable_ != NULL) stringtable_->::StringTable::Clear();
_clear_bit(3);
}
inline const ::StringTable& OsmAndRoutingIndex_RouteDataBlock::stringtable() const {
return stringtable_ != NULL ? *stringtable_ : *default_instance_->stringtable_;
}
inline ::StringTable* OsmAndRoutingIndex_RouteDataBlock::mutable_stringtable() {
_set_bit(3);
if (stringtable_ == NULL) stringtable_ = new ::StringTable;
return stringtable_;
}
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// OsmAndRoutingIndex // OsmAndRoutingIndex