use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion in project OsmAnd-tools by osmandapp.
the class IndexUploader method extractRoadOnlyFile.
public static void extractRoadOnlyFile(File mainFile, File roadOnlyFile) throws IOException, RTreeException {
RandomAccessFile raf = new RandomAccessFile(mainFile, "r");
BinaryMapIndexReader index = new BinaryMapIndexReader(raf, mainFile);
final RandomAccessFile routf = new RandomAccessFile(roadOnlyFile, "rw");
routf.setLength(0);
CodedOutputStream ous = CodedOutputStream.newInstance(new OutputStream() {
@Override
public void write(int b) throws IOException {
routf.write(b);
}
@Override
public void write(byte[] b) throws IOException {
routf.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
routf.write(b, off, len);
}
});
byte[] BUFFER_TO_READ = new byte[BUFFER_SIZE];
ous.writeInt32(OsmandOdb.OsmAndStructure.VERSION_FIELD_NUMBER, index.getVersion());
ous.writeInt64(OsmandOdb.OsmAndStructure.DATECREATED_FIELD_NUMBER, index.getDateCreated());
for (int i = 0; i < index.getIndexes().size(); i++) {
BinaryIndexPart part = index.getIndexes().get(i);
if (part instanceof MapIndex) {
// skip map part
copyMapIndex(roadOnlyFile, (MapIndex) part, index, ous, routf);
continue;
} else if (part instanceof AddressRegion) {
ous.writeTag(OsmandOdb.OsmAndStructure.ADDRESSINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
} else if (part instanceof TransportIndex) {
ous.writeTag(OsmandOdb.OsmAndStructure.TRANSPORTINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
} else if (part instanceof PoiRegion) {
ous.writeTag(OsmandOdb.OsmAndStructure.POIINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
} else if (part instanceof RouteRegion) {
ous.writeTag(OsmandOdb.OsmAndStructure.ROUTINGINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
} else {
throw new UnsupportedOperationException();
}
BinaryMerger.writeInt(ous, part.getLength());
BinaryMerger.copyBinaryPart(ous, BUFFER_TO_READ, raf, part.getFilePointer(), part.getLength());
}
ous.writeInt32(OsmandOdb.OsmAndStructure.VERSIONCONFIRM_FIELD_NUMBER, index.getVersion());
ous.flush();
routf.close();
raf.close();
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion 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.RouteRegion 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.RouteRegion in project OsmAnd-tools by osmandapp.
the class MapAddressLayer method justifyResults.
private double justifyResults(List<BinaryMapIndexReader> list, GeocodingUtilities su, List<GeocodingResult> complete, List<GeocodingResult> res) throws IOException {
double minBuildingDistance = 0;
for (GeocodingResult r : res) {
BinaryMapIndexReader reader = null;
for (BinaryMapIndexReader b : list) {
for (RouteRegion rb : b.getRoutingIndexes()) {
if (r.regionFP == rb.getFilePointer() && r.regionLen == rb.getLength()) {
reader = b;
break;
}
}
if (reader != null) {
break;
}
}
if (reader != null) {
List<GeocodingResult> justified = su.justifyReverseGeocodingSearch(r, reader, minBuildingDistance, null);
if (!justified.isEmpty()) {
double md = justified.get(0).getDistance();
if (minBuildingDistance == 0) {
minBuildingDistance = md;
} else {
minBuildingDistance = Math.min(md, minBuildingDistance);
}
complete.addAll(justified);
}
} else {
complete.add(r);
}
}
return minBuildingDistance;
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion in project OsmAnd-tools by osmandapp.
the class ObfDiffGenerator method compareRouteData.
private void compareRouteData(ObfFileInMemory fStart, ObfFileInMemory fEnd, boolean print, Set<EntityId> modifiedObjIds) {
RouteRegion ri = fEnd.getRouteIndex();
int deleteId = ri.searchRouteEncodingRule(OSMAND_CHANGE_TAG, OSMAND_CHANGE_VALUE);
if (deleteId == -1) {
deleteId = ri.routeEncodingRules.size();
if (deleteId == 0) {
deleteId = 1;
}
ri.initRouteEncodingRule(deleteId, OSMAND_CHANGE_TAG, OSMAND_CHANGE_VALUE);
}
TLongObjectHashMap<RouteDataObject> startData = fStart.getRoutingData();
TLongObjectHashMap<RouteDataObject> endData = fEnd.getRoutingData();
if (endData == null) {
return;
}
for (Long idx : startData.keys()) {
RouteDataObject objE = endData.get(idx);
RouteDataObject objS = startData.get(idx);
if (print) {
if (objE == null) {
System.out.println("Route " + idx + " is missing in (2): " + objS);
} else {
if (!objE.compareRoute(objS)) {
System.out.println("Route " + idx + " is not equal: " + objS + " != " + objE);
}
endData.remove(idx);
}
} else {
if (objE == null) {
EntityId wayId = new EntityId(EntityType.WAY, idx >> (BinaryInspector.SHIFT_ID));
if (modifiedObjIds == null || modifiedObjIds.contains(wayId)) {
RouteDataObject rdo = generateDeletedRouteObject(ri, deleteId, objS);
endData.put(idx, rdo);
}
} else if (objE.compareRoute(objS)) {
endData.remove(idx);
}
}
}
if (print) {
for (RouteDataObject e : endData.valueCollection()) {
System.out.println("Route " + e.getId() + " is missing in (1): " + e);
}
}
}
Aggregations