Search in sources :

Example 6 with MapRenderingTypesEncoder

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);
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) FileOutputStream(java.io.FileOutputStream) MapZooms(net.osmand.binary.MapZooms) IndexCreator(net.osmand.data.preparation.IndexCreator) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 7 with MapRenderingTypesEncoder

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();
        }
    }
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) IndexCreator(net.osmand.data.preparation.IndexCreator) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 8 with MapRenderingTypesEncoder

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);
}
Also used : Amenity(net.osmand.data.Amenity) CodedOutputStream(com.google.protobuf.CodedOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) CodedOutputStream(com.google.protobuf.CodedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) IOException(java.io.IOException) IndexPoiCreator(net.osmand.data.preparation.IndexPoiCreator) FileInputStream(java.io.FileInputStream) Entry(java.util.Map.Entry) MapZoomPair(net.osmand.binary.MapZooms.MapZoomPair) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) RandomAccessFile(java.io.RandomAccessFile) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) BinaryMapIndexWriter(net.osmand.data.preparation.BinaryMapIndexWriter) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 9 with MapRenderingTypesEncoder

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.");
}
Also used : Amenity(net.osmand.data.Amenity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) IndexPoiCreator(net.osmand.data.preparation.IndexPoiCreator) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) TLongHashSet(gnu.trove.set.hash.TLongHashSet) List(java.util.List) ArrayList(java.util.ArrayList) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 10 with MapRenderingTypesEncoder

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);
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation)

Aggregations

MapRenderingTypesEncoder (net.osmand.osm.MapRenderingTypesEncoder)17 File (java.io.File)16 ConsoleProgressImplementation (net.osmand.impl.ConsoleProgressImplementation)10 RandomAccessFile (java.io.RandomAccessFile)7 FileOutputStream (java.io.FileOutputStream)6 IndexCreator (net.osmand.data.preparation.IndexCreator)6 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 MapZooms (net.osmand.binary.MapZooms)4 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)2 Amenity (net.osmand.data.Amenity)2 IndexPoiCreator (net.osmand.data.preparation.IndexPoiCreator)2 Entity (net.osmand.osm.edit.Entity)2