use of net.osmand.binary.OsmandOdb.StreetIndex in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method createStreetAndBuildings.
protected StreetIndex createStreetAndBuildings(Street street, int cx, int cy, String postcodeFilter, Map<Long, Set<Street>> mapNodeToStreet, Map<Street, List<Node>> wayNodes, Map<String, Integer> tagRules) throws IOException {
checkPeekState(CITY_INDEX_INIT);
StreetIndex.Builder streetBuilder = OsmandOdb.StreetIndex.newBuilder();
streetBuilder.setName(street.getName());
if (checkEnNameToWrite(street)) {
streetBuilder.setNameEn(street.getEnName(false));
}
Iterator<Entry<String, String>> it = street.getNamesMap(false).entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> next = it.next();
Integer intg = tagRules.get("name:" + next.getKey());
if (intg != null) {
streetBuilder.addAttributeTagIds(intg);
streetBuilder.addAttributeValues(next.getValue());
}
}
streetBuilder.setId(street.getId());
int sx = MapUtils.get31TileNumberX(street.getLocation().getLongitude());
int sy = MapUtils.get31TileNumberY(street.getLocation().getLatitude());
streetBuilder.setX((sx - cx) >> 7);
streetBuilder.setY((sy - cy) >> 7);
street.sortBuildings();
for (Building b : street.getBuildings()) {
if (postcodeFilter != null && !postcodeFilter.equalsIgnoreCase(b.getPostcode())) {
continue;
}
OsmandOdb.BuildingIndex.Builder bbuilder = OsmandOdb.BuildingIndex.newBuilder();
int bx = MapUtils.get31TileNumberX(b.getLocation().getLongitude());
int by = MapUtils.get31TileNumberY(b.getLocation().getLatitude());
bbuilder.setX((bx - sx) >> 7);
bbuilder.setY((by - sy) >> 7);
String number2 = b.getName2();
if (!Algorithms.isEmpty(number2)) {
LatLon loc = b.getLatLon2();
if (loc == null) {
bbuilder.setX((bx - sx) >> 7);
bbuilder.setY((by - sy) >> 7);
} else {
int bcx = MapUtils.get31TileNumberX(loc.getLongitude());
int bcy = MapUtils.get31TileNumberY(loc.getLatitude());
bbuilder.setX2((bcx - sx) >> 7);
bbuilder.setY2((bcy - sy) >> 7);
}
bbuilder.setName2(number2);
if (b.getInterpolationType() != null) {
bbuilder.setInterpolation(b.getInterpolationType().getValue());
} else if (b.getInterpolationInterval() > 0) {
bbuilder.setInterpolation(b.getInterpolationInterval());
} else {
bbuilder.setInterpolation(1);
}
}
// bbuilder.setId(b.getId());
bbuilder.setName(b.getName());
if (b.getPostcode() != null) {
bbuilder.setPostcode(b.getPostcode());
}
it = b.getNamesMap(false).entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> next = it.next();
Integer intg = tagRules.get("name:" + next.getKey());
if (intg != null) {
bbuilder.addAttributeTagIds(intg);
bbuilder.addAttributeValues(next.getValue());
}
}
if (checkEnNameToWrite(b)) {
bbuilder.setNameEn(b.getEnName(false));
}
if (postcodeFilter == null && b.getPostcode() != null) {
bbuilder.setPostcode(b.getPostcode());
}
streetBuilder.addBuildings(bbuilder.build());
}
if (wayNodes != null) {
Set<Street> checkedStreets = new TreeSet<Street>();
for (Node intersection : wayNodes.get(street)) {
for (Street streetJ : mapNodeToStreet.get(intersection.getId())) {
if (checkedStreets.contains(streetJ) || streetJ.getId().longValue() == street.getId().longValue()) {
continue;
}
checkedStreets.add(streetJ);
StreetIntersection.Builder builder = OsmandOdb.StreetIntersection.newBuilder();
int ix = MapUtils.get31TileNumberX(intersection.getLongitude());
int iy = MapUtils.get31TileNumberY(intersection.getLatitude());
builder.setIntersectedX((ix - sx) >> 7);
builder.setIntersectedY((iy - sy) >> 7);
builder.setName(streetJ.getName());
if (checkEnNameToWrite(streetJ)) {
builder.setNameEn(streetJ.getEnName(false));
}
it = streetJ.getNamesMap(false).entrySet().iterator();
while (it.hasNext()) {
Entry<String, String> next = it.next();
Integer intg = tagRules.get("name:" + next.getKey());
if (intg != null) {
builder.addAttributeTagIds(intg);
builder.addAttributeValues(next.getValue());
}
}
streetBuilder.addIntersections(builder.build());
}
}
}
return streetBuilder.build();
}
use of net.osmand.binary.OsmandOdb.StreetIndex 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