use of net.osmand.binary.OsmandOdb.CityBlockIndex in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method writeCityIndex.
public void writeCityIndex(City cityOrPostcode, List<Street> streets, Map<Street, List<Node>> wayNodes, BinaryFileReference ref, Map<String, Integer> tagRules) throws IOException {
checkPeekState(CITY_INDEX_INIT);
codedOutStream.writeTag(CitiesIndex.BLOCKS_FIELD_NUMBER, FieldType.MESSAGE.getWireType());
codedOutStream.flush();
long startMessage = getFilePointer();
long startCityBlock = ref.getStartPointer();
ref.writeReference(raf, startMessage);
CityBlockIndex.Builder cityInd = OsmandOdb.CityBlockIndex.newBuilder();
cityInd.setShiftToCityIndex((int) (startMessage - startCityBlock));
long currentPointer = startMessage + 4 + CodedOutputStream.computeTagSize(CityBlockIndex.SHIFTTOCITYINDEX_FIELD_NUMBER);
int cx = MapUtils.get31TileNumberX(cityOrPostcode.getLocation().getLongitude());
int cy = MapUtils.get31TileNumberY(cityOrPostcode.getLocation().getLatitude());
Map<Long, Set<Street>> mapNodeToStreet = new LinkedHashMap<Long, Set<Street>>();
if (wayNodes != null) {
for (int i = 0; i < streets.size(); i++) {
for (Node n : wayNodes.get(streets.get(i))) {
if (!mapNodeToStreet.containsKey(n.getId())) {
mapNodeToStreet.put(n.getId(), new LinkedHashSet<Street>(3));
}
mapNodeToStreet.get(n.getId()).add(streets.get(i));
}
}
}
String postcodeFilter = cityOrPostcode.isPostcode() ? cityOrPostcode.getName() : null;
for (Street s : streets) {
StreetIndex streetInd = createStreetAndBuildings(s, cx, cy, postcodeFilter, mapNodeToStreet, wayNodes, tagRules);
currentPointer += CodedOutputStream.computeTagSize(CityBlockIndex.STREETS_FIELD_NUMBER);
if (currentPointer > Integer.MAX_VALUE) {
throw new IllegalArgumentException("File offset > 2 GB.");
}
s.setFileOffset((int) currentPointer);
currentPointer += CodedOutputStream.computeMessageSizeNoTag(streetInd);
cityInd.addStreets(streetInd);
}
CityBlockIndex block = cityInd.build();
int size = CodedOutputStream.computeRawVarint32Size(block.getSerializedSize());
codedOutStream.writeMessageNoTag(block);
for (Street s : streets) {
s.setFileOffset(s.getFileOffset() + size);
}
}
Aggregations