use of net.osmand.osm.MapRenderingTypesEncoder 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.osm.MapRenderingTypesEncoder 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.osm.MapRenderingTypesEncoder in project OsmAnd-tools by osmandapp.
the class ObfFileInMemory method writeFile.
public void writeFile(File targetFile, boolean doNotSimplifyObjects) throws IOException, RTreeException, SQLException {
boolean gzip = targetFile.getName().endsWith(".gz");
File nonGzip = targetFile;
if (gzip) {
nonGzip = new File(targetFile.getParentFile(), targetFile.getName().substring(0, targetFile.getName().length() - 3));
}
final RandomAccessFile raf = new RandomAccessFile(nonGzip, "rw");
// write files
CodedOutputStream ous = CodedOutputStream.newInstance(new OutputStream() {
@Override
public void write(int b) throws IOException {
raf.write(b);
}
@Override
public void write(byte[] b) throws IOException {
raf.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
raf.write(b, off, len);
}
});
timestamp = timestamp == 0 ? System.currentTimeMillis() : timestamp;
int version = IndexConstants.BINARY_MAP_VERSION;
ous.writeInt32(OsmandOdb.OsmAndStructure.VERSION_FIELD_NUMBER, version);
ous.writeInt64(OsmandOdb.OsmAndStructure.DATECREATED_FIELD_NUMBER, timestamp);
BinaryMapIndexWriter writer = new BinaryMapIndexWriter(raf, ous);
String defName = targetFile.getName().substring(0, targetFile.getName().indexOf('.'));
if (mapObjects.size() > 0) {
String name = mapIndex.getName();
if (Algorithms.isEmpty(name)) {
name = defName;
}
writer.startWriteMapIndex(Algorithms.capitalizeFirstLetter(name));
writer.writeMapEncodingRules(mapIndex.decodingRules);
Iterator<Entry<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>>> it = mapObjects.entrySet().iterator();
while (it.hasNext()) {
Entry<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>> n = it.next();
writeMapData(writer, n.getKey(), n.getValue(), targetFile, doNotSimplifyObjects);
}
writer.endWriteMapIndex();
}
if (routeObjects.size() > 0) {
String name = mapIndex.getName();
if (Algorithms.isEmpty(name)) {
name = defName;
}
writer.startWriteRouteIndex(name);
writer.writeRouteRawEncodingRules(routeIndex.routeEncodingRules);
writeRouteData(writer, routeObjects, targetFile);
writer.endWriteRouteIndex();
}
if (poiObjects.size() > 0) {
String name = "";
boolean overwriteIds = false;
if (Algorithms.isEmpty(name)) {
name = defName;
}
MapRenderingTypesEncoder renderingTypes = new MapRenderingTypesEncoder(null, name);
final IndexPoiCreator indexPoiCreator = new IndexPoiCreator(renderingTypes, overwriteIds);
File poiFile = new File(targetFile.getParentFile(), IndexCreator.getPoiFileName(name));
indexPoiCreator.createDatabaseStructure(poiFile);
for (Map<String, Amenity> mp : poiObjects.valueCollection()) {
for (Amenity a : mp.values()) {
indexPoiCreator.insertAmenityIntoPoi(a);
}
}
indexPoiCreator.writeBinaryPoiIndex(writer, name, null);
indexPoiCreator.commitAndClosePoiFile(System.currentTimeMillis());
indexPoiCreator.removePoiFile();
}
// TODO Write Transport
ous.writeInt32(OsmandOdb.OsmAndStructure.VERSIONCONFIRM_FIELD_NUMBER, version);
ous.flush();
raf.close();
if (gzip) {
nonGzip.setLastModified(timestamp);
FileInputStream fis = new FileInputStream(nonGzip);
GZIPOutputStream gzout = new GZIPOutputStream(new FileOutputStream(targetFile));
Algorithms.streamCopy(fis, gzout);
fis.close();
gzout.close();
nonGzip.delete();
}
targetFile.setLastModified(timestamp);
}
use of net.osmand.osm.MapRenderingTypesEncoder in project OsmAnd-tools by osmandapp.
the class BinaryMerger method combinePoiIndex.
private void combinePoiIndex(String name, BinaryMapIndexWriter writer, long dateCreated, PoiRegion[] poiRegions, BinaryMapIndexReader[] indexes) throws IOException, SQLException {
final int[] writtenPoiCount = { 0 };
MapRenderingTypesEncoder renderingTypes = new MapRenderingTypesEncoder(null, name);
boolean overwriteIds = false;
final IndexPoiCreator indexPoiCreator = new IndexPoiCreator(renderingTypes, overwriteIds);
indexPoiCreator.createDatabaseStructure(new File(new File(System.getProperty("user.dir")), IndexCreator.getPoiFileName(name)));
final Map<Long, List<Amenity>> amenityRelations = new HashMap<Long, List<Amenity>>();
final TLongHashSet set = new TLongHashSet();
final long[] generatedRelationId = { -1 };
for (int i = 0; i < poiRegions.length; i++) {
BinaryMapIndexReader index = indexes[i];
final TLongHashSet file = new TLongHashSet();
log.info("Region: " + extractRegionName(index));
index.searchPoi(BinaryMapIndexReader.buildSearchPoiRequest(0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, -1, BinaryMapIndexReader.ACCEPT_ALL_POI_TYPE_FILTER, new ResultMatcher<Amenity>() {
@Override
public boolean publish(Amenity amenity) {
try {
boolean isRelation = amenity.getId() < 0;
if (isRelation) {
long j = latlon(amenity);
List<Amenity> list;
if (!amenityRelations.containsKey(j)) {
list = new ArrayList<Amenity>(1);
amenityRelations.put(j, list);
} else {
list = amenityRelations.get(j);
}
boolean unique = true;
for (Amenity a : list) {
if (a.getType() == amenity.getType() && Algorithms.objectEquals(a.getSubType(), amenity.getSubType())) {
unique = false;
break;
}
}
if (unique) {
amenity.setId(generatedRelationId[0]--);
amenityRelations.get(j).add(amenity);
indexPoiCreator.insertAmenityIntoPoi(amenity);
writtenPoiCount[0]++;
}
} else {
if (!set.contains(amenity.getId())) {
file.add(amenity.getId());
indexPoiCreator.insertAmenityIntoPoi(amenity);
writtenPoiCount[0]++;
}
}
return false;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public boolean isCancelled() {
return false;
}
}));
set.addAll(file);
}
indexPoiCreator.writeBinaryPoiIndex(writer, name, null);
indexPoiCreator.commitAndClosePoiFile(dateCreated);
// REMOVE_POI_DB = false;
if (REMOVE_POI_DB) {
indexPoiCreator.removePoiFile();
}
log.info("Written " + writtenPoiCount[0] + " POI.");
}
use of net.osmand.osm.MapRenderingTypesEncoder 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);
}
Aggregations