use of net.osmand.binary.OsmandOdb.MapData in project OsmAnd-tools by osmandapp.
the class IndexUploader method writeBinaryMapBlock.
public static void writeBinaryMapBlock(Node parent, Rect parentBounds, RTree r, BinaryMapIndexWriter writer, TLongObjectHashMap<BinaryFileReference> bounds, TLongObjectHashMap<BinaryMapDataObject> objects, MapZooms.MapZoomPair pair, boolean doNotSimplify) throws IOException, RTreeException {
rtree.Element[] e = parent.getAllElements();
MapDataBlock.Builder dataBlock = null;
BinaryFileReference ref = bounds.get(parent.getNodeIndex());
long baseId = 0;
Map<String, Integer> tempStringTable = new LinkedHashMap<String, Integer>();
for (int i = 0; i < parent.getTotalElements(); i++) {
if (e[i].getElementType() == rtree.Node.LEAF_NODE) {
long id = e[i].getPtr();
if (objects.containsKey(id)) {
long cid = id;
BinaryMapDataObject mdo = objects.get(id);
if (dataBlock == null) {
baseId = cid;
dataBlock = writer.createWriteMapDataBlock(baseId);
tempStringTable.clear();
}
int[] typeUse = mdo.getTypes();
int[] addtypeUse = mdo.getAdditionalTypes();
byte[] coordinates = new byte[8 * mdo.getPointsLength()];
for (int t = 0; t < mdo.getPointsLength(); t++) {
Algorithms.putIntToBytes(coordinates, 8 * t, mdo.getPoint31XTile(t));
Algorithms.putIntToBytes(coordinates, 8 * t + 4, mdo.getPoint31YTile(t));
}
byte[] innerPolygonTypes = new byte[0];
int[][] pip = mdo.getPolygonInnerCoordinates();
if (pip != null && pip.length > 0) {
ByteArrayOutputStream bous = new ByteArrayOutputStream();
for (int s = 0; s < pip.length; s++) {
int[] st = pip[s];
for (int t = 0; t < st.length; t++) {
Algorithms.writeInt(bous, st[t]);
}
Algorithms.writeInt(bous, 0);
Algorithms.writeInt(bous, 0);
}
innerPolygonTypes = bous.toByteArray();
}
MapData mapData = writer.writeMapData(cid - baseId, parentBounds.getMinX(), parentBounds.getMinY(), mdo.isArea(), coordinates, innerPolygonTypes, typeUse, addtypeUse, null, mdo.getOrderedObjectNames(), tempStringTable, dataBlock, !doNotSimplify && pair.getMaxZoom() > 15);
if (mapData != null) {
dataBlock.addDataObjects(mapData);
}
} else {
// $NON-NLS-1$
log.error("Something goes wrong with id = " + id);
}
}
}
if (dataBlock != null) {
writer.writeMapDataBlock(dataBlock, tempStringTable, ref);
}
for (int i = 0; i < parent.getTotalElements(); i++) {
if (e[i].getElementType() != rtree.Node.LEAF_NODE) {
long ptr = e[i].getPtr();
rtree.Node ns = r.getReadNode(ptr);
writeBinaryMapBlock(ns, e[i].getRect(), r, writer, bounds, objects, pair, doNotSimplify);
}
}
}
use of net.osmand.binary.OsmandOdb.MapData in project OsmAnd-tools by osmandapp.
the class BasemapProcessor method writeBinaryMapBlock.
private void writeBinaryMapBlock(SimplisticQuadTree simplisticQuadTree, BinaryMapIndexWriter writer, Map<SimplisticQuadTree, BinaryFileReference> refs, MapZoomPair level) throws IOException {
Iterator<Entry<SimplisticQuadTree, BinaryFileReference>> it = refs.entrySet().iterator();
while (it.hasNext()) {
Entry<SimplisticQuadTree, BinaryFileReference> e = it.next();
MapDataBlock.Builder dataBlock = MapDataBlock.newBuilder();
SimplisticQuadTree quad = e.getKey();
Map<String, Integer> stringTable = new LinkedHashMap<String, Integer>();
long baseId = 0;
for (SimplisticBinaryData w : quad.getData(level)) {
baseId = Math.min(w.id, baseId);
}
dataBlock.setBaseId(baseId);
for (SimplisticBinaryData w : quad.getData(level)) {
int[] wts = null;
int[] wats = null;
if (w.types != null) {
wts = new int[w.types.length];
for (int j = 0; j < w.types.length; j++) {
wts[j] = renderingTypes.getTypeByInternalId(w.types[j]).getTargetId();
}
}
if (w.addTypes != null) {
wats = new int[w.addTypes.length];
for (int j = 0; j < w.addTypes.length; j++) {
wats[j] = renderingTypes.getTypeByInternalId(w.addTypes[j]).getTargetId();
}
}
MapData mapData = writer.writeMapData(w.id - baseId, quad.x << (31 - quad.zoom), quad.y << (31 - quad.zoom), false, w.coordinates, w.innerCoordinates, wts, wats, w.names, null, stringTable, dataBlock, level.getMaxZoom() > 15);
if (mapData != null) {
dataBlock.addDataObjects(mapData);
}
}
writer.writeMapDataBlock(dataBlock, stringTable, e.getValue());
}
}
use of net.osmand.binary.OsmandOdb.MapData in project OsmAnd-tools by osmandapp.
the class IndexVectorMapCreator method writeBinaryMapBlock.
public void writeBinaryMapBlock(rtree.Node parent, Rect parentBounds, RTree r, BinaryMapIndexWriter writer, PreparedStatement selectData, TLongObjectHashMap<BinaryFileReference> bounds, Map<String, Integer> tempStringTable, LinkedHashMap<MapRulType, String> tempNames, MapZoomPair level) throws IOException, RTreeException, SQLException {
Element[] e = parent.getAllElements();
MapDataBlock.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 = e[i].getPtr();
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);
if (dataBlock == null) {
baseId = cid;
dataBlock = writer.createWriteMapDataBlock(baseId);
tempStringTable.clear();
}
tempNames.clear();
decodeNames(rs.getString(6), tempNames);
byte[] types = rs.getBytes(4);
int[] typeUse = new int[types.length / 2];
for (int j = 0; j < types.length; j += 2) {
int ids = Algorithms.parseSmallIntFromBytes(types, j);
typeUse[j / 2] = renderingTypes.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 = Algorithms.parseSmallIntFromBytes(addTypes, j);
addtypeUse[j / 2] = renderingTypes.getTypeByInternalId(ids).getTargetId();
}
}
MapData mapData = writer.writeMapData(cid - baseId, parentBounds.getMinX(), parentBounds.getMinY(), rs.getBoolean(1), rs.getBytes(2), rs.getBytes(3), typeUse, addtypeUse, tempNames, null, tempStringTable, dataBlock, level.getMaxZoom() > 15);
if (mapData != null) {
dataBlock.addDataObjects(mapData);
}
} else {
// $NON-NLS-1$
logMapDataWarn.error("Something goes wrong with id = " + id);
}
}
}
if (dataBlock != null) {
writer.writeMapDataBlock(dataBlock, tempStringTable, ref);
}
for (int i = 0; i < parent.getTotalElements(); i++) {
if (e[i].getElementType() != rtree.Node.LEAF_NODE) {
long ptr = e[i].getPtr();
rtree.Node ns = r.getReadNode(ptr);
writeBinaryMapBlock(ns, e[i].getRect(), r, writer, selectData, bounds, tempStringTable, tempNames, level);
}
}
}
Aggregations