use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.
the class CountryOcbfGeneration method createFile.
private void createFile(CountryRegion global, Map<String, Set<TranslateEntity>> translates, Map<String, File> polygonFiles, String targetObf, String targetOsmXml) throws IOException, SQLException, InterruptedException, XmlPullParserException {
File osm = new File(targetOsmXml);
XmlSerializer serializer = new org.kxml2.io.KXmlSerializer();
FileOutputStream fous = new FileOutputStream(osm);
serializer.setOutput(fous, "UTF-8");
serializer.startDocument("UTF-8", true);
serializer.startTag(null, "osm");
serializer.attribute(null, "version", "0.6");
serializer.attribute(null, "generator", "OsmAnd");
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
for (CountryRegion r : global.children) {
r.parent = null;
processRegion(r, translates, polygonFiles, targetObf, targetOsmXml, "", serializer);
}
serializer.endDocument();
serializer.flush();
fous.close();
// $NON-NLS-1$
IndexCreator creator = new IndexCreator(new File(targetObf).getParentFile());
creator.setMapFileName(new File(targetObf).getName());
creator.setIndexMap(true);
creator.setIndexAddress(false);
creator.setIndexPOI(false);
creator.setIndexTransport(false);
creator.setIndexRouting(false);
MapZooms zooms = MapZooms.parseZooms("5-6");
creator.generateIndexes(osm, new ConsoleProgressImplementation(1), null, zooms, new MapRenderingTypesEncoder("regions"), log);
}
use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.
the class FixAdminLevel0 method process.
private static void process(File read, File write) throws IOException, XMLStreamException, XmlPullParserException {
OsmBaseStorage storage = new OsmBaseStorage();
storage.parseOSM(new FileInputStream(read), new ConsoleProgressImplementation());
Map<EntityId, Entity> entities = new HashMap<EntityId, Entity>(storage.getRegisteredEntities());
long id = -1;
for (EntityId e : entities.keySet()) {
Entity es = storage.getRegisteredEntities().get(e);
if (e.getId() < id) {
id = e.getId() - 1;
}
if (e.getType() == EntityType.WAY) {
processWay((Way) es);
}
}
for (String country : countryNames.keySet()) {
List<Way> list = countryNames.get(country);
for (Way w : list) {
LatLon latLon = OsmMapUtils.getMathWeightCenterForNodes(w.getNodes());
// LatLon latLon = w.getLatLon();
Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), id--);
node.putTag("name", country);
node.putTag("place", "country");
storage.getRegisteredEntities().put(EntityId.valueOf(node), node);
}
}
OsmStorageWriter writer = new OsmStorageWriter();
writer.saveStorage(new FileOutputStream(write), storage, null, true);
}
use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.
the class GenerateDailyObf method generateCountry.
public static void generateCountry(String name, File targetObfZip, File[] array, long targetTimestamp, File nodesFile) throws IOException, SQLException, InterruptedException, XmlPullParserException {
boolean exception = true;
try {
RTree.clearCache();
IndexCreator ic = new IndexCreator(targetObfZip.getParentFile());
ic.setIndexAddress(false);
ic.setIndexPOI(true);
ic.setIndexRouting(true);
ic.setIndexMap(true);
ic.setLastModifiedDate(targetTimestamp);
ic.setGenerateLowLevelIndexes(false);
ic.setDialects(DBDialect.SQLITE, DBDialect.SQLITE_IN_MEMORY);
ic.setLastModifiedDate(targetTimestamp);
ic.setRegionName(Algorithms.capitalizeFirstLetterAndLowercase(name));
ic.setNodesDBFile(nodesFile);
ic.setDeleteOsmDB(false);
ic.generateIndexes(array, new ConsoleProgressImplementation(), null, MapZooms.parseZooms("13-14;15-"), new MapRenderingTypesEncoder(name), log, false, true);
File targetFile = new File(targetObfZip.getParentFile(), ic.getMapFileName());
targetFile.setLastModified(targetTimestamp);
FileInputStream fis = new FileInputStream(targetFile);
GZIPOutputStream gzout = new GZIPOutputStream(new FileOutputStream(targetObfZip));
Algorithms.streamCopy(fis, gzout);
fis.close();
gzout.close();
targetObfZip.setLastModified(targetTimestamp);
targetFile.delete();
exception = false;
} finally {
if (exception) {
nodesFile.delete();
nodesFile.deleteOnExit();
}
}
}
use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.
the class MainUtilities method generateObf.
private static void generateObf(String[] subArgsArray, IndexCreator ic) throws IOException, SQLException, InterruptedException, XmlPullParserException {
String fn = DataExtractionSettings.getSettings().getMapRenderingTypesFile();
String regionName = subArgsArray[0];
MapRenderingTypesEncoder types = new MapRenderingTypesEncoder(fn, regionName);
ic.generateIndexes(new File(subArgsArray[0]), new ConsoleProgressImplementation(), null, MapZooms.getDefault(), types, log);
}
use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.
the class GenerateRegionTags method process.
private static void process(File inputFile, File targetFile, OsmandRegions or) throws IOException, XmlPullParserException, XMLStreamException {
InputStream fis = new FileInputStream(inputFile);
if (inputFile.getName().endsWith(".gz")) {
fis = new GZIPInputStream(fis);
} else if (inputFile.getName().endsWith(".bz2")) {
if (fis.read() != 'B' || fis.read() != 'Z') {
throw new RuntimeException(// $NON-NLS-1$
"The source stream must start with the characters BZ if it is to be read as a BZip2 stream.");
}
fis = new CBZip2InputStream(fis);
}
OsmBaseStorage bs = new OsmBaseStorage();
bs.parseOSM(fis, new ConsoleProgressImplementation());
LOG.info("File was read");
iterateOverEntities(bs.getRegisteredEntities(), or);
OsmStorageWriter w = new OsmStorageWriter();
OutputStream output = new FileOutputStream(targetFile);
if (targetFile.getName().endsWith(".gz")) {
output = new GZIPOutputStream(output);
} else if (targetFile.getName().endsWith(".bz2")) {
output.write("BZ".getBytes());
output = new CBZip2OutputStream(output);
}
LOG.info("Entities processed. About to save the file.");
w.saveStorage(output, bs, null, true);
output.close();
fis.close();
}
Aggregations