use of net.osmand.binary.BinaryMapIndexReader in project OsmAnd-tools by osmandapp.
the class IndexUploader method checkfileAndGetDescription.
private String checkfileAndGetDescription(File mainFile) throws OneFileException, IOException, RTreeException {
String fileName = mainFile.getName();
boolean srtmFile = mainFile.getName().contains(".srtm");
boolean roadFile = mainFile.getName().contains(".road");
boolean wikiFile = mainFile.getName().contains(".wiki");
boolean tourFile = fileName.endsWith(IndexConstants.TOUR_INDEX_EXT) || fileName.endsWith(IndexConstants.TOUR_INDEX_EXT_ZIP);
boolean worldFile = fileName.toLowerCase().contains("basemap") || fileName.toLowerCase().contains("world");
boolean regionFile = !srtmFile && !roadFile && !wikiFile && !tourFile && !worldFile;
if (srtmFile != this.srtmProcess) {
return null;
}
if (tourFile != this.tourProcess) {
return null;
}
if (roadFile != this.roadProcess) {
return null;
}
if (wikiFile != this.wikiProcess) {
return null;
}
if (regionFile) {
extractRoadOnlyFile(mainFile, new File(mainFile.getParentFile(), fileName.replace(IndexConstants.BINARY_MAP_INDEX_EXT, IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)));
}
if (tourFile) {
File fl = new File(mainFile, "inventory.xml");
if (!fl.exists()) {
System.err.println("inventory.xml doesn't exist " + fl.getAbsolutePath());
return null;
}
try {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(fl);
return ((Element) doc.getElementsByTagName("shortDescription").item(0)).getTextContent();
} catch (Exception e) {
throw new OneFileException("Not supported file format " + fileName, e);
}
} else if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) || fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(mainFile, "r");
BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, mainFile);
if (reader.getVersion() != IndexConstants.BINARY_MAP_VERSION) {
throw new OneFileException("Uploader version is not compatible " + reader.getVersion() + " to current " + IndexConstants.BINARY_MAP_VERSION);
}
String summary = getDescription(reader, fileName);
reader.close();
mainFile.setLastModified(reader.getDateCreated());
return summary;
} catch (IOException e) {
if (raf != null) {
try {
raf.close();
} catch (IOException e1) {
}
}
throw new OneFileException("Reader could not read the index: " + e.getMessage());
}
} else {
throw new OneFileException("Not supported file format " + fileName);
}
}
use of net.osmand.binary.BinaryMapIndexReader in project OsmAnd-tools by osmandapp.
the class ManyToOneRoadCalculation method main.
public static void main(String[] args) throws IOException, InterruptedException {
File fl = new File("/home/victor/projects/osmand/osm-gen/Netherlands_europe_2.obf");
// $NON-NLS-1$ //$NON-NLS-2$
RandomAccessFile raf = new RandomAccessFile(fl, "r");
BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, fl);
int zoom = 9;
double top = 53.2949;
double bottom = MapUtils.getLatitudeFromTile(zoom, (MapUtils.getTileNumberY(zoom, top) + 1));
System.out.println(top + " - " + bottom);
new ManyToOneRoadCalculation().manyToManyCalculation(reader, top, bottom);
}
use of net.osmand.binary.BinaryMapIndexReader in project OsmAnd-tools by osmandapp.
the class NativeSwingRendering method updateBoundaries.
private void updateBoundaries(File f, String nm) {
try {
BinaryMapIndexReader r = new BinaryMapIndexReader(new RandomAccessFile(f, "r"), f);
try {
if (r.getMapIndexes().isEmpty() || r.getMapIndexes().get(0).getRoots().isEmpty()) {
return;
}
MapRoot rt = r.getMapIndexes().get(0).getRoots().get(0);
if (!diffs.containsKey(nm)) {
MapDiff mm = new MapDiff();
mm.baseName = nm;
diffs.put(nm, mm);
}
MapDiff dd = diffs.get(nm);
dd.baseFile = f;
dd.timestamp = r.getDateCreated();
dd.bounds = new QuadRect(MapUtils.get31LongitudeX(rt.getLeft()), MapUtils.get31LatitudeY(rt.getTop()), MapUtils.get31LongitudeX(rt.getRight()), MapUtils.get31LatitudeY(rt.getBottom()));
Iterator<String> iterator = dd.diffs.keySet().iterator();
while (iterator.hasNext()) {
dd.selected = iterator.next();
}
} finally {
r.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of net.osmand.binary.BinaryMapIndexReader in project OsmAnd-tools by osmandapp.
the class MapClusterLayer method clustering.
private List<RouteSegment> clustering(final ClusteringContext clusterCtx, double lat, double lon, final DataTileManager<Way> points) throws IOException {
List<BinaryMapIndexReader> rs = new ArrayList<BinaryMapIndexReader>();
for (File f : new File(DataExtractionSettings.getSettings().getBinaryFilesDir()).listFiles()) {
if (f.getName().endsWith(".obf")) {
// $NON-NLS-1$ //$NON-NLS-2$
RandomAccessFile raf = new RandomAccessFile(f, "r");
rs.add(new BinaryMapIndexReader(raf, f));
}
}
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(true);
Builder builder = RoutingConfiguration.getDefault();
RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
RoutingContext ctx = router.buildRoutingContext(config, NativeSwingRendering.getDefaultFromSettings(), rs.toArray(new BinaryMapIndexReader[rs.size()]), clusterCtx.BASEMAP_CLUSTERING ? RouteCalculationMode.BASE : RouteCalculationMode.NORMAL);
// find closest way
RouteSegment st = router.findRouteSegment(lat, lon, ctx, null);
if (st != null) {
RouteDataObject road = st.getRoad();
String highway = getHighway(road);
log.info(// road.getName() + " "
"ROAD TO START " + highway + " " + +road.id);
}
map.setPoints(points);
ctx.setVisitor(new RouteSegmentVisitor() {
private List<RouteSegment> cache = new ArrayList<RouteSegment>();
@Override
public void visitSegment(RouteSegment s, int endSegment, boolean poll) {
if (!clusterCtx.ANIMATE_CLUSTERING) {
return;
}
cache.add(s);
if (cache.size() < SIZE_OF_ROUTES_TO_ANIMATE) {
return;
}
for (RouteSegment segment : cache) {
Way way = new Way(-1);
for (int i = 0; i < segment.getRoad().getPointsLength(); i++) {
net.osmand.osm.edit.Node n = new net.osmand.osm.edit.Node(MapUtils.get31LatitudeY(segment.getRoad().getPoint31YTile(i)), MapUtils.get31LongitudeX(segment.getRoad().getPoint31XTile(i)), -1);
way.addNode(n);
}
way.putTag("color", "white");
LatLon n = way.getLatLon();
points.registerObject(n.getLatitude(), n.getLongitude(), way);
}
cache.clear();
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
map.prepareImage();
}
});
} catch (InterruptedException e1) {
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
});
List<RouteSegment> results = searchCluster(clusterCtx, ctx, st);
return results;
}
use of net.osmand.binary.BinaryMapIndexReader in project OsmAnd-tools by osmandapp.
the class CombineSRTMIntoFile method main.
public static void main(String[] args) throws IOException {
File directoryWithSRTMFiles = new File(args[0]);
File directoryWithTargetFiles = new File(args[1]);
String ocbfFile = args[2];
boolean dryRun = true;
// mauritius
String filter = null;
for (int i = 3; i < args.length; i++) {
if ("--dry-run".equals(args[i])) {
dryRun = true;
} else if (args[i].startsWith("--filter")) {
filter = args[i].substring("--filter".length());
}
}
OsmandRegions or = new OsmandRegions();
BinaryMapIndexReader fl = or.prepareFile(ocbfFile);
Map<String, LinkedList<BinaryMapDataObject>> allCountries = or.cacheAllCountries();
MapIndex mapIndex = fl.getMapIndexes().get(0);
int srtm = mapIndex.getRule("region_srtm", "yes");
int downloadName = mapIndex.getRule("download_name", null);
int boundary = mapIndex.getRule("osmand_region", "boundary");
int cnt = 1;
Set<String> failedCountries = new HashSet<String>();
for (String fullName : allCountries.keySet()) {
LinkedList<BinaryMapDataObject> lst = allCountries.get(fullName);
if (fullName == null || (filter != null && !fullName.contains(filter))) {
continue;
}
BinaryMapDataObject rc = null;
for (BinaryMapDataObject r : lst) {
if (!r.containsType(boundary)) {
rc = r;
break;
}
}
System.out.println(fullName);
if (rc != null && rc.containsAdditionalType(srtm)) {
String dw = rc.getNameByType(downloadName);
System.out.println("Region " + fullName + " " + cnt++ + " out of " + lst.size());
try {
process(rc, lst.subList(1, lst.size()), dw, directoryWithSRTMFiles, directoryWithTargetFiles, dryRun);
} catch (Exception e) {
failedCountries.add(fullName);
e.printStackTrace();
}
}
}
if (!failedCountries.isEmpty()) {
throw new IllegalStateException("Failed countries " + failedCountries);
}
}
Aggregations