use of net.osmand.osm.MapRenderingTypesEncoder in project OsmAnd-tools by osmandapp.
the class IndexCreator method generateRegionsFile.
public static void generateRegionsFile() throws IOException, SQLException, InterruptedException, XmlPullParserException {
MapRenderingTypesEncoder rt = new MapRenderingTypesEncoder("regions");
String file = "/home/victor/projects/osmand/repo/resources/osmand_regions.osm";
String folder = "/home/victor/projects/osmand/repo/resources/countries-info/";
// $NON-NLS-1$
IndexCreator creator = new IndexCreator(new File(folder));
creator.setMapFileName("regions.ocbf");
creator.setIndexMap(true);
creator.setIndexAddress(false);
creator.setIndexPOI(false);
creator.setIndexTransport(false);
creator.setIndexRouting(false);
MapZooms zooms = MapZooms.parseZooms("5-6");
creator.zoomWaySmoothness = 1;
int st = file.lastIndexOf('/');
int e = file.indexOf('.', st);
creator.setNodesDBFile(new File(folder + file.substring(st, e) + ".tmp.odb"));
creator.generateIndexes(new File(file), new ConsoleProgressImplementation(1), null, zooms, rt, log);
}
use of net.osmand.osm.MapRenderingTypesEncoder in project OsmAnd-tools by osmandapp.
the class IndexCreator method generateBasemapIndex.
public void generateBasemapIndex(IProgress progress, IOsmStorageFilter addFilter, MapZooms mapZooms, MapRenderingTypesEncoder renderingTypes, Log logMapDataWarn, String regionName, File... readFiles) throws IOException, SQLException, InterruptedException, XmlPullParserException {
if (logMapDataWarn == null) {
logMapDataWarn = log;
}
if (renderingTypes == null) {
renderingTypes = new MapRenderingTypesEncoder("basemap");
}
if (mapZooms == null) {
mapZooms = MapZooms.getDefault();
}
// clear previous results and setting variables
try {
final BasemapProcessor processor = new BasemapProcessor(logMapDataWarn, mapZooms, renderingTypes, zoomWaySmoothness);
final IndexPoiCreator poiCreator = indexPOI ? new IndexPoiCreator(renderingTypes, false) : null;
if (indexPOI) {
poiCreator.createDatabaseStructure(getPoiFile());
}
OsmDbAccessor accessor = initDbAccessor(readFiles, progress, addFilter, true, false, true);
// 2. Create index connections and index structure
setGeneralProgress(progress, "[50 / 100]");
progress.startTask(Messages.getString("IndexCreator.PROCESS_OSM_NODES"), accessor.getAllNodes());
accessor.iterateOverEntities(progress, EntityType.NODE, new OsmDbVisitor() {
@Override
public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
processor.processEntity(e);
if (indexPOI) {
poiCreator.iterateEntity(e, ctx, true);
}
}
});
setGeneralProgress(progress, "[70 / 100]");
progress.startTask(Messages.getString("IndexCreator.PROCESS_OSM_WAYS"), accessor.getAllWays());
accessor.iterateOverEntities(progress, EntityType.WAY, new OsmDbVisitor() {
@Override
public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
processor.processEntity(e);
if (indexPOI) {
poiCreator.iterateEntity(e, ctx, true);
}
}
});
setGeneralProgress(progress, "[90 / 100]");
progress.startTask(Messages.getString("IndexCreator.PROCESS_OSM_REL"), accessor.getAllRelations());
accessor.iterateOverEntities(progress, EntityType.RELATION, new OsmDbVisitor() {
@Override
public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
ctx.loadEntityRelation((Relation) e);
processor.processEntity(e);
}
});
accessor.closeReadingConnection();
mapFile = new File(workingDir, getMapFileName());
// to save space
mapFile.getParentFile().mkdirs();
if (mapFile.exists()) {
mapFile.delete();
}
mapRAFile = new RandomAccessFile(mapFile, "rw");
BinaryMapIndexWriter writer = new BinaryMapIndexWriter(mapRAFile, lastModifiedDate == null ? System.currentTimeMillis() : lastModifiedDate.longValue());
setGeneralProgress(progress, "[95 of 100]");
progress.startTask("Writing map index to binary file...", -1);
processor.writeBasemapFile(writer, regionName);
if (indexPOI) {
poiCreator.writeBinaryPoiIndex(writer, regionName, progress);
}
progress.finishTask();
writer.close();
mapRAFile.close();
// $NON-NLS-1$
log.info("Finish writing binary file");
} catch (RuntimeException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
} catch (SQLException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
} catch (IOException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
} catch (XmlPullParserException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
}
}
use of net.osmand.osm.MapRenderingTypesEncoder in project OsmAnd-tools by osmandapp.
the class IndexCreator method generateIndexes.
public void generateIndexes(File[] readFile, IProgress progress, IOsmStorageFilter addFilter, MapZooms mapZooms, MapRenderingTypesEncoder renderingTypes, Log logMapDataWarn, boolean generateUniqueIds, boolean overwriteIds) throws IOException, SQLException, InterruptedException, XmlPullParserException {
// }
if (logMapDataWarn == null) {
logMapDataWarn = log;
}
if (mapZooms == null) {
mapZooms = MapZooms.getDefault();
}
// clear previous results and setting variables
if (readFile != null && readFile.length > 0 && regionName == null) {
int i = readFile[0].getName().indexOf('.');
if (i > -1) {
regionName = Algorithms.capitalizeFirstLetterAndLowercase(readFile[0].getName().substring(0, i));
}
}
if (renderingTypes == null) {
renderingTypes = new MapRenderingTypesEncoder(null, regionName);
}
this.indexTransportCreator = new IndexTransportCreator();
this.indexPoiCreator = new IndexPoiCreator(renderingTypes, overwriteIds);
this.indexAddressCreator = new IndexAddressCreator(logMapDataWarn);
this.indexMapCreator = new IndexVectorMapCreator(logMapDataWarn, mapZooms, renderingTypes, zoomWaySmoothness);
this.indexRouteCreator = new IndexRouteCreator(renderingTypes, logMapDataWarn, generateLowLevel);
// init address
indexAddressCreator.initSettings(cityAdminLevel);
// Main generation method
try {
// do not create temp map file and rtree files
if (recreateOnlyBinaryFile) {
mapFile = new File(workingDir, getMapFileName());
File tempDBMapFile = new File(workingDir, getTempMapDBFileName());
mapConnection = (Connection) getDatabaseConnection(tempDBMapFile.getAbsolutePath(), mapIndexDBDialect);
mapConnection.setAutoCommit(false);
try {
if (indexMap) {
indexMapCreator.createRTreeFiles(getRTreeMapIndexPackFileName());
}
if (indexRouting) {
indexRouteCreator.createRTreeFiles(getRTreeRouteIndexPackFileName());
}
if (indexTransport) {
indexTransportCreator.createRTreeFile(getRTreeTransportStopsPackFileName());
}
} catch (RTreeException e) {
// $NON-NLS-1$
log.error("Error flushing", e);
throw new IOException(e);
}
} else {
// 2. Create index connections and index structure
createDatabaseIndexesStructure();
OsmDbAccessor accessor = initDbAccessor(readFile, progress, addFilter, generateUniqueIds, overwriteIds, false);
// 3. Processing all entries
// 3.1 write all cities
writeAllCities(accessor, progress);
// 3.2 index address relations
indexRelations(accessor, progress);
// 3.3 MAIN iterate over all entities
iterateMainEntities(accessor, progress);
accessor.closeReadingConnection();
// do not delete first db connection
if (accessor.getDbConn() != null) {
osmDBdialect.commitDatabase(accessor.getDbConn());
osmDBdialect.closeDatabase(accessor.getDbConn());
}
if (deleteOsmDB) {
osmDBdialect.removeDatabase(dbFile);
}
// 3.4 combine all low level ways and simplify them
if (indexMap || indexRouting) {
setGeneralProgress(progress, "[90 / 100]");
if (indexMap) {
progress.startTask(Messages.getString("IndexCreator.INDEX_LO_LEVEL_WAYS"), indexMapCreator.getLowLevelWays());
indexMapCreator.processingLowLevelWays(progress);
}
if (indexRouting) {
progress.startTask(Messages.getString("IndexCreator.INDEX_LO_LEVEL_WAYS"), -1);
indexRouteCreator.processingLowLevelWays(progress);
}
}
// 4. packing map rtree indexes
if (indexMap) {
// $NON-NLS-1$
setGeneralProgress(progress, "[90 / 100]");
// $NON-NLS-1$
progress.startTask(Messages.getString("IndexCreator.PACK_RTREE_MAP"), -1);
indexMapCreator.packRtreeFiles(getRTreeMapIndexNonPackFileName(), getRTreeMapIndexPackFileName());
}
if (indexRouting) {
indexRouteCreator.packRtreeFiles(getRTreeRouteIndexNonPackFileName(), getRTreeRouteIndexPackFileName());
}
if (indexTransport) {
// $NON-NLS-1$
setGeneralProgress(progress, "[90 / 100]");
// $NON-NLS-1$
progress.startTask(Messages.getString("IndexCreator.PACK_RTREE_TRANSP"), -1);
indexTransportCreator.packRTree(getRTreeTransportStopsFileName(), getRTreeTransportStopsPackFileName());
}
}
// 5. Writing binary file
if (indexMap || indexAddress || indexTransport || indexPOI || indexRouting) {
if (mapFile.exists()) {
mapFile.delete();
}
mapRAFile = new RandomAccessFile(mapFile, "rw");
BinaryMapIndexWriter writer = new BinaryMapIndexWriter(mapRAFile, lastModifiedDate == null ? System.currentTimeMillis() : lastModifiedDate.longValue());
if (indexMap) {
setGeneralProgress(progress, "[95 of 100]");
progress.startTask("Writing map index to binary file...", -1);
indexMapCreator.writeBinaryMapIndex(writer, regionName);
}
if (indexRouting) {
setGeneralProgress(progress, "[95 of 100]");
progress.startTask("Writing route index to binary file...", -1);
indexRouteCreator.writeBinaryRouteIndex(mapFile, writer, regionName, generateLowLevel);
}
if (indexAddress) {
setGeneralProgress(progress, "[95 of 100]");
progress.startTask("Writing address index to binary file...", -1);
indexAddressCreator.writeBinaryAddressIndex(writer, regionName, progress);
}
if (indexPOI) {
setGeneralProgress(progress, "[95 of 100]");
progress.startTask("Writing poi index to binary file...", -1);
indexPoiCreator.writeBinaryPoiIndex(writer, regionName, progress);
}
if (indexTransport) {
setGeneralProgress(progress, "[95 of 100]");
progress.startTask("Writing transport index to binary file...", -1);
indexTransportCreator.writeBinaryTransportIndex(writer, regionName, mapConnection);
}
progress.finishTask();
writer.close();
mapRAFile.close();
// $NON-NLS-1$
log.info("Finish writing binary file");
}
} catch (RuntimeException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
} catch (SQLException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
} catch (IOException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
} catch (XmlPullParserException e) {
// $NON-NLS-1$
log.error("Log exception", e);
throw e;
} finally {
try {
indexPoiCreator.commitAndClosePoiFile(lastModifiedDate);
if (REMOVE_POI_DB) {
indexPoiCreator.removePoiFile();
}
indexAddressCreator.closeAllPreparedStatements();
indexTransportCreator.commitAndCloseFiles(getRTreeTransportStopsFileName(), getRTreeTransportStopsPackFileName(), deleteDatabaseIndexes);
indexMapCreator.commitAndCloseFiles(getRTreeMapIndexNonPackFileName(), getRTreeMapIndexPackFileName(), deleteDatabaseIndexes);
indexRouteCreator.commitAndCloseFiles(getRTreeRouteIndexNonPackFileName(), getRTreeRouteIndexPackFileName(), deleteDatabaseIndexes);
if (mapConnection != null) {
mapConnection.commit();
mapConnection.close();
mapConnection = null;
File tempDBFile = new File(workingDir, getTempMapDBFileName());
if (mapIndexDBDialect.databaseFileExists(tempDBFile) && deleteDatabaseIndexes) {
// do not delete it for now
mapIndexDBDialect.removeDatabase(tempDBFile);
}
}
} catch (SQLException e) {
e.printStackTrace();
} catch (RuntimeException e) {
e.printStackTrace();
}
}
}
use of net.osmand.osm.MapRenderingTypesEncoder in project OsmAnd-tools by osmandapp.
the class FixBasemapRoads method process.
private void process(File read, File write, List<File> relationFiles) throws IOException, XMLStreamException, XmlPullParserException, SQLException {
MapRenderingTypesEncoder renderingTypes = new MapRenderingTypesEncoder("basemap");
OsmandRegions or = prepareRegions();
TagsTransformer transformer = new TagsTransformer();
for (File relFile : relationFiles) {
LOG.info("Parse relations file " + relFile.getName());
OsmBaseStorage storage = parseOsmFile(relFile);
int total = 0;
for (EntityId e : storage.getRegisteredEntities().keySet()) {
if (e.getType() == EntityType.RELATION) {
total++;
if (total % 1000 == 0) {
LOG.info("Processed " + total + " relations");
}
Relation es = (Relation) storage.getRegisteredEntities().get(e);
transformer.handleRelationPropogatedTags(es, renderingTypes, null, EntityConvertApplyType.MAP);
}
}
}
LOG.info("Parse main file " + read.getName());
OsmBaseStorage storage = parseOsmFile(read);
Map<EntityId, Entity> entities = new HashMap<EntityId, Entity>(storage.getRegisteredEntities());
int total = 0;
for (EntityId e : entities.keySet()) {
if (e.getType() == EntityType.WAY) {
Way es = (Way) storage.getRegisteredEntities().get(e);
total++;
if (total % 1000 == 0) {
LOG.info("Processed " + total + " ways");
}
addRegionTag(or, es);
transformer.addPropogatedTags(es);
Map<String, String> ntags = renderingTypes.transformTags(es.getModifiableTags(), EntityType.WAY, EntityConvertApplyType.MAP);
if (es.getModifiableTags() != ntags) {
es.getModifiableTags().putAll(ntags);
}
processWay(es);
}
}
List<EntityId> toWrite = new ArrayList<EntityId>();
processRegion(toWrite);
OsmStorageWriter writer = new OsmStorageWriter();
LOG.info("Writing file... ");
writer.saveStorage(new FileOutputStream(write), storage, toWrite, true);
LOG.info("DONE");
}
use of net.osmand.osm.MapRenderingTypesEncoder in project OsmAnd-tools by osmandapp.
the class CoastlinesLayer method initLayer.
@Override
public void initLayer(MapPanel map) {
this.map = map;
basemapProcessor = new BasemapProcessor(null, MapZooms.getDefault(), new MapRenderingTypesEncoder("basemap"), 0);
fillPopupMenuWithActions(map.getPopupMenu());
}
Aggregations