use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class OsmandRegions method getCountryName.
public String getCountryName(LatLon ll) {
double lat = ll.getLatitude();
double lon = ll.getLongitude();
int y = MapUtils.get31TileNumberY(lat);
int x = MapUtils.get31TileNumberX(lon);
try {
List<BinaryMapDataObject> list = query(x, y);
for (BinaryMapDataObject o : list) {
if (contain(o, x, y)) {
String name = mapIndexFields.get(mapIndexFields.nameType, o);
if (name != null) {
return name;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.
the class OsmandRegions method getCountries.
private List<BinaryMapDataObject> getCountries(int tile31x, int tile31y) {
HashSet<String> set = new HashSet<String>(quadTree.queryInBox(new QuadRect(tile31x, tile31y, tile31x, tile31y), new ArrayList<String>()));
List<BinaryMapDataObject> result = new ArrayList<BinaryMapDataObject>();
Iterator<String> it = set.iterator();
while (it.hasNext()) {
String cname = it.next();
BinaryMapDataObject container = null;
int count = 0;
for (BinaryMapDataObject bo : countriesByDownloadName.get(cname)) {
if (contain(bo, tile31x, tile31y)) {
count++;
container = bo;
break;
}
}
if (count % 2 == 1) {
result.add(container);
}
}
return result;
}
use of net.osmand.binary.BinaryMapDataObject in project OsmAnd-tools by osmandapp.
the class FixBasemapRoads method addRegionTag.
private void addRegionTag(OsmandRegions or, Way firstWay) throws IOException {
QuadRect qr = firstWay.getLatLonBBox();
int lx = MapUtils.get31TileNumberX(qr.left);
int rx = MapUtils.get31TileNumberX(qr.right);
int by = MapUtils.get31TileNumberY(qr.bottom);
int ty = MapUtils.get31TileNumberY(qr.top);
List<BinaryMapDataObject> bbox = or.queryBbox(lx, rx, ty, by);
TreeSet<String> lst = new TreeSet<String>();
for (BinaryMapDataObject bo : bbox) {
// }
if (or.contain(bo, lx / 2 + rx / 2, by / 2 + ty / 2)) {
String dw = or.getDownloadName(bo);
if (!Algorithms.isEmpty(dw) && or.isDownloadOfType(bo, OsmandRegions.MAP_TYPE)) {
lst.add(dw);
}
}
}
firstWay.putTag(MapRenderingTypesEncoder.OSMAND_REGION_NAME_TAG, serialize(lst));
}
use of net.osmand.binary.BinaryMapDataObject 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);
}
}
use of net.osmand.binary.BinaryMapDataObject in project OsmAnd-tools by osmandapp.
the class CombineSRTMIntoFile method process.
private static void process(BinaryMapDataObject country, List<BinaryMapDataObject> boundaries, String downloadName, File directoryWithSRTMFiles, File directoryWithTargetFiles, boolean dryRun) throws IOException, SQLException, InterruptedException, IllegalArgumentException, XmlPullParserException {
final String suffix = "_" + IndexConstants.BINARY_MAP_VERSION + IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
String name = country.getName();
final File targetFile = new File(directoryWithTargetFiles, Algorithms.capitalizeFirstLetterAndLowercase(downloadName + suffix));
if (targetFile.exists()) {
System.out.println("Already processed " + name);
return;
}
Set<String> srtmFileNames = new TreeSet<String>();
QuadRect qr = new QuadRect(180, -90, -180, 90);
MultipolygonBuilder bld = new MultipolygonBuilder();
bld.addOuterWay(convertToWay(country));
updateBbox(country, qr);
if (boundaries != null) {
for (BinaryMapDataObject o : boundaries) {
bld.addOuterWay(convertToWay(o));
updateBbox(o, qr);
}
}
Multipolygon polygon = bld.build();
System.out.println("RINGS OF MULTIPOLYGON ARE " + polygon.areRingsComplete());
int rightLon = (int) Math.floor(qr.right);
int leftLon = (int) Math.floor(qr.left);
int bottomLat = (int) Math.floor(qr.bottom);
int topLat = (int) Math.floor(qr.top);
boolean onetile = leftLon == rightLon && bottomLat == topLat;
for (int lon = leftLon; lon <= rightLon; lon++) {
for (int lat = bottomLat; lat <= topLat; lat++) {
boolean isOut = !polygon.containsPoint(lat + 0.5, lon + 0.5) && !onetile;
if (isOut) {
LatLon bl = new LatLon(lat, lon);
LatLon br = new LatLon(lat, lon + 1);
LatLon tr = new LatLon(lat + 1, lon + 1);
LatLon tl = new LatLon(lat + 1, lon);
for (Ring r : polygon.getOuterRings()) {
List<Node> border = r.getBorder();
Node prev = border.get(border.size() - 1);
for (int i = 0; i < border.size() && isOut; i++) {
Node n = border.get(i);
if (MapAlgorithms.linesIntersect(prev.getLatLon(), n.getLatLon(), tr, tl)) {
isOut = false;
} else if (MapAlgorithms.linesIntersect(prev.getLatLon(), n.getLatLon(), tr, br)) {
isOut = false;
} else if (MapAlgorithms.linesIntersect(prev.getLatLon(), n.getLatLon(), bl, tl)) {
isOut = false;
} else if (MapAlgorithms.linesIntersect(prev.getLatLon(), n.getLatLon(), br, bl)) {
isOut = false;
}
prev = n;
}
if (!isOut) {
break;
}
}
}
if (!isOut) {
final String filename = getFileName(lon, lat);
srtmFileNames.add(filename);
}
}
}
System.out.println();
System.out.println("PROCESSING " + name + " lon [" + leftLon + " - " + rightLon + "] lat [" + bottomLat + " - " + topLat + "] TOTAL " + srtmFileNames.size() + " files " + srtmFileNames);
System.out.println("-----------------------------");
if (dryRun) {
return;
}
// final File work = new File(directoryWithTargetFiles, "work");
// Map<File, String> mp = new HashMap<File, String>();
// long length = 0;
List<File> files = new ArrayList<File>();
for (String file : srtmFileNames) {
final File fl = new File(directoryWithSRTMFiles, file + ".osm.bz2");
if (!fl.exists()) {
System.err.println("!! Missing " + name + " because " + file + " doesn't exist");
} else {
files.add(fl);
// File ttf = new File(fl.getParentFile(), Algorithms.capitalizeFirstLetterAndLowercase(file) + "_"+ name + ".obf");
// mp.put(ttf, null);
}
}
// be independent of previous results
new File(targetFile.getParentFile(), IndexCreator.TEMP_NODES_DB).delete();
RTree.clearCache();
IndexCreator ic = new IndexCreator(targetFile.getParentFile());
if (srtmFileNames.size() > 100) {
ic.setDialects(DBDialect.SQLITE, DBDialect.SQLITE);
} else {
ic.setDialects(DBDialect.SQLITE_IN_MEMORY, DBDialect.SQLITE_IN_MEMORY);
}
ic.setIndexMap(true);
ic.setRegionName(name + " contour lines");
ic.setMapFileName(targetFile.getName());
ic.setBoundary(polygon);
ic.setZoomWaySmoothness(2);
ic.generateIndexes(files.toArray(new File[files.size()]), new ConsoleProgressImplementation(1), null, MapZooms.parseZooms("11-12;13-"), new MapRenderingTypesEncoder(targetFile.getName()), log, true, false);
// if(length > Integer.MAX_VALUE) {
// System.err.println("!! Can't process " + name + " because too big");
// } else {
// BinaryInspector.combineParts(targetFile, mp);
// }
// for(String file : srtmFileNames) {
// final File fl = new File(work, file);
// fl.delete();
// }
}
Aggregations