use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion in project OsmAnd-tools by osmandapp.
the class ManyToOneRoadCalculation method cut.
private void cut(BinaryMapIndexReader reader) throws IOException {
RoutePlannerFrontEnd frontEnd = new RoutePlannerFrontEnd(false);
RoutingConfiguration config = RoutingConfiguration.getDefault().build("car", 1000);
RouteCalculationMode mode = RouteCalculationMode.BASE;
RoutingContext ctx = frontEnd.buildRoutingContext(config, null, new BinaryMapIndexReader[] { reader }, mode);
RouteRegion reg = reader.getRoutingIndexes().get(0);
List<RouteSubregion> baseSubregions = reg.getBaseSubregions();
List<RoutingSubregionTile> tiles = new ArrayList<RoutingContext.RoutingSubregionTile>();
for (RouteSubregion s : baseSubregions) {
List<RoutingSubregionTile> loadTiles = ctx.loadAllSubregionTiles(reader, s);
tiles.addAll(loadTiles);
}
int zoom = 9;
int ty = (int) MapUtils.getTileNumberY(zoom, reg.getTopLatitude());
int by = (int) MapUtils.getTileNumberY(zoom, reg.getBottomLatitude()) + 1;
int lx = (int) MapUtils.getTileNumberX(zoom, reg.getLeftLongitude());
int rx = (int) MapUtils.getTileNumberX(zoom, reg.getRightLongitude()) + 1;
for (int ky = ty + 1; ky < by; ky++) {
for (int kx = lx + 1; kx < rx; kx++) {
cutByQuadrant((kx - 1) << (31 - zoom), (ky - 1) << (31 - zoom), kx << (31 - zoom), ky << (31 - zoom), ctx, tiles);
}
}
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion in project OsmAnd-tools by osmandapp.
the class CheckRoadConnectivity method clustering.
public void clustering(final ClusteringContext clusterCtx, BinaryMapIndexReader reader) throws IOException {
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(false);
Builder builder = RoutingConfiguration.getDefault();
RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
RoutingContext ctx = router.buildRoutingContext(config, null, new BinaryMapIndexReader[] { reader }, RouteCalculationMode.BASE);
if (reader.getRoutingIndexes().size() != 1) {
throw new UnsupportedOperationException();
}
RouteRegion reg = reader.getRoutingIndexes().get(0);
List<RouteSubregion> baseSubregions = reg.getBaseSubregions();
List<RoutingSubregionTile> tiles = new ArrayList<RoutingContext.RoutingSubregionTile>();
for (RouteSubregion s : baseSubregions) {
List<RoutingSubregionTile> loadTiles = ctx.loadAllSubregionTiles(reader, s);
tiles.addAll(loadTiles);
}
List<Cluster> allClusters = new ArrayList<CheckRoadConnectivity.Cluster>();
for (RoutingSubregionTile tile : tiles) {
List<Cluster> clusters = processDataObjects(ctx, tile);
allClusters.addAll(clusters);
}
combineClusters(allClusters, tiles);
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion in project Osmand by osmandapp.
the class CachedOsmandIndexes method addToCache.
public void addToCache(BinaryMapIndexReader reader, File f) {
hasChanged = true;
if (storedIndexBuilder == null) {
storedIndexBuilder = OsmandIndex.OsmAndStoredIndex.newBuilder();
storedIndexBuilder.setVersion(VERSION);
storedIndexBuilder.setDateCreated(System.currentTimeMillis());
if (storedIndex != null) {
for (FileIndex ex : storedIndex.getFileIndexList()) {
storedIndexBuilder.addFileIndex(ex);
}
}
}
FileIndex.Builder fileIndex = OsmandIndex.FileIndex.newBuilder();
long d = reader.getDateCreated();
fileIndex.setDateModified(d == 0 ? f.lastModified() : d);
fileIndex.setSize(f.length());
fileIndex.setVersion(reader.getVersion());
fileIndex.setFileName(f.getName());
for (MapIndex index : reader.getMapIndexes()) {
MapPart.Builder map = OsmandIndex.MapPart.newBuilder();
map.setSize(index.getLength());
map.setOffset(index.getFilePointer());
if (index.getName() != null) {
map.setName(index.getName());
}
for (MapRoot mr : index.getRoots()) {
MapLevel.Builder lev = OsmandIndex.MapLevel.newBuilder();
lev.setSize(mr.length);
lev.setOffset(mr.filePointer);
lev.setLeft(mr.left);
lev.setRight(mr.right);
lev.setTop(mr.top);
lev.setBottom(mr.bottom);
lev.setMinzoom(mr.minZoom);
lev.setMaxzoom(mr.maxZoom);
map.addLevels(lev);
}
fileIndex.addMapIndex(map);
}
for (AddressRegion index : reader.getAddressIndexes()) {
AddressPart.Builder addr = OsmandIndex.AddressPart.newBuilder();
addr.setSize(index.getLength());
addr.setOffset(index.getFilePointer());
if (index.getName() != null) {
addr.setName(index.getName());
}
if (index.getEnName() != null) {
addr.setNameEn(index.getEnName());
}
addr.setIndexNameOffset(index.getIndexNameOffset());
for (CitiesBlock mr : index.getCities()) {
CityBlock.Builder cblock = OsmandIndex.CityBlock.newBuilder();
cblock.setSize(mr.length);
cblock.setOffset(mr.filePointer);
cblock.setType(mr.type);
addr.addCities(cblock);
}
for (String s : index.getAttributeTagsTable()) {
addr.addAdditionalTags(s);
}
fileIndex.addAddressIndex(addr);
}
for (PoiRegion index : reader.getPoiIndexes()) {
PoiPart.Builder poi = OsmandIndex.PoiPart.newBuilder();
poi.setSize(index.getLength());
poi.setOffset(index.getFilePointer());
if (index.getName() != null) {
poi.setName(index.getName());
}
poi.setLeft(index.left31);
poi.setRight(index.right31);
poi.setTop(index.top31);
poi.setBottom(index.bottom31);
fileIndex.addPoiIndex(poi.build());
}
for (TransportIndex index : reader.getTransportIndexes()) {
TransportPart.Builder transport = OsmandIndex.TransportPart.newBuilder();
transport.setSize(index.getLength());
transport.setOffset(index.getFilePointer());
if (index.getName() != null) {
transport.setName(index.getName());
}
transport.setLeft(index.getLeft());
transport.setRight(index.getRight());
transport.setTop(index.getTop());
transport.setBottom(index.getBottom());
transport.setStopsTableLength(index.stopsFileLength);
transport.setStopsTableOffset(index.stopsFileOffset);
transport.setStringTableLength(index.stringTable.length);
transport.setStringTableOffset(index.stringTable.fileOffset);
fileIndex.addTransportIndex(transport);
}
for (RouteRegion index : reader.getRoutingIndexes()) {
RoutingPart.Builder routing = OsmandIndex.RoutingPart.newBuilder();
routing.setSize(index.getLength());
routing.setOffset(index.getFilePointer());
if (index.getName() != null) {
routing.setName(index.getName());
}
for (RouteSubregion sub : index.getSubregions()) {
addRouteSubregion(routing, sub, false);
}
for (RouteSubregion sub : index.getBaseSubregions()) {
addRouteSubregion(routing, sub, true);
}
fileIndex.addRoutingIndex(routing);
}
storedIndexBuilder.addFileIndex(fileIndex);
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion in project Osmand by osmandapp.
the class CachedOsmandIndexes method initFileIndex.
private BinaryMapIndexReader initFileIndex(FileIndex found, RandomAccessFile mf, File f) throws IOException {
BinaryMapIndexReader reader = new BinaryMapIndexReader(mf, f, false);
reader.version = found.getVersion();
reader.dateCreated = found.getDateModified();
for (MapPart index : found.getMapIndexList()) {
MapIndex mi = new MapIndex();
mi.length = (int) index.getSize();
mi.filePointer = (int) index.getOffset();
mi.name = index.getName();
for (MapLevel mr : index.getLevelsList()) {
MapRoot root = new MapRoot();
root.length = (int) mr.getSize();
root.filePointer = (int) mr.getOffset();
root.left = mr.getLeft();
root.right = mr.getRight();
root.top = mr.getTop();
root.bottom = mr.getBottom();
root.minZoom = mr.getMinzoom();
root.maxZoom = mr.getMaxzoom();
mi.roots.add(root);
}
reader.mapIndexes.add(mi);
reader.indexes.add(mi);
reader.basemap = reader.basemap || mi.isBaseMap();
}
for (AddressPart index : found.getAddressIndexList()) {
AddressRegion mi = new AddressRegion();
mi.length = (int) index.getSize();
mi.filePointer = (int) index.getOffset();
mi.name = index.getName();
mi.enName = index.getNameEn();
mi.indexNameOffset = index.getIndexNameOffset();
for (CityBlock mr : index.getCitiesList()) {
CitiesBlock cblock = new CitiesBlock();
cblock.length = (int) mr.getSize();
cblock.filePointer = (int) mr.getOffset();
cblock.type = mr.getType();
mi.cities.add(cblock);
}
for (String s : index.getAdditionalTagsList()) {
mi.attributeTagsTable.add(s);
}
reader.addressIndexes.add(mi);
reader.indexes.add(mi);
}
for (PoiPart index : found.getPoiIndexList()) {
PoiRegion mi = new PoiRegion();
mi.length = (int) index.getSize();
mi.filePointer = (int) index.getOffset();
mi.name = index.getName();
mi.left31 = index.getLeft();
mi.right31 = index.getRight();
mi.top31 = index.getTop();
mi.bottom31 = index.getBottom();
reader.poiIndexes.add(mi);
reader.indexes.add(mi);
}
for (TransportPart index : found.getTransportIndexList()) {
TransportIndex mi = new TransportIndex();
mi.length = (int) index.getSize();
mi.filePointer = (int) index.getOffset();
mi.name = index.getName();
mi.left = index.getLeft();
mi.right = index.getRight();
mi.top = index.getTop();
mi.bottom = index.getBottom();
mi.stopsFileLength = index.getStopsTableLength();
mi.stopsFileOffset = index.getStopsTableOffset();
mi.stringTable = new IndexStringTable();
mi.stringTable.fileOffset = index.getStringTableOffset();
mi.stringTable.length = index.getStringTableLength();
reader.transportIndexes.add(mi);
reader.indexes.add(mi);
}
for (RoutingPart index : found.getRoutingIndexList()) {
RouteRegion mi = new RouteRegion();
mi.length = (int) index.getSize();
mi.filePointer = (int) index.getOffset();
mi.name = index.getName();
for (RoutingSubregion mr : index.getSubregionsList()) {
RouteSubregion sub = new RouteSubregion(mi);
sub.length = (int) mr.getSize();
sub.filePointer = (int) mr.getOffset();
sub.left = mr.getLeft();
sub.right = mr.getRight();
sub.top = mr.getTop();
sub.bottom = mr.getBottom();
sub.shiftToData = mr.getShifToData();
if (mr.getBasemap()) {
mi.basesubregions.add(sub);
} else {
mi.subregions.add(sub);
}
}
reader.routingIndexes.add(mi);
reader.indexes.add(mi);
}
return reader;
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion in project Osmand by osmandapp.
the class RoutingContext method loadTileHeaders.
public List<RoutingSubregionTile> loadTileHeaders(final int zoomToLoadM31, int tileX, int tileY) {
SearchRequest<RouteDataObject> request = BinaryMapIndexReader.buildSearchRouteRequest(tileX << zoomToLoadM31, (tileX + 1) << zoomToLoadM31, tileY << zoomToLoadM31, (tileY + 1) << zoomToLoadM31, null);
List<RoutingSubregionTile> collection = null;
for (Entry<BinaryMapIndexReader, List<RouteSubregion>> r : map.entrySet()) {
// NOTE: load headers same as we do in non-native (it is not native optimized)
try {
if (r.getValue().size() > 0) {
long now = System.nanoTime();
// int rg = r.getValue().get(0).routeReg.regionsRead;
List<RouteSubregion> subregs = r.getKey().searchRouteIndexTree(request, r.getValue());
if (subregs.size() > 0) {
checkOldRoutingFiles(r.getKey());
}
for (RouteSubregion sr : subregs) {
int ind = searchSubregionTile(sr);
RoutingSubregionTile found;
if (ind < 0) {
found = new RoutingSubregionTile(sr);
subregionTiles.add(-(ind + 1), found);
} else {
found = subregionTiles.get(ind);
}
if (collection == null) {
collection = new ArrayList<RoutingContext.RoutingSubregionTile>(4);
}
collection.add(found);
}
timeToLoadHeaders += (System.nanoTime() - now);
}
} catch (IOException e) {
throw new RuntimeException("Loading data exception", e);
}
}
return collection;
}
Aggregations