Search in sources :

Example 1 with OsmDbVisitor

use of net.osmand.data.preparation.OsmDbAccessor.OsmDbVisitor in project OsmAnd-tools by osmandapp.

the class IndexCreator method indexRelations.

private void indexRelations(OsmDbAccessor accessor, IProgress progress) throws SQLException, InterruptedException {
    if (indexAddress || indexMap || indexRouting || indexPOI || indexTransport) {
        // $NON-NLS-1$
        setGeneralProgress(progress, "[30 / 100]");
        // $NON-NLS-1$
        progress.startTask(Messages.getString("IndexCreator.PREINDEX_BOUNDARIES_RELATIONS"), accessor.getAllRelations());
        accessor.iterateOverEntities(progress, EntityType.RELATION, new OsmDbVisitor() {

            @Override
            public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
                if (indexAddress) {
                    // indexAddressCreator.indexAddressRelation((Relation) e, ctx); streets needs loaded boundaries !!!
                    indexAddressCreator.indexBoundariesRelation(e, ctx);
                }
                if (indexMap) {
                    indexMapCreator.indexMapRelationsAndMultiPolygons(e, ctx);
                }
                if (indexRouting) {
                    indexRouteCreator.indexRelations(e, ctx);
                }
                if (indexPOI) {
                    indexPoiCreator.iterateRelation((Relation) e, ctx);
                }
                if (indexTransport) {
                    indexTransportCreator.indexRelations((Relation) e, ctx);
                }
            }
        });
        if (indexMap) {
            indexMapCreator.createMapIndexTableIndexes(mapConnection);
        }
        if (indexAddress) {
            // $NON-NLS-1$
            setGeneralProgress(progress, "[40 / 100]");
            // $NON-NLS-1$
            progress.startTask(Messages.getString("IndexCreator.PREINDEX_BOUNDARIES_WAYS"), accessor.getAllWays());
            accessor.iterateOverEntities(progress, EntityType.WAY_BOUNDARY, new OsmDbVisitor() {

                @Override
                public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
                    indexAddressCreator.indexBoundariesRelation(e, ctx);
                }
            });
            // $NON-NLS-1$
            setGeneralProgress(progress, "[42 / 100]");
            // $NON-NLS-1$
            progress.startTask(Messages.getString("IndexCreator.BIND_CITIES_AND_BOUNDARIES"), 100);
            // finish up the boundaries and cities
            indexAddressCreator.tryToAssignBoundaryToFreeCities(progress);
            // $NON-NLS-1$
            setGeneralProgress(progress, "[45 / 100]");
            // $NON-NLS-1$
            progress.startTask(Messages.getString("IndexCreator.PREINDEX_ADRESS_MAP"), accessor.getAllRelations());
            accessor.iterateOverEntities(progress, EntityType.RELATION, new OsmDbVisitor() {

                @Override
                public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
                    indexAddressCreator.indexAddressRelation((Relation) e, ctx);
                }
            });
            indexAddressCreator.commitToPutAllCities();
        }
    }
}
Also used : Entity(net.osmand.osm.edit.Entity) Relation(net.osmand.osm.edit.Relation) SQLException(java.sql.SQLException) OsmDbVisitor(net.osmand.data.preparation.OsmDbAccessor.OsmDbVisitor)

Example 2 with OsmDbVisitor

use of net.osmand.data.preparation.OsmDbAccessor.OsmDbVisitor 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;
    }
}
Also used : Entity(net.osmand.osm.edit.Entity) SQLException(java.sql.SQLException) IOException(java.io.IOException) Relation(net.osmand.osm.edit.Relation) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) RandomAccessFile(java.io.RandomAccessFile) OsmDbVisitor(net.osmand.data.preparation.OsmDbAccessor.OsmDbVisitor) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 3 with OsmDbVisitor

use of net.osmand.data.preparation.OsmDbAccessor.OsmDbVisitor in project OsmAnd-tools by osmandapp.

the class IndexCreator method iterateMainEntities.

private void iterateMainEntities(OsmDbAccessor accessor, IProgress progress) throws SQLException, InterruptedException {
    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 {
            iterateMainEntity(e, ctx);
        }
    });
    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 {
            iterateMainEntity(e, ctx);
        }
    });
    setGeneralProgress(progress, "[85 / 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 {
            iterateMainEntity(e, ctx);
        }
    });
}
Also used : Entity(net.osmand.osm.edit.Entity) SQLException(java.sql.SQLException) OsmDbVisitor(net.osmand.data.preparation.OsmDbAccessor.OsmDbVisitor)

Aggregations

SQLException (java.sql.SQLException)3 OsmDbVisitor (net.osmand.data.preparation.OsmDbAccessor.OsmDbVisitor)3 Entity (net.osmand.osm.edit.Entity)3 Relation (net.osmand.osm.edit.Relation)2 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 MapRenderingTypesEncoder (net.osmand.osm.MapRenderingTypesEncoder)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1