First try route index
This commit is contained in:
parent
197279be11
commit
28f0423ff0
17 changed files with 6425 additions and 422 deletions
|
@ -1,16 +1,17 @@
|
|||
<!-- build JAR libraty -->
|
||||
<project name="DataExtractionOsm" default="build" basedir=".">
|
||||
<project name="DataExtractionOsm" default="all" basedir=".">
|
||||
<target name="build">
|
||||
<exec dir="." executable="/usr/bin/protoc">
|
||||
<exec dir="." executable="protoc">
|
||||
<arg value="src/osmand_odb.proto" />
|
||||
<arg value="--java_out=./src/" />
|
||||
</exec>
|
||||
</target>
|
||||
<target name="all" depends="build,cpp"/>
|
||||
|
||||
<target name="cpp">
|
||||
<exec dir="." executable="/usr/bin/protoc">
|
||||
<exec dir="." executable="protoc">
|
||||
<arg value="src/osmand_odb.proto" />
|
||||
<arg value="--cpp_out=../OsmAnd/jni/osmand/proto/" />
|
||||
<arg value="--cpp_out=../Osmand-kernel/osmand/src/proto" />
|
||||
</exec>
|
||||
</target>
|
||||
</project>
|
||||
|
|
|
@ -26,6 +26,7 @@ import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
|||
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
||||
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
||||
import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
|
||||
import net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.AmenityType;
|
||||
|
@ -48,7 +49,7 @@ public class BinaryInspector {
|
|||
// test cases show info
|
||||
|
||||
|
||||
// inspector(new String[]{"-vmap", /*"-bbox=-121.785,37.35,-121.744,37.33", */"/home/victor/projects/OsmAnd/data/osm-gen/Map.obf"});
|
||||
inspector(new String[]{/*"-vmap", "-bbox=-121.785,37.35,-121.744,37.33", */"/home/victor/projects/OsmAnd/data/osm-gen/Ru-spe.obf"});
|
||||
// test case extract parts
|
||||
// test case
|
||||
}
|
||||
|
@ -390,6 +391,8 @@ public class BinaryInspector {
|
|||
partname = "Map";
|
||||
} else if(p instanceof TransportIndex){
|
||||
partname = "Transport";
|
||||
} else if(p instanceof RouteRegion){
|
||||
partname = "Route";
|
||||
} else if(p instanceof PoiRegion){
|
||||
partname = "Poi";
|
||||
} else if(p instanceof AddressRegion){
|
||||
|
|
|
@ -29,6 +29,7 @@ import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
|||
import net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion;
|
||||
import net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock;
|
||||
import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
|
||||
import net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex;
|
||||
import net.osmand.binary.OsmandOdb.MapDataBlock;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapDataBox;
|
||||
|
@ -65,6 +66,7 @@ public class BinaryMapIndexReader {
|
|||
private List<PoiRegion> poiIndexes = new ArrayList<PoiRegion>();
|
||||
private List<AddressRegion> addressIndexes = new ArrayList<AddressRegion>();
|
||||
private List<TransportIndex> transportIndexes = new ArrayList<TransportIndex>();
|
||||
private List<RouteRegion> routingIndexes = new ArrayList<RouteRegion>();
|
||||
private List<BinaryIndexPart> indexes = new ArrayList<BinaryIndexPart>();
|
||||
|
||||
protected CodedInputStreamRAF codedIS;
|
||||
|
@ -72,6 +74,7 @@ public class BinaryMapIndexReader {
|
|||
private final BinaryMapTransportReaderAdapter transportAdapter;
|
||||
private final BinaryMapPoiReaderAdapter poiAdapter;
|
||||
private final BinaryMapAddressReaderAdapter addressAdapter;
|
||||
private BinaryMapRouteReaderAdapter routeAdapter;
|
||||
|
||||
private static String BASEMAP_NAME = "basemap";
|
||||
|
||||
|
@ -88,10 +91,12 @@ public class BinaryMapIndexReader {
|
|||
transportAdapter = new BinaryMapTransportReaderAdapter(this);
|
||||
addressAdapter = new BinaryMapAddressReaderAdapter(this);
|
||||
poiAdapter = new BinaryMapPoiReaderAdapter(this);
|
||||
routeAdapter = new BinaryMapRouteReaderAdapter(this);
|
||||
mapIndexes = new ArrayList<BinaryMapIndexReader.MapIndex>(referenceToSameFile.mapIndexes);
|
||||
poiIndexes = new ArrayList<PoiRegion>(referenceToSameFile.poiIndexes);
|
||||
addressIndexes = new ArrayList<AddressRegion>(referenceToSameFile.addressIndexes);
|
||||
transportIndexes = new ArrayList<TransportIndex>(referenceToSameFile.transportIndexes);
|
||||
routingIndexes = new ArrayList<RouteRegion>(referenceToSameFile.routingIndexes);
|
||||
indexes = new ArrayList<BinaryIndexPart>(referenceToSameFile.indexes);
|
||||
basemap = referenceToSameFile.basemap;
|
||||
}
|
||||
|
@ -104,6 +109,7 @@ public class BinaryMapIndexReader {
|
|||
transportAdapter = new BinaryMapTransportReaderAdapter(this);
|
||||
addressAdapter = new BinaryMapAddressReaderAdapter(this);
|
||||
poiAdapter = new BinaryMapPoiReaderAdapter(this);
|
||||
routeAdapter = new BinaryMapRouteReaderAdapter(this);
|
||||
} else {
|
||||
transportAdapter = null;
|
||||
addressAdapter = null;
|
||||
|
@ -175,6 +181,19 @@ public class BinaryMapIndexReader {
|
|||
}
|
||||
codedIS.seek(ind.filePointer + ind.length);
|
||||
break;
|
||||
case OsmandOdb.OsmAndStructure.ROUTINGINDEX_FIELD_NUMBER:
|
||||
RouteRegion routeReg = new RouteRegion();
|
||||
routeReg.length = readInt();
|
||||
routeReg.filePointer = codedIS.getTotalBytesRead();
|
||||
if (routeAdapter != null) {
|
||||
oldLimit = codedIS.pushLimit(routeReg.length);
|
||||
routeAdapter.readRouteIndex(routeReg);
|
||||
codedIS.popLimit(oldLimit);
|
||||
routingIndexes.add(routeReg);
|
||||
indexes.add(routeReg);
|
||||
}
|
||||
codedIS.seek(routeReg.filePointer + routeReg.length);
|
||||
break;
|
||||
case OsmandOdb.OsmAndStructure.POIINDEX_FIELD_NUMBER:
|
||||
PoiRegion poiInd = new PoiRegion();
|
||||
poiInd.length = readInt();
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
package net.osmand.binary;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import com.google.protobuf.CodedInputStreamRAF;
|
||||
import com.google.protobuf.WireFormat;
|
||||
|
||||
public class BinaryMapRouteReaderAdapter {
|
||||
private static final Log LOG = LogUtil.getLog(BinaryMapRouteReaderAdapter.class);
|
||||
|
||||
|
||||
public static class RouteRegion extends BinaryIndexPart {
|
||||
|
||||
double leftLongitude;
|
||||
double rightLongitude;
|
||||
double topLatitude;
|
||||
double bottomLatitude;
|
||||
|
||||
public double getLeftLongitude() {
|
||||
return leftLongitude;
|
||||
}
|
||||
|
||||
public double getRightLongitude() {
|
||||
return rightLongitude;
|
||||
}
|
||||
|
||||
public double getTopLatitude() {
|
||||
return topLatitude;
|
||||
}
|
||||
|
||||
public double getBottomLatitude() {
|
||||
return bottomLatitude;
|
||||
}
|
||||
}
|
||||
|
||||
private CodedInputStreamRAF codedIS;
|
||||
private final BinaryMapIndexReader map;
|
||||
|
||||
protected BinaryMapRouteReaderAdapter(BinaryMapIndexReader map){
|
||||
this.codedIS = map.codedIS;
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
private void skipUnknownField(int t) throws IOException {
|
||||
map.skipUnknownField(t);
|
||||
}
|
||||
|
||||
private int readInt() throws IOException {
|
||||
return map.readInt();
|
||||
}
|
||||
|
||||
|
||||
protected void readRouteIndex(RouteRegion region) throws IOException {
|
||||
while(true){
|
||||
int t = codedIS.readTag();
|
||||
int tag = WireFormat.getTagFieldNumber(t);
|
||||
switch (tag) {
|
||||
case 0:
|
||||
return;
|
||||
case OsmandOdb.OsmAndRoutingIndex.NAME_FIELD_NUMBER :
|
||||
region.name = codedIS.readString();
|
||||
break;
|
||||
default:
|
||||
skipUnknownField(t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -31,6 +31,7 @@ import net.osmand.binary.OsmandOdb.CityIndex;
|
|||
import net.osmand.binary.OsmandOdb.MapData;
|
||||
import net.osmand.binary.OsmandOdb.MapDataBlock;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndAddressIndex;
|
||||
import net.osmand.binary.OsmandOdb.RouteData;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndAddressIndex.CitiesIndex;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndAddressNameIndexData.AddressNameIndexData;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndAddressNameIndexData;
|
||||
|
@ -41,7 +42,12 @@ import net.osmand.binary.OsmandOdb.OsmAndMapIndex;
|
|||
import net.osmand.binary.OsmandOdb.OsmAndPoiBoxDataAtom;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndPoiNameIndex;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndPoiNameIndexDataAtom;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBox;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteEncodingRule;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndTransportIndex;
|
||||
import net.osmand.binary.OsmandOdb.RoutePoint;
|
||||
import net.osmand.binary.OsmandOdb.StreetIndex;
|
||||
import net.osmand.binary.OsmandOdb.StreetIntersection;
|
||||
import net.osmand.binary.OsmandOdb.StringTable;
|
||||
|
@ -60,6 +66,7 @@ import net.osmand.osm.LatLon;
|
|||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.osm.Node;
|
||||
import net.osmand.osm.MapRenderingTypes.MapRulType;
|
||||
import net.osmand.osm.MapRoutingTypes.MapRouteType;
|
||||
import net.sf.junidecode.Junidecode;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
@ -113,6 +120,9 @@ public class BinaryMapIndexWriter {
|
|||
private final static int POI_BOX = 13;
|
||||
private final static int POI_DATA = 14;
|
||||
|
||||
private final static int ROUTE_INDEX_INIT = 15;
|
||||
private final static int ROUTE_TREE = 16;
|
||||
|
||||
public BinaryMapIndexWriter(final RandomAccessFile raf) throws IOException {
|
||||
this.raf = raf;
|
||||
codedOutStream = CodedOutputStream.newInstance(new OutputStream() {
|
||||
|
@ -184,6 +194,27 @@ public class BinaryMapIndexWriter {
|
|||
log.info("MAP INDEX SIZE : " + len);
|
||||
}
|
||||
|
||||
public void startWriteRouteIndex(String name) throws IOException {
|
||||
pushState(ROUTE_INDEX_INIT, OSMAND_STRUCTURE_INIT);
|
||||
codedOutStream.writeTag(OsmandOdb.OsmAndStructure.ROUTINGINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||
preserveInt32Size();
|
||||
if (name != null) {
|
||||
codedOutStream.writeString(OsmandOdb.OsmAndMapIndex.NAME_FIELD_NUMBER, name);
|
||||
}
|
||||
}
|
||||
|
||||
public void endWriteRouteIndex() throws IOException {
|
||||
popState(ROUTE_INDEX_INIT);
|
||||
int len = writeInt32Size();
|
||||
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 ID SIZE " + BinaryMapIndexWriter.ROUTE_ID_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;
|
||||
log.info("ROUTE INDEX SIZE : " + len);
|
||||
}
|
||||
|
||||
|
||||
public void startWriteMapLevelIndex(int minZoom, int maxZoom, int leftX, int rightX, int topY, int bottomY) throws IOException {
|
||||
pushState(MAP_ROOT_LEVEL_INIT, MAP_INDEX_INIT);
|
||||
|
||||
|
@ -208,7 +239,6 @@ public class BinaryMapIndexWriter {
|
|||
|
||||
public void writeMapEncodingRules(Map<String, MapRulType> types) throws IOException {
|
||||
checkPeekState(MAP_INDEX_INIT);
|
||||
long fp = getFilePointer();
|
||||
|
||||
ArrayList<MapRulType> out = new ArrayList<MapRulType>();
|
||||
int highestTargetId = types.size();
|
||||
|
@ -247,10 +277,73 @@ public class BinaryMapIndexWriter {
|
|||
MapEncodingRule rulet = builder.build();
|
||||
codedOutStream.writeMessage(OsmandOdb.OsmAndMapIndex.RULES_FIELD_NUMBER, rulet);
|
||||
}
|
||||
long newfp = getFilePointer();
|
||||
System.out.println("RENDERING SCHEMA takes " + (newfp - fp));
|
||||
}
|
||||
|
||||
public void writeRouteEncodingRules(List<MapRouteType> types) throws IOException {
|
||||
checkPeekState(ROUTE_INDEX_INIT);
|
||||
|
||||
ArrayList<MapRouteType> out = new ArrayList<MapRouteType>(types);
|
||||
// 2. sort by frequency and assign ids
|
||||
Collections.sort(out, new Comparator<MapRouteType>() {
|
||||
@Override
|
||||
public int compare(MapRouteType o1, MapRouteType o2) {
|
||||
return o2.getFreq() - o1.getFreq();
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < out.size(); i++) {
|
||||
RouteEncodingRule.Builder builder = OsmandOdb.OsmAndRoutingIndex.RouteEncodingRule.newBuilder();
|
||||
MapRouteType rule = out.get(i);
|
||||
rule.setTargetId(i + 1);
|
||||
|
||||
builder.setTag(rule.getTag());
|
||||
if (rule.getValue() != null) {
|
||||
builder.setValue(rule.getValue());
|
||||
}
|
||||
RouteEncodingRule rulet = builder.build();
|
||||
codedOutStream.writeMessage(OsmandOdb.OsmAndRoutingIndex.RULES_FIELD_NUMBER, rulet);
|
||||
}
|
||||
}
|
||||
|
||||
public BinaryFileReference startRouteTreeElement(int leftX, int rightX, int topY, int bottomY, boolean containsObjects) throws IOException {
|
||||
checkPeekState(ROUTE_TREE, ROUTE_INDEX_INIT);
|
||||
if (state.peek() == ROUTE_INDEX_INIT) {
|
||||
codedOutStream.writeTag(OsmAndRoutingIndex.ROOTBOXES_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||
} else {
|
||||
codedOutStream.writeTag(RouteDataBox.BOXES_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||
}
|
||||
state.push(ROUTE_TREE);
|
||||
preserveInt32Size();
|
||||
long fp = getFilePointer();
|
||||
|
||||
|
||||
Bounds bounds;
|
||||
if(stackBounds.isEmpty()) {
|
||||
bounds = new Bounds(0, 0, 0, 0);
|
||||
} else {
|
||||
bounds = stackBounds.peek();
|
||||
}
|
||||
codedOutStream.writeSInt32(RouteDataBox.LEFT_FIELD_NUMBER, leftX - bounds.leftX);
|
||||
codedOutStream.writeSInt32(RouteDataBox.RIGHT_FIELD_NUMBER, rightX - bounds.rightX);
|
||||
codedOutStream.writeSInt32(RouteDataBox.TOP_FIELD_NUMBER, topY - bounds.topY);
|
||||
codedOutStream.writeSInt32(RouteDataBox.BOTTOM_FIELD_NUMBER, bottomY - bounds.bottomY);
|
||||
stackBounds.push(new Bounds(leftX, rightX, topY, bottomY));
|
||||
BinaryFileReference ref = null;
|
||||
if (containsObjects) {
|
||||
codedOutStream.writeTag(RouteDataBox.SHIFTTODATA_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
|
||||
ref = BinaryFileReference.createShiftReference(getFilePointer(), fp);
|
||||
codedOutStream.writeFixed32NoTag(0);
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
|
||||
public void endRouteTreeElement() throws IOException {
|
||||
popState(ROUTE_TREE);
|
||||
stackBounds.pop();
|
||||
writeInt32Size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public BinaryFileReference startMapTreeElement(int leftX, int rightX, int topY, int bottomY, boolean containsLeaf) throws IOException {
|
||||
return startMapTreeElement(leftX, rightX, topY, bottomY, containsLeaf, false, false);
|
||||
|
@ -299,12 +392,121 @@ public class BinaryMapIndexWriter {
|
|||
public static int MAP_DATA_SIZE = 0;
|
||||
public static int STRING_TABLE_SIZE = 0;
|
||||
|
||||
public static int ROUTE_ID_SIZE = 0;
|
||||
public static int ROUTE_TYPES_SIZE = 0;
|
||||
public static int ROUTE_COORDINATES_SIZE = 0;
|
||||
public static int ROUTE_COORDINATES_COUNT = 0;
|
||||
public static int ROUTE_DATA_SIZE = 0;
|
||||
|
||||
public MapDataBlock.Builder createWriteMapDataBlock(long baseid) throws IOException {
|
||||
MapDataBlock.Builder builder = MapDataBlock.newBuilder();
|
||||
builder.setBaseId(baseid);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public void writeRouteDataBlock(RouteDataBlock.Builder builder, Map<String, Integer> stringTable, BinaryFileReference ref)
|
||||
throws IOException {
|
||||
|
||||
checkPeekState(ROUTE_INDEX_INIT);
|
||||
StringTable.Builder bs = OsmandOdb.StringTable.newBuilder();
|
||||
if (stringTable != null) {
|
||||
for (String s : stringTable.keySet()) {
|
||||
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;
|
||||
|
||||
codedOutStream.writeTag(OsmAndMapIndex.MapRootLevel.BLOCKS_FIELD_NUMBER, FieldType.MESSAGE.getWireType());
|
||||
|
||||
codedOutStream.flush();
|
||||
ref.writeReference(raf, getFilePointer());
|
||||
RouteDataBlock block = builder.build();
|
||||
ROUTE_DATA_SIZE += block.getSerializedSize();
|
||||
codedOutStream.writeMessageNoTag(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode and write a varint. {@code value} is treated as unsigned, so it won't be sign-extended if negative.
|
||||
*/
|
||||
public void writeRawVarint32(TByteArrayList bf, int value) throws IOException {
|
||||
while (true) {
|
||||
if ((value & ~0x7F) == 0) {
|
||||
writeRawByte(bf, value);
|
||||
return;
|
||||
} else {
|
||||
writeRawByte(bf, (value & 0x7F) | 0x80);
|
||||
value >>>= 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Write a single byte. */
|
||||
public void writeRawByte(TByteArrayList bf, final int value) throws IOException {
|
||||
bf.add((byte) value);
|
||||
}
|
||||
|
||||
public RouteData writeRouteData(int diffId, int pleft, int ptop, int[] types, RoutePointToWrite[] points,
|
||||
Map<MapRouteType, String> names, Map<String, Integer> stringTable, RouteDataBlock.Builder dataBlock,
|
||||
boolean allowCoordinateSimplification)
|
||||
throws IOException {
|
||||
RouteData.Builder builder = RouteData.newBuilder();
|
||||
builder.setRouteId(diffId);
|
||||
ROUTE_ID_SIZE += CodedOutputStream.computeInt64Size(RouteData.ROUTEID_FIELD_NUMBER, diffId);
|
||||
mapDataBuf.clear();
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
writeRawVarint32(mapDataBuf, types[i]);
|
||||
}
|
||||
builder.setTypes(ByteString.copyFrom(mapDataBuf.toArray()));
|
||||
ROUTE_TYPES_SIZE += CodedOutputStream.computeTagSize(RouteData.TYPES_FIELD_NUMBER)
|
||||
+ CodedOutputStream.computeRawVarint32Size(mapDataBuf.size()) + mapDataBuf.size();
|
||||
int pcalcx = pleft >> SHIFT_COORDINATES;
|
||||
int pcalcy = ptop >> SHIFT_COORDINATES;
|
||||
for(int k=0; k<points.length; k++) {
|
||||
ROUTE_COORDINATES_COUNT++;
|
||||
RoutePoint.Builder point = RoutePoint.newBuilder();
|
||||
// not implemented correctly
|
||||
// point.setPointId(points[j].id);
|
||||
mapDataBuf.clear();
|
||||
int tx = (points[k].x >> SHIFT_COORDINATES) - pcalcx;
|
||||
int ty = (points[k].y >> SHIFT_COORDINATES) - pcalcy;
|
||||
writeRawVarint32(mapDataBuf, CodedOutputStream.encodeZigZag32(tx));
|
||||
writeRawVarint32(mapDataBuf, CodedOutputStream.encodeZigZag32(ty));
|
||||
pcalcx = pcalcx + tx ;
|
||||
pcalcy = pcalcy + ty ;
|
||||
point.setPoint(ByteString.copyFrom(mapDataBuf.toArray()));
|
||||
ROUTE_COORDINATES_SIZE += CodedOutputStream.computeTagSize(RoutePoint.POINT_FIELD_NUMBER)
|
||||
+ CodedOutputStream.computeRawVarint32Size(mapDataBuf.size()) + mapDataBuf.size();
|
||||
mapDataBuf.clear();
|
||||
for(int ij =0; ij < points[k].types.size(); ij++){
|
||||
writeRawVarint32(mapDataBuf, points[k].types.get(ij));
|
||||
}
|
||||
point.setTypes(ByteString.copyFrom(mapDataBuf.toArray()));
|
||||
ROUTE_TYPES_SIZE += CodedOutputStream.computeTagSize(RoutePoint.TYPES_FIELD_NUMBER)
|
||||
+ CodedOutputStream.computeRawVarint32Size(mapDataBuf.size()) + mapDataBuf.size();
|
||||
builder.addPoints(point.build());
|
||||
}
|
||||
mapDataBuf.clear();
|
||||
if (names != null) {
|
||||
for (Entry<MapRouteType, String> s : names.entrySet()) {
|
||||
writeRawVarint32(mapDataBuf, s.getKey().getTargetId());
|
||||
Integer ls = stringTable.get(s.getValue());
|
||||
if (ls == null) {
|
||||
ls = stringTable.size();
|
||||
stringTable.put(s.getValue(), ls);
|
||||
}
|
||||
writeRawVarint32(mapDataBuf, ls);
|
||||
}
|
||||
}
|
||||
STRING_TABLE_SIZE += mapDataBuf.size();
|
||||
builder.setStringNames(ByteString.copyFrom(mapDataBuf.toArray()));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void writeMapDataBlock(MapDataBlock.Builder builder, Map<String, Integer> stringTable, BinaryFileReference ref)
|
||||
throws IOException {
|
||||
|
||||
|
@ -330,26 +532,6 @@ public class BinaryMapIndexWriter {
|
|||
codedOutStream.writeMessageNoTag(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode and write a varint. {@code value} is treated as unsigned, so it won't be sign-extended if negative.
|
||||
*/
|
||||
public void writeRawVarint32(TByteArrayList bf, int value) throws IOException {
|
||||
while (true) {
|
||||
if ((value & ~0x7F) == 0) {
|
||||
writeRawByte(bf, value);
|
||||
return;
|
||||
} else {
|
||||
writeRawByte(bf, (value & 0x7F) | 0x80);
|
||||
value >>>= 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Write a single byte. */
|
||||
public void writeRawByte(TByteArrayList bf, final int value) throws IOException {
|
||||
bf.add((byte) value);
|
||||
}
|
||||
|
||||
private TByteArrayList mapDataBuf = new TByteArrayList();
|
||||
|
||||
public MapData writeMapData(long diffId, int pleft, int ptop, boolean area, byte[] coordinates, byte[] innerPolygonTypes, int[] typeUse,
|
||||
|
@ -454,6 +636,13 @@ public class BinaryMapIndexWriter {
|
|||
return data.build();
|
||||
}
|
||||
|
||||
public static class RoutePointToWrite {
|
||||
public TIntArrayList types = new TIntArrayList();
|
||||
public long id;
|
||||
public int x;
|
||||
public int y;
|
||||
}
|
||||
|
||||
private static double orthogonalDistance(int x, int y, int x1, int y1, int x2, int y2) {
|
||||
long A = (x - x1);
|
||||
long B = (y - y1);
|
||||
|
|
|
@ -492,8 +492,7 @@ public class IndexCreator {
|
|||
indexMapCreator.createRTreeFiles(getRTreeMapIndexPackFileName());
|
||||
}
|
||||
if (indexRouting) {
|
||||
// FIXME
|
||||
// indexRouteCreator.createRTreeFiles(getRTreeRouteIndexPackFileName());
|
||||
indexRouteCreator.createRTreeFiles(getRTreeRouteIndexPackFileName());
|
||||
}
|
||||
if (indexTransport) {
|
||||
indexTransportCreator.createRTreeFile(getRTreeTransportStopsPackFileName());
|
||||
|
@ -621,8 +620,7 @@ public class IndexCreator {
|
|||
indexMapCreator.packRtreeFiles(getRTreeMapIndexNonPackFileName(), getRTreeMapIndexPackFileName());
|
||||
}
|
||||
if(indexRouting) {
|
||||
// FIXME
|
||||
// indexRouteCreator.packRtreeFiles(getRTreeRouteIndexNonPackFileName(), getRTreeRouteIndexPackFileName());
|
||||
indexRouteCreator.packRtreeFiles(getRTreeRouteIndexNonPackFileName(), getRTreeRouteIndexPackFileName());
|
||||
}
|
||||
|
||||
if (indexTransport) {
|
||||
|
@ -647,8 +645,7 @@ public class IndexCreator {
|
|||
if (indexRouting) {
|
||||
progress.setGeneralProgress("[95 of 100]");
|
||||
progress.startTask("Writing route index to binary file...", -1);
|
||||
// FIXME
|
||||
// indexRouteCreator.writeBinaryMapIndex(writer, regionName);
|
||||
indexRouteCreator.writeBinaryRouteIndex(writer, regionName);
|
||||
}
|
||||
|
||||
if (indexAddress) {
|
||||
|
@ -744,17 +741,18 @@ public class IndexCreator {
|
|||
creator.setIndexAddress(true);
|
||||
creator.setIndexPOI(true);
|
||||
creator.setIndexTransport(false);
|
||||
creator.setIndexRouting(true);
|
||||
|
||||
// creator.deleteDatabaseIndexes = false;
|
||||
// creator.recreateOnlyBinaryFile = true;
|
||||
creator.deleteOsmDB = false;
|
||||
|
||||
// creator.deleteOsmDB = false;
|
||||
|
||||
creator.setZoomWaySmothness(2);
|
||||
MapRenderingTypes rt = MapRenderingTypes.getDefault();// new MapRenderingTypes("/home/victor/projects/OsmAnd/data/testdata/roads_rendering_types.xml");
|
||||
MapRenderingTypes rt = MapRenderingTypes.getDefault();
|
||||
MapZooms zooms = MapZooms.getDefault(); // MapZooms.parseZooms("15-");
|
||||
// creator.setNodesDBFile(new File("/home/victor/projects/OsmAnd/data/osm-gen/nodes.tmp.odb"));
|
||||
// creator.setMapFileName("Luxembourg_poi.obf");
|
||||
creator.generateIndexes(new File("/home/victor/projects/OsmAnd/temp/map.osm"),
|
||||
creator.setNodesDBFile(new File("/home/victor/projects/OsmAnd/data/osm-gen/nodes.tmp.odb"));
|
||||
creator.generateIndexes(new File("/home/victor/projects/OsmAnd/data/osm-maps/RU-SPE.osm.pbf"),
|
||||
new ConsoleProgressImplementation(1), null, zooms, rt, log);
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package net.osmand.data.preparation;
|
|||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
import gnu.trove.map.hash.TLongObjectHashMap;
|
||||
import gnu.trove.set.hash.TLongHashSet;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -15,7 +14,7 @@ import java.sql.SQLException;
|
|||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -24,8 +23,11 @@ import net.osmand.Algoritms;
|
|||
import net.osmand.IProgress;
|
||||
import net.osmand.binary.OsmandOdb.MapData;
|
||||
import net.osmand.binary.OsmandOdb.MapDataBlock;
|
||||
import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock;
|
||||
import net.osmand.binary.OsmandOdb.RouteData;
|
||||
import net.osmand.data.Boundary;
|
||||
import net.osmand.data.MapAlgorithms;
|
||||
import net.osmand.data.preparation.BinaryMapIndexWriter.RoutePointToWrite;
|
||||
import net.osmand.osm.Entity;
|
||||
import net.osmand.osm.Entity.EntityId;
|
||||
import net.osmand.osm.Entity.EntityType;
|
||||
|
@ -55,15 +57,16 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
|
|||
private Connection mapConnection;
|
||||
private final Log logMapDataWarn;
|
||||
|
||||
private RTree mapTree = null;
|
||||
private RTree routeTree = null;
|
||||
private MapRoutingTypes routeTypes;
|
||||
private Map<Long, List<Long>> highwayRestrictions = new LinkedHashMap<Long, List<Long>>();
|
||||
|
||||
// local purpose to speed up processing cache allocation
|
||||
TIntArrayList outTypes = new TIntArrayList();
|
||||
TLongObjectHashMap<TIntArrayList> pointTypes = new TLongObjectHashMap<TIntArrayList>();
|
||||
Map<MapRoutingTypes.MapRouteType, String> names = new HashMap<MapRoutingTypes.MapRouteType, String>();
|
||||
|
||||
private PreparedStatement mapRouteStat;
|
||||
private PreparedStatement mapRouteInsertStat;
|
||||
|
||||
|
||||
public IndexRouteCreator(Log logMapDataWarn) {
|
||||
|
@ -76,43 +79,80 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
|
|||
}
|
||||
|
||||
|
||||
private void loadNodes(byte[] nodes, List<Float> toPut) {
|
||||
toPut.clear();
|
||||
for (int i = 0; i < nodes.length;) {
|
||||
int lat = Algoritms.parseIntFromBytes(nodes, i);
|
||||
i += 4;
|
||||
int lon = Algoritms.parseIntFromBytes(nodes, i);
|
||||
i += 4;
|
||||
toPut.add(Float.intBitsToFloat(lat));
|
||||
toPut.add(Float.intBitsToFloat(lon));
|
||||
}
|
||||
}
|
||||
|
||||
private void parseAndSort(TIntArrayList ts, byte[] bs) {
|
||||
ts.clear();
|
||||
if (bs != null && bs.length > 0) {
|
||||
for (int j = 0; j < bs.length; j += 2) {
|
||||
ts.add(Algoritms.parseSmallIntFromBytes(bs, j));
|
||||
}
|
||||
}
|
||||
ts.sort();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void iterateMainEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
|
||||
if (e instanceof Way) {
|
||||
// manipulate what kind of way to load
|
||||
public void iterateMainEntity(Entity es, OsmDbAccessorContext ctx) throws SQLException {
|
||||
if (es instanceof Way) {
|
||||
Way e = (Way) es;
|
||||
ctx.loadEntityData(e);
|
||||
boolean encoded = routeTypes.encodeEntity((Way) e, outTypes, pointTypes);
|
||||
boolean encoded = routeTypes.encodeEntity(e, outTypes, pointTypes, names);
|
||||
if (encoded) {
|
||||
boolean init = false;
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int maxX = 0;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int maxY = 0;
|
||||
|
||||
ByteArrayOutputStream bcoordinates = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream bpointIds = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream bpointTypes = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream btypes = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
for (int j = 0; j < outTypes.size(); j++) {
|
||||
Algoritms.writeSmallInt(btypes, outTypes.get(j));
|
||||
}
|
||||
|
||||
for (Node n : e.getNodes()) {
|
||||
if (n != null) {
|
||||
// write id
|
||||
Algoritms.writeLongInt(bpointIds, n.getId());
|
||||
// write point type
|
||||
TIntArrayList types = pointTypes.get(n.getId());
|
||||
if (types != null) {
|
||||
for (int j = 0; j < types.size(); j++) {
|
||||
Algoritms.writeSmallInt(bpointTypes, types.get(j));
|
||||
}
|
||||
}
|
||||
Algoritms.writeSmallInt(bpointTypes, 0);
|
||||
// write coordinates
|
||||
int y = MapUtils.get31TileNumberY(n.getLatitude());
|
||||
int x = MapUtils.get31TileNumberX(n.getLongitude());
|
||||
minX = Math.min(minX, x);
|
||||
maxX = Math.max(maxX, x);
|
||||
minY = Math.min(minY, y);
|
||||
maxY = Math.max(maxY, y);
|
||||
init = true;
|
||||
Algoritms.writeInt(bcoordinates, x);
|
||||
Algoritms.writeInt(bcoordinates, y);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException est) {
|
||||
throw new IllegalStateException(est);
|
||||
}
|
||||
if (init) {
|
||||
// conn.prepareStatement("insert into route_objects(id, types, pointTypes, pointIds, pointCoordinates, name) values(?, ?, ?, ?, ?, ?, ?)");
|
||||
mapRouteInsertStat.setLong(1, e.getId());
|
||||
mapRouteInsertStat.setBytes(2, btypes.toByteArray());
|
||||
mapRouteInsertStat.setBytes(3, bpointTypes.toByteArray());
|
||||
mapRouteInsertStat.setBytes(4, bpointIds.toByteArray());
|
||||
mapRouteInsertStat.setBytes(5, bcoordinates.toByteArray());
|
||||
mapRouteInsertStat.setString(6, encodeNames(names));
|
||||
|
||||
addBatch(mapRouteInsertStat, false);
|
||||
try {
|
||||
routeTree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), e.getId()));
|
||||
} catch (RTreeInsertException e1) {
|
||||
throw new IllegalArgumentException(e1);
|
||||
} catch (IllegalValueException e1) {
|
||||
throw new IllegalArgumentException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final char SPECIAL_CHAR = ((char) 0x60000);
|
||||
|
||||
protected String encodeNames(Map<MapRouteType, String> tempNames) {
|
||||
|
@ -161,117 +201,37 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
|
|||
|
||||
public void createDatabaseStructure(Connection mapConnection, DBDialect dialect, String rtreeMapIndexNonPackFileName)
|
||||
throws SQLException, IOException {
|
||||
createRouteIndexStructure(mapConnection);
|
||||
this.mapConnection = mapConnection;
|
||||
mapRouteStat = createStatementRouteObjInsert(mapConnection);
|
||||
Statement stat = mapConnection.createStatement();
|
||||
stat.executeUpdate(CREATETABLE);
|
||||
stat.executeUpdate(CREATE_IND);
|
||||
stat.close();
|
||||
mapRouteInsertStat = createStatementRouteObjInsert(mapConnection);
|
||||
try {
|
||||
mapTree = new RTree(rtreeMapIndexNonPackFileName);
|
||||
routeTree = new RTree(rtreeMapIndexNonPackFileName);
|
||||
} catch (RTreeException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
pStatements.put(mapRouteStat, 0);
|
||||
pStatements.put(mapRouteInsertStat, 0);
|
||||
}
|
||||
|
||||
private void createRouteIndexStructure(Connection conn) throws SQLException {
|
||||
Statement stat = conn.createStatement();
|
||||
stat.executeUpdate("create table route_objects (id bigint primary key, "
|
||||
+ "types binary, pointTypes binary, pointIds binary, pointCoordinates binary)");
|
||||
stat.executeUpdate("create index route_objects_ind on binary_map_objects (id)");
|
||||
stat.close();
|
||||
}
|
||||
private static final String CREATETABLE = "create table route_objects (id bigint primary key, "
|
||||
+ "types binary, pointTypes binary, pointIds binary, pointCoordinates binary, name varchar(4096))";
|
||||
private static final String CREATE_IND = "create index route_objects_ind on route_objects (id)";
|
||||
private static final String SELECT_STAT = "SELECT types, pointTypes, pointIds, pointCoordinates, name FROM route_objects WHERE id = ?";
|
||||
private static final String INSERT_STAT = "insert into route_objects(id, types, pointTypes, pointIds, pointCoordinates, name) values(?, ?, ?, ?, ?, ?)";
|
||||
|
||||
|
||||
private PreparedStatement createStatementRouteObjInsert(Connection conn) throws SQLException {
|
||||
return conn
|
||||
.prepareStatement("insert into route_objects(id, area, coordinates, innerPolygons, types, additionalTypes, name) values(?, ?, ?, ?, ?, ?, ?)");
|
||||
return conn.prepareStatement(INSERT_STAT);
|
||||
}
|
||||
|
||||
private void insertBinaryMapRenderObjectIndex(RTree mapTree, Collection<Node> nodes, List<List<Node>> innerWays,
|
||||
Map<MapRouteType, String> names, long id, boolean area, TIntArrayList types, TIntArrayList addTypes, boolean commit)
|
||||
throws SQLException {
|
||||
boolean init = false;
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int maxX = 0;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int maxY = 0;
|
||||
|
||||
ByteArrayOutputStream bcoordinates = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream binnercoord = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream btypes = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream badditionalTypes = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
for (int j = 0; j < types.size(); j++) {
|
||||
Algoritms.writeSmallInt(btypes, types.get(j));
|
||||
}
|
||||
for (int j = 0; j < addTypes.size(); j++) {
|
||||
Algoritms.writeSmallInt(badditionalTypes, addTypes.get(j));
|
||||
}
|
||||
|
||||
for (Node n : nodes) {
|
||||
if (n != null) {
|
||||
int y = MapUtils.get31TileNumberY(n.getLatitude());
|
||||
int x = MapUtils.get31TileNumberX(n.getLongitude());
|
||||
minX = Math.min(minX, x);
|
||||
maxX = Math.max(maxX, x);
|
||||
minY = Math.min(minY, y);
|
||||
maxY = Math.max(maxY, y);
|
||||
init = true;
|
||||
Algoritms.writeInt(bcoordinates, x);
|
||||
Algoritms.writeInt(bcoordinates, y);
|
||||
}
|
||||
}
|
||||
|
||||
if (innerWays != null) {
|
||||
for (List<Node> ws : innerWays) {
|
||||
boolean exist = false;
|
||||
if (ws != null) {
|
||||
for (Node n : ws) {
|
||||
if (n != null) {
|
||||
exist = true;
|
||||
int y = MapUtils.get31TileNumberY(n.getLatitude());
|
||||
int x = MapUtils.get31TileNumberX(n.getLongitude());
|
||||
Algoritms.writeInt(binnercoord, x);
|
||||
Algoritms.writeInt(binnercoord, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exist) {
|
||||
Algoritms.writeInt(binnercoord, 0);
|
||||
Algoritms.writeInt(binnercoord, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException es) {
|
||||
throw new IllegalStateException(es);
|
||||
}
|
||||
if (init) {
|
||||
// conn.prepareStatement("insert into binary_map_objects(id, area, coordinates, innerPolygons, types, additionalTypes, name) values(?, ?, ?, ?, ?, ?, ?)");
|
||||
mapRouteStat.setLong(1, id);
|
||||
mapRouteStat.setBoolean(2, area);
|
||||
mapRouteStat.setBytes(3, bcoordinates.toByteArray());
|
||||
mapRouteStat.setBytes(4, binnercoord.toByteArray());
|
||||
mapRouteStat.setBytes(5, btypes.toByteArray());
|
||||
mapRouteStat.setBytes(6, badditionalTypes.toByteArray());
|
||||
mapRouteStat.setString(7, encodeNames(names));
|
||||
|
||||
addBatch(mapRouteStat, commit);
|
||||
try {
|
||||
mapTree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), id));
|
||||
} catch (RTreeInsertException e1) {
|
||||
throw new IllegalArgumentException(e1);
|
||||
} catch (IllegalValueException e1) {
|
||||
throw new IllegalArgumentException(e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void commitAndCloseFiles(String rTreeMapIndexNonPackFileName, String rTreeMapIndexPackFileName, boolean deleteDatabaseIndexes)
|
||||
throws IOException, SQLException {
|
||||
|
||||
// delete map rtree files
|
||||
if (mapTree != null) {
|
||||
RandomAccessFile file = mapTree.getFileHdr().getFile();
|
||||
if (routeTree != null) {
|
||||
RandomAccessFile file = routeTree.getFileHdr().getFile();
|
||||
file.close();
|
||||
if (rTreeMapIndexNonPackFileName != null) {
|
||||
File f = new File(rTreeMapIndexNonPackFileName);
|
||||
|
@ -329,89 +289,100 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
|
|||
}
|
||||
}
|
||||
|
||||
/* FIXME
|
||||
public void writeBinaryMapIndex(BinaryMapIndexWriter writer, String regionName) throws IOException, SQLException {
|
||||
closePreparedStatements(mapBinaryStat, mapLowLevelBinaryStat);
|
||||
public void createRTreeFiles(String rTreeRouteIndexPackFileName) throws RTreeException {
|
||||
routeTree = new RTree(rTreeRouteIndexPackFileName);
|
||||
}
|
||||
|
||||
public void packRtreeFiles(String rTreeRouteIndexNonPackFileName, String rTreeRouteIndexPackFileName) throws IOException {
|
||||
routeTree = packRtreeFile(routeTree, rTreeRouteIndexNonPackFileName, rTreeRouteIndexPackFileName);
|
||||
|
||||
}
|
||||
|
||||
public void writeBinaryRouteIndex(BinaryMapIndexWriter writer, String regionName) throws IOException, SQLException {
|
||||
closePreparedStatements(mapRouteInsertStat);
|
||||
mapConnection.commit();
|
||||
try {
|
||||
writer.startWriteMapIndex(regionName);
|
||||
writer.startWriteRouteIndex(regionName);
|
||||
// write map encoding rules
|
||||
|
||||
writer.writeMapEncodingRules(routeTypes.getEncodingRuleTypes());
|
||||
|
||||
PreparedStatement selectData = mapConnection
|
||||
.prepareStatement("SELECT area, coordinates, innerPolygons, types, additionalTypes, name FROM binary_map_objects WHERE id = ?");
|
||||
writer.writeRouteEncodingRules(routeTypes.getEncodingRuleTypes());
|
||||
|
||||
PreparedStatement selectData = mapConnection.prepareStatement(SELECT_STAT);
|
||||
// write map levels and map index
|
||||
TLongObjectHashMap<BinaryFileReference> treeHeader = new TLongObjectHashMap<BinaryFileReference>();
|
||||
RTree rtree = mapTree;
|
||||
long rootIndex = rtree.getFileHdr().getRootIndex();
|
||||
rtree.Node root = rtree.getReadNode(rootIndex);
|
||||
long rootIndex = routeTree.getFileHdr().getRootIndex();
|
||||
rtree.Node root = routeTree.getReadNode(rootIndex);
|
||||
Rect rootBounds = calcBounds(root);
|
||||
if (rootBounds != null) {
|
||||
writer.startWriteMapLevelIndex(mapZooms.getLevel(i).getMinZoom(), mapZooms.getLevel(i).getMaxZoom(), rootBounds.getMinX(),
|
||||
rootBounds.getMaxX(), rootBounds.getMinY(), rootBounds.getMaxY());
|
||||
writeBinaryMapTree(root, rootBounds, rtree, writer, treeHeader);
|
||||
|
||||
writeBinaryMapBlock(root, rootBounds, rtree, writer, selectData, treeHeader, new LinkedHashMap<String, Integer>(),
|
||||
new LinkedHashMap<MapRenderingTypes.MapRulType, String>());
|
||||
|
||||
writer.endWriteMapLevelIndex();
|
||||
writeBinaryRouteTree(root, rootBounds, routeTree, writer, treeHeader);
|
||||
writeBinaryMapBlock(root, rootBounds, routeTree, writer, selectData, treeHeader, new LinkedHashMap<String, Integer>(),
|
||||
new LinkedHashMap<MapRouteType, String>());
|
||||
}
|
||||
|
||||
selectData.close();
|
||||
|
||||
writer.endWriteMapIndex();
|
||||
writer.endWriteRouteIndex();
|
||||
writer.flush();
|
||||
} catch (RTreeException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void writeBinaryMapBlock(rtree.Node parent, Rect parentBounds, RTree r, BinaryMapIndexWriter writer, PreparedStatement selectData,
|
||||
TLongObjectHashMap<BinaryFileReference> bounds, Map<String, Integer> tempStringTable, Map<MapRulType, String> tempNames)
|
||||
TLongObjectHashMap<BinaryFileReference> bounds, Map<String, Integer> tempStringTable, Map<MapRouteType, String> tempNames)
|
||||
throws IOException, RTreeException, SQLException {
|
||||
Element[] e = parent.getAllElements();
|
||||
|
||||
MapDataBlock.Builder dataBlock = null;
|
||||
RouteDataBlock.Builder dataBlock = null;
|
||||
BinaryFileReference ref = bounds.get(parent.getNodeIndex());
|
||||
long baseId = 0;
|
||||
for (int i = 0; i < parent.getTotalElements(); i++) {
|
||||
if (e[i].getElementType() == rtree.Node.LEAF_NODE) {
|
||||
long id = ((LeafElement) e[i]).getPtr();
|
||||
// IndexRouteCreator.SELECT_STAT;
|
||||
// "SELECT types, pointTypes, pointIds, pointCoordinates, name FROM route_objects WHERE id = ?"
|
||||
selectData.setLong(1, id);
|
||||
// selectData = mapConnection.prepareStatement("SELECT area, coordinates, innerPolygons, types, additionalTypes, name FROM binary_map_objects WHERE id = ?");
|
||||
|
||||
ResultSet rs = selectData.executeQuery();
|
||||
if (rs.next()) {
|
||||
long cid = convertGeneratedIdToObfWrite(id);
|
||||
long cid = id;
|
||||
if (dataBlock == null) {
|
||||
baseId = cid;
|
||||
dataBlock = writer.createWriteMapDataBlock(baseId);
|
||||
dataBlock = RouteDataBlock.newBuilder();
|
||||
tempStringTable.clear();
|
||||
|
||||
}
|
||||
tempNames.clear();
|
||||
decodeNames(rs.getString(6), tempNames);
|
||||
byte[] types = rs.getBytes(4);
|
||||
decodeNames(rs.getString(5), tempNames);
|
||||
byte[] types = rs.getBytes(1);
|
||||
int[] typeUse = new int[types.length / 2];
|
||||
for (int j = 0; j < types.length; j += 2) {
|
||||
int ids = Algoritms.parseSmallIntFromBytes(types, j);
|
||||
typeUse[j / 2] = routeTypes.getTypeByInternalId(ids).getTargetId();
|
||||
}
|
||||
byte[] addTypes = rs.getBytes(5);
|
||||
int[] addtypeUse = null ;
|
||||
if (addTypes != null) {
|
||||
addtypeUse = new int[addTypes.length / 2];
|
||||
for (int j = 0; j < addTypes.length; j += 2) {
|
||||
int ids = Algoritms.parseSmallIntFromBytes(addTypes, j);
|
||||
addtypeUse[j / 2] = routeTypes.getTypeByInternalId(ids).getTargetId();
|
||||
byte[] pointTypes = rs.getBytes(2);
|
||||
byte[] pointIds = rs.getBytes(3);
|
||||
byte[] pointCoordinates = rs.getBytes(4);
|
||||
int typeInd = 0;
|
||||
RoutePointToWrite[] points = new RoutePointToWrite[pointCoordinates.length / 8];
|
||||
for (int j = 0; j < points.length; j++) {
|
||||
points[j] = new RoutePointToWrite();
|
||||
points[j].x = Algoritms.parseIntFromBytes(pointCoordinates, j * 8);
|
||||
points[j].y = Algoritms.parseIntFromBytes(pointCoordinates, j * 8 + 4);
|
||||
points[j].id = Algoritms.parseLongFromBytes(pointIds, j * 8);
|
||||
int type = 0;
|
||||
do {
|
||||
type = Algoritms.parseSmallIntFromBytes(pointTypes, typeInd);
|
||||
typeInd += 2;
|
||||
if (type != 0) {
|
||||
points[j].types.add(routeTypes.getTypeByInternalId(type).getTargetId());
|
||||
}
|
||||
} while (type != 0);
|
||||
}
|
||||
|
||||
|
||||
MapData mapData = writer.writeMapData(cid - baseId, parentBounds.getMinX(), parentBounds.getMinY(), rs.getBoolean(1), rs.getBytes(2), rs.getBytes(3),
|
||||
typeUse, addtypeUse, tempNames, tempStringTable, dataBlock);
|
||||
if(mapData != null) {
|
||||
dataBlock.addDataObjects(mapData);
|
||||
RouteData routeData = writer.writeRouteData((int) cid, parentBounds.getMinX(), parentBounds.getMinY(), typeUse, points,
|
||||
names, tempStringTable, dataBlock, true);
|
||||
if (routeData != null) {
|
||||
dataBlock.addDataObjects(routeData);
|
||||
}
|
||||
} else {
|
||||
logMapDataWarn.error("Something goes wrong with id = " + id); //$NON-NLS-1$
|
||||
|
@ -419,7 +390,7 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
|
|||
}
|
||||
}
|
||||
if (dataBlock != null) {
|
||||
writer.writeMapDataBlock(dataBlock, tempStringTable, ref);
|
||||
writer.writeRouteDataBlock(dataBlock, tempStringTable, ref);
|
||||
}
|
||||
for (int i = 0; i < parent.getTotalElements(); i++) {
|
||||
if (e[i].getElementType() != rtree.Node.LEAF_NODE) {
|
||||
|
@ -430,7 +401,7 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
|
|||
}
|
||||
}
|
||||
|
||||
public void writeBinaryMapTree(rtree.Node parent, Rect re, RTree r, BinaryMapIndexWriter writer, TLongObjectHashMap<BinaryFileReference> bounds)
|
||||
public void writeBinaryRouteTree(rtree.Node parent, Rect re, RTree r, BinaryMapIndexWriter writer, TLongObjectHashMap<BinaryFileReference> bounds)
|
||||
throws IOException, RTreeException {
|
||||
Element[] e = parent.getAllElements();
|
||||
boolean containsLeaf = false;
|
||||
|
@ -439,17 +410,16 @@ public class IndexRouteCreator extends AbstractIndexPartCreator {
|
|||
containsLeaf = true;
|
||||
}
|
||||
}
|
||||
BinaryFileReference ref = writer.startMapTreeElement(re.getMinX(), re.getMaxX(), re.getMinY(), re.getMaxY(), containsLeaf);
|
||||
BinaryFileReference ref = writer.startRouteTreeElement(re.getMinX(), re.getMaxX(), re.getMinY(), re.getMaxY(), containsLeaf);
|
||||
if (ref != null) {
|
||||
bounds.put(parent.getNodeIndex(), ref);
|
||||
}
|
||||
for (int i = 0; i < parent.getTotalElements(); i++) {
|
||||
if (e[i].getElementType() != rtree.Node.LEAF_NODE) {
|
||||
rtree.Node chNode = r.getReadNode(((NonLeafElement) e[i]).getPtr());
|
||||
writeBinaryMapTree(chNode, e[i].getRect(), r, writer, bounds);
|
||||
writeBinaryRouteTree(chNode, e[i].getRect(), r, writer, bounds);
|
||||
}
|
||||
}
|
||||
writer.endWriteMapTreeElement();
|
||||
writer.endRouteTreeElement();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.osm.MapRoutingTypes.MapRouteType;
|
||||
|
||||
public class MapRoutingTypes {
|
||||
|
||||
private static Set<String> TAGS_TO_SAVE = new HashSet<String>();
|
||||
|
@ -62,7 +64,11 @@ public class MapRoutingTypes {
|
|||
}
|
||||
|
||||
|
||||
public boolean encodeEntity(Way e, TIntArrayList outTypes, TLongObjectHashMap<TIntArrayList> pointTypes){
|
||||
public boolean encodeEntity(Entity et, TIntArrayList outTypes, TLongObjectHashMap<TIntArrayList> pointTypes, Map<MapRouteType, String> names){
|
||||
if (!(et instanceof Way)) {
|
||||
return false;
|
||||
}
|
||||
Way e = (Way) et;
|
||||
boolean init = false;
|
||||
for(String tg : e.getTagKeySet()) {
|
||||
if(TAGS_TO_ACCEPT.contains(tg)){
|
||||
|
@ -105,6 +111,7 @@ public class MapRoutingTypes {
|
|||
String id = constructRuleKey(tag, val);
|
||||
if(!types.containsKey(id)) {
|
||||
MapRouteType rt = new MapRouteType();
|
||||
// first one is always 1
|
||||
rt.id = types.size() + 1;
|
||||
rt.tag = tag;
|
||||
rt.value = val;
|
||||
|
@ -112,12 +119,12 @@ public class MapRoutingTypes {
|
|||
listTypes.add(rt);
|
||||
}
|
||||
MapRouteType type = types.get(id);
|
||||
type.count ++;
|
||||
type.freq ++;
|
||||
return type;
|
||||
}
|
||||
|
||||
public static class MapRouteType {
|
||||
int count = 0;
|
||||
int freq = 0;
|
||||
int id;
|
||||
int targetId;
|
||||
String tag;
|
||||
|
@ -127,9 +134,29 @@ public class MapRoutingTypes {
|
|||
return id;
|
||||
}
|
||||
|
||||
public int getFreq() {
|
||||
return freq;
|
||||
}
|
||||
|
||||
public int getTargetId() {
|
||||
return targetId;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setTargetId(int targetId) {
|
||||
this.targetId = targetId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<MapRouteType> getEncodingRuleTypes() {
|
||||
return listTypes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// Highly coupled with protobuf 2.3.0
|
||||
option java_package = "net.osmand.binary";
|
||||
//protoc --java_out=DataExtractionOSM/src DataExtractionOSM/src/osmand_odb.proto
|
||||
|
||||
|
@ -489,6 +490,10 @@ message RouteData {
|
|||
required bytes types = 7;
|
||||
|
||||
required int32 routeId = 12; // id internal
|
||||
|
||||
// repeated array<pair<tagId : raw_var_int, indexOfStringInParent : raw_var_int> >
|
||||
optional bytes stringNames = 14; // in parent block
|
||||
|
||||
}
|
||||
|
||||
message OsmAndRoutingIndex {
|
||||
|
@ -525,8 +530,10 @@ message OsmAndRoutingIndex {
|
|||
// required sint32 top = 3; // delta encoded
|
||||
// required sint32 bottom = 4; // delta encoded
|
||||
optional IdTable idTable = 5;
|
||||
optional StringTable stringTable = 8;
|
||||
repeated RouteData dataObjects = 6;
|
||||
repeated RestrictionData restrictions = 7;
|
||||
|
||||
}
|
||||
|
||||
}
|
10
Osmand-kernel/configure.sh
Normal file → Executable file
10
Osmand-kernel/configure.sh
Normal file → Executable file
|
@ -1,2 +1,8 @@
|
|||
cd zlib && configure.sh && cd ..
|
||||
cd pthread && configure.sh && cd ..
|
||||
chmod +x zlib/configure.sh
|
||||
cd zlib
|
||||
./configure.sh
|
||||
cd ..
|
||||
chmod +x pthread/configure.sh
|
||||
cd pthread
|
||||
./configure.sh
|
||||
cd ..
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -177,6 +177,7 @@ void drawWrappedText(RenderingContext* rc, SkCanvas* cv, TextDrawInfo* text, flo
|
|||
|
||||
if(text->text.length() > text->textWrap) {
|
||||
const char* c_str = text->text.c_str();
|
||||
|
||||
int end = text->text.length();
|
||||
int line = 0;
|
||||
int pos = 0;
|
||||
|
|
2
Osmand-kernel/pthread/.gitignore
vendored
2
Osmand-kernel/pthread/.gitignore
vendored
|
@ -1,2 +1,2 @@
|
|||
pthreads_library
|
||||
pthreads_library/
|
||||
build-*
|
||||
|
|
0
Osmand-kernel/pthread/configure.sh
Normal file → Executable file
0
Osmand-kernel/pthread/configure.sh
Normal file → Executable file
2
Osmand-kernel/zlib/.gitignore
vendored
2
Osmand-kernel/zlib/.gitignore
vendored
|
@ -1,2 +1,2 @@
|
|||
zlib_library
|
||||
zlib_library/
|
||||
build-*
|
||||
|
|
4
Osmand-kernel/zlib/configure.sh
Normal file → Executable file
4
Osmand-kernel/zlib/configure.sh
Normal file → Executable file
|
@ -1,2 +1,2 @@
|
|||
wget -qO - http://zlib.net/zlib-1.2.4.tar.gz | tar xzvf -
|
||||
mv zlib-1.2.4 zlib_library
|
||||
wget -qO - http://zlib.net/zlib-1.2.7.tar.gz | tar xzvf -
|
||||
mv zlib-1.2.7 zlib_library
|
||||
|
|
Loading…
Reference in a new issue