use of net.osmand.map.OsmandRegions in project OsmAnd-tools by osmandapp.
the class CalculateCountryForChangesets method calculateCountries.
private static void calculateCountries() throws Exception {
// jdbc:postgresql://user:secret@localhost
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5433/changeset", System.getenv("DB_USER"), System.getenv("DB_PWD"));
try {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT COUNT(*) FROM countries");
boolean empty = !rs.next() || rs.getInt(1) == 0;
rs.close();
Map<WorldRegion, Integer> map = new LinkedHashMap<WorldRegion, Integer>();
OsmandRegions or = initCountriesTable(conn, empty, map);
PreparedStatement ps = conn.prepareStatement("INSERT INTO changeset_country(changesetid, countryid, small)" + " VALUES(?, ?, ?)");
rs = stat.executeQuery("select id, minlat, minlon, maxlat, maxlon from changesets C " + " where (maxlat <> 0 or minlat <> 0 or maxlon <> 0 or minlon <> 0) and " + "not exists (select 1 from changeset_country CC where CC.changesetid=C.id) limit " + FETCH_LIMIT);
int batch = 0;
int batchInd = 1;
while (rs.next()) {
double minlat = rs.getDouble(2);
double minlon = rs.getDouble(3);
double maxlat = rs.getDouble(4);
double maxlon = rs.getDouble(5);
String changesetId = rs.getString(1);
int lx = MapUtils.get31TileNumberX(minlon);
int rx = MapUtils.get31TileNumberX(maxlon);
int ty = MapUtils.get31TileNumberY(maxlat);
int by = MapUtils.get31TileNumberY(minlat);
List<BinaryMapDataObject> objs = or.queryBbox(lx, rx, ty, by);
int cid = 0;
for (BinaryMapDataObject o : objs) {
if (!or.intersect(o, lx, ty, rx, by)) {
continue;
}
String full = or.getFullName(o);
WorldRegion reg = or.getRegionData(full);
if (reg.isRegionMapDownload() && !full.toLowerCase().startsWith("world_")) {
cid++;
if (cid > MAX_COUNTRY_SIZE) {
continue;
}
// System.out.println(changesetId + " " + full + " " + reg.getLocaleName() + " " + map.get(reg));
if (map.get(reg) == null) {
throw new UnsupportedOperationException("Not found " + changesetId + " " + full);
}
boolean small = true;
List<WorldRegion> subs = reg.getSubregions();
if (subs != null) {
for (WorldRegion sub : subs) {
if (sub.isRegionMapDownload()) {
small = false;
break;
}
}
}
ps.setString(1, changesetId);
ps.setInt(2, map.get(reg));
ps.setInt(3, small ? 1 : 0);
ps.addBatch();
}
}
if (batch++ > BATCH_SIZE) {
System.out.println("Execute batch " + (batchInd++) + " by " + BATCH_SIZE);
ps.executeBatch();
batch = 0;
}
}
ps.executeBatch();
} finally {
conn.close();
}
}
use of net.osmand.map.OsmandRegions in project OsmAnd-tools by osmandapp.
the class AugmentedDiffsInspector method main.
public static void main(String[] args) {
try {
File inputFile = new File(args[0]);
File targetDir = new File(args[1]);
File ocbfFile = args.length <= 2 ? null : new File(args[2]);
AugmentedDiffsInspector inspector = new AugmentedDiffsInspector();
Context ctx = inspector.parseFile(inputFile);
OsmandRegions osmandRegions = null;
if (ocbfFile != null) {
osmandRegions = new OsmandRegions();
osmandRegions.prepareFile(ocbfFile.getAbsolutePath());
osmandRegions.cacheAllCountries();
}
inspector.prepareRegions(ctx, ctx.newIds, ctx.regionsNew, osmandRegions);
inspector.prepareRegions(ctx, ctx.oldIds, ctx.regionsOld, osmandRegions);
String name = inputFile.getName();
String date = name.substring(0, name.indexOf('-'));
String time = name.substring(name.indexOf('-') + 1, name.indexOf('.'));
inspector.write(ctx, targetDir, date, time, inputFile.lastModified());
} catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}
}
use of net.osmand.map.OsmandRegions in project OsmAnd-tools by osmandapp.
the class ObfRegionSplitter method split.
private void split(String[] args) throws IOException {
File worldObf = new File(args[0]);
File ocbfFile = new File(args[2]);
File dir = new File(args[1]);
String subFolder = args.length > 3 ? args[3] : "";
String fileSuffix = args.length > 4 ? args[4] : "";
if (!worldObf.exists() || !ocbfFile.exists()) {
System.out.println("Incorrect file!");
System.exit(1);
}
if (!dir.exists()) {
dir.mkdir();
}
try {
ObfFileInMemory fl = new ObfFileInMemory();
fl.readObfFiles(Collections.singletonList(worldObf));
OsmandRegions osmandRegions = new OsmandRegions();
osmandRegions.prepareFile(ocbfFile.getAbsolutePath());
osmandRegions.cacheAllCountries();
Map<String, Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>>> regionsMapData = splitRegionMapData(fl, osmandRegions);
Map<String, TLongObjectHashMap<RouteDataObject>> regionsRouteData = splitRegionRouteData(fl, osmandRegions);
Map<String, TLongObjectHashMap<Map<String, Amenity>>> regionsPoiData = splitRegionPoiData(fl, osmandRegions);
TreeSet<String> regionNames = new TreeSet<>();
regionNames.addAll(regionsMapData.keySet());
regionNames.addAll(regionsRouteData.keySet());
for (String regionName : regionNames) {
File folder = new File(dir, regionName);
if (!Algorithms.isEmpty(subFolder)) {
folder = new File(folder, subFolder);
}
folder.mkdirs();
File result = new File(folder, Algorithms.capitalizeFirstLetter(regionName) + fileSuffix + ".obf.gz");
ObfFileInMemory obf = new ObfFileInMemory();
Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>> mp = regionsMapData.get(regionName);
if (mp != null) {
for (MapZoomPair mzPair : mp.keySet()) {
obf.putMapObjects(mzPair, mp.get(mzPair).valueCollection(), true);
}
}
TLongObjectHashMap<RouteDataObject> ro = regionsRouteData.get(regionName);
if (ro != null) {
obf.putRoutingData(ro, true);
}
TLongObjectHashMap<Map<String, Amenity>> poi = regionsPoiData.get(regionName);
if (poi != null) {
obf.putPoiData(poi, true);
}
// TODO split Transport
obf.updateTimestamp(fl.getTimestamp());
obf.writeFile(result, true);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
use of net.osmand.map.OsmandRegions in project OsmAnd-tools by osmandapp.
the class GenerateRegionTags method main.
public static void main(String[] args) {
try {
if (args.length == 0) {
args = new String[] { "/Users/victorshcherb/osmand/temp/proc_line_motorway_out.osm.bz2", "/Users/victorshcherb/osmand/temp/region_proc_line_motorway_out.osm.bz2", "/Users/victorshcherb/osmand/repos/resources/countries-info/regions.ocbf" };
}
File inputFile = new File(args[0]);
File targetFile = new File(args[1]);
File ocbfFile = new File(args[2]);
OsmandRegions or = new OsmandRegions();
or.prepareFile(ocbfFile.getAbsolutePath());
or.cacheAllCountries();
process(inputFile, targetFile, or);
} catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}
}
use of net.osmand.map.OsmandRegions in project Osmand by osmandapp.
the class DownloadResources method prepareData.
protected boolean prepareData(List<IndexItem> resources) {
this.rawResources = resources;
DownloadResourceGroup otherMapsGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.OTHER_MAPS_GROUP);
DownloadResourceGroup otherMapsScreen = new DownloadResourceGroup(otherMapsGroup, DownloadResourceGroupType.OTHER_MAPS);
DownloadResourceGroup otherMaps = new DownloadResourceGroup(otherMapsGroup, DownloadResourceGroupType.OTHER_MAPS_HEADER);
otherMapsScreen.addGroup(otherMaps);
otherMapsGroup.addGroup(otherMapsScreen);
DownloadResourceGroup otherGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.OTHER_GROUP);
DownloadResourceGroup voiceScreenTTS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_TTS);
DownloadResourceGroup voiceScreenRec = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_REC);
DownloadResourceGroup fontScreen = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.FONTS);
DownloadResourceGroup voiceTTS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_TTS);
DownloadResourceGroup voiceRec = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_REC);
DownloadResourceGroup fonts = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.FONTS_HEADER);
DownloadResourceGroup worldMaps = new DownloadResourceGroup(this, DownloadResourceGroupType.WORLD_MAPS);
DownloadResourceGroup nauticalMapsGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.NAUTICAL_MAPS_GROUP);
DownloadResourceGroup nauticalMapsScreen = new DownloadResourceGroup(nauticalMapsGroup, DownloadResourceGroupType.NAUTICAL_MAPS);
DownloadResourceGroup nauticalMaps = new DownloadResourceGroup(nauticalMapsGroup, DownloadResourceGroupType.NAUTICAL_MAPS_HEADER);
Map<WorldRegion, List<IndexItem>> groupByRegion = new LinkedHashMap<WorldRegion, List<IndexItem>>();
OsmandRegions regs = app.getRegions();
for (IndexItem ii : resources) {
if (ii.getType() == DownloadActivityType.VOICE_FILE) {
if (ii.getFileName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
voiceTTS.addItem(ii);
} else {
voiceRec.addItem(ii);
}
continue;
}
if (ii.getType() == DownloadActivityType.FONT_FILE) {
fonts.addItem(ii);
continue;
}
if (ii.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE) {
if (app.getSettings().DEPTH_CONTOURS_PURCHASED.get() || nauticalMaps.size() == 0) {
nauticalMaps.addItem(ii);
}
continue;
}
String basename = ii.getBasename().toLowerCase();
WorldRegion wg = regs.getRegionDataByDownloadName(basename);
if (wg != null) {
if (!groupByRegion.containsKey(wg)) {
groupByRegion.put(wg, new ArrayList<IndexItem>());
}
groupByRegion.get(wg).add(ii);
} else {
if (ii.getFileName().startsWith("World_")) {
if (ii.getFileName().toLowerCase().startsWith(WORLD_SEAMARKS_KEY) || ii.getFileName().toLowerCase().startsWith(WORLD_SEAMARKS_OLD_KEY)) {
nauticalMaps.addItem(ii);
} else {
worldMaps.addItem(ii);
}
} else {
otherMaps.addItem(ii);
}
}
}
this.groupByRegion = groupByRegion;
LinkedList<WorldRegion> queue = new LinkedList<WorldRegion>();
LinkedList<DownloadResourceGroup> parent = new LinkedList<DownloadResourceGroup>();
DownloadResourceGroup worldSubregions = new DownloadResourceGroup(this, DownloadResourceGroupType.SUBREGIONS);
addGroup(worldSubregions);
for (WorldRegion rg : region.getSubregions()) {
queue.add(rg);
parent.add(worldSubregions);
}
while (!queue.isEmpty()) {
WorldRegion reg = queue.pollFirst();
DownloadResourceGroup parentGroup = parent.pollFirst();
List<WorldRegion> subregions = reg.getSubregions();
DownloadResourceGroup mainGrp = new DownloadResourceGroup(parentGroup, DownloadResourceGroupType.REGION, reg.getRegionId());
mainGrp.region = reg;
parentGroup.addGroup(mainGrp);
List<IndexItem> list = groupByRegion.get(reg);
if (list != null) {
DownloadResourceGroup flatFiles = new DownloadResourceGroup(mainGrp, DownloadResourceGroupType.REGION_MAPS);
for (IndexItem ii : list) {
flatFiles.addItem(ii);
}
mainGrp.addGroup(flatFiles);
}
DownloadResourceGroup subRegions = new DownloadResourceGroup(mainGrp, DownloadResourceGroupType.SUBREGIONS);
mainGrp.addGroup(subRegions);
// add to processing queue
for (WorldRegion rg : subregions) {
queue.add(rg);
parent.add(subRegions);
}
}
// Possible improvements
// 1. if there is no subregions no need to create resource group REGIONS_MAPS - objection raise diversity and there is no value
// 2. if there is no subregions and there only 1 index item it could be merged to the level up - objection there is no such maps
// 3. if hillshade/srtm is disabled, all maps from inner level could be combined into 1
addGroup(worldMaps);
nauticalMapsScreen.addGroup(nauticalMaps);
nauticalMapsGroup.addGroup(nauticalMapsScreen);
addGroup(nauticalMapsGroup);
if (otherMaps.size() > 0) {
addGroup(otherMapsGroup);
}
voiceScreenTTS.addGroup(voiceTTS);
voiceScreenRec.addGroup(voiceRec);
if (fonts.getIndividualResources() != null) {
fontScreen.addGroup(fonts);
}
otherGroup.addGroup(voiceScreenTTS);
otherGroup.addGroup(voiceScreenRec);
if (fonts.getIndividualResources() != null) {
otherGroup.addGroup(fontScreen);
}
addGroup(otherGroup);
createHillshadeSRTMGroups();
trimEmptyGroups();
updateLoadedFiles();
return true;
}
Aggregations