Search in sources :

Example 1 with Node

use of com.baremaps.osm.domain.Node in project baremaps by baremaps.

the class OsmXmlSpliterator method readNode.

private Node readNode() throws XMLStreamException {
    long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_ID));
    Info info = readInfo();
    double latitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LATITUDE));
    double longitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LONGITUDE));
    // read the content of the node
    Map<String, String> tags = new HashMap<>();
    reader.nextTag();
    while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
        switch(reader.getLocalName()) {
            case ELEMENT_NAME_TAG:
                readTag(tags);
                break;
            default:
                readUnknownElement();
                break;
        }
    }
    return new Node(id, info, tags, longitude, latitude);
}
Also used : HashMap(java.util.HashMap) Node(com.baremaps.osm.domain.Node) Info(com.baremaps.osm.domain.Info)

Example 2 with Node

use of com.baremaps.osm.domain.Node in project baremaps by baremaps.

the class DataBlockReader method readDenseNodes.

/**
 * Read the dense nodes with the provided consumer.
 *
 * @param consumer the consumer
 */
public void readDenseNodes(Consumer<Node> consumer) {
    for (PrimitiveGroup group : primitiveBlock.getPrimitivegroupList()) {
        DenseNodes denseNodes = group.getDense();
        long id = 0;
        long lat = 0;
        long lon = 0;
        long timestamp = 0;
        long changeset = 0;
        int sid = 0;
        int uid = 0;
        // Index into the keysvals array.
        int j = 0;
        for (int i = 0; i < denseNodes.getIdCount(); i++) {
            id = denseNodes.getId(i) + id;
            Osmformat.DenseInfo denseInfo = denseNodes.getDenseinfo();
            int version = denseInfo.getVersion(i);
            uid = denseInfo.getUid(i) + uid;
            sid = denseInfo.getUserSid(i) + sid;
            timestamp = denseInfo.getTimestamp(i) + timestamp;
            changeset = denseInfo.getChangeset(i) + changeset;
            lat = denseNodes.getLat(i) + lat;
            lon = denseNodes.getLon(i) + lon;
            // If empty, assume that nothing here has keys or vals.
            Map<String, String> tags = new HashMap<>();
            if (denseNodes.getKeysValsCount() > 0) {
                while (denseNodes.getKeysVals(j) != 0) {
                    int keyid = denseNodes.getKeysVals(j++);
                    int valid = denseNodes.getKeysVals(j++);
                    tags.put(getString(keyid), getString(valid));
                }
                // Skip over the '0' delimiter.
                j++;
            }
            Info info = new Info(version, getTimestamp(timestamp), changeset, uid);
            consumer.accept(new Node(id, info, tags, getLon(lon), getLat(lat)));
        }
    }
}
Also used : PrimitiveGroup(com.baremaps.osm.binary.Osmformat.PrimitiveGroup) HashMap(java.util.HashMap) Node(com.baremaps.osm.domain.Node) DenseNodes(com.baremaps.osm.binary.Osmformat.DenseNodes) Osmformat(com.baremaps.osm.binary.Osmformat) Info(com.baremaps.osm.domain.Info)

Example 3 with Node

use of com.baremaps.osm.domain.Node in project baremaps by baremaps.

the class OsmChangeSpliterator method readNode.

private Node readNode() throws XMLStreamException {
    long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_ID));
    Info info = readInfo();
    double latitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LATITUDE));
    double longitude = Double.parseDouble(reader.getAttributeValue(null, ATTRIBUTE_NAME_LONGITUDE));
    // read the content of the node
    Map<String, String> tags = new HashMap<>();
    reader.nextTag();
    while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
        switch(reader.getLocalName()) {
            case ELEMENT_NAME_TAG:
                readTag(tags);
                break;
            default:
                readUnknownElement();
                break;
        }
    }
    return new Node(id, info, tags, latitude, longitude);
}
Also used : HashMap(java.util.HashMap) Node(com.baremaps.osm.domain.Node) Info(com.baremaps.osm.domain.Info)

Example 4 with Node

use of com.baremaps.osm.domain.Node in project baremaps by baremaps.

the class Diff method call.

@Override
public Integer call() throws Exception {
    BlobStore blobStore = options.blobStore();
    DataSource datasource = PostgresUtils.datasource(database);
    LongDataMap<Coordinate> coordinates = new PostgresCoordinateMap(datasource);
    LongDataMap<List<Long>> references = new PostgresReferenceMap(datasource);
    HeaderRepository headerRepository = new PostgresHeaderRepository(datasource);
    Repository<Long, Node> nodeRepository = new PostgresNodeRepository(datasource);
    Repository<Long, Way> wayRepository = new PostgresWayRepository(datasource);
    Repository<Long, Relation> relationRepository = new PostgresRelationRepository(datasource);
    logger.info("Saving diff");
    Path tmpTiles = Files.createFile(Paths.get("diff.tmp"));
    try (PrintWriter printWriter = new PrintWriter(Files.newBufferedWriter(tmpTiles))) {
        new DiffService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, srid, zoom).call();
    }
    blobStore.put(this.tiles, Blob.builder().withContentLength(Files.size(tmpTiles)).withInputStream(Files.newInputStream(tmpTiles)).build());
    Files.deleteIfExists(tmpTiles);
    logger.info("Done");
    return 0;
}
Also used : Path(java.nio.file.Path) PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository) HeaderRepository(com.baremaps.osm.repository.HeaderRepository) PostgresWayRepository(com.baremaps.osm.postgres.PostgresWayRepository) PostgresReferenceMap(com.baremaps.osm.postgres.PostgresReferenceMap) Node(com.baremaps.osm.domain.Node) DiffService(com.baremaps.osm.repository.DiffService) PostgresCoordinateMap(com.baremaps.osm.postgres.PostgresCoordinateMap) Way(com.baremaps.osm.domain.Way) DataSource(javax.sql.DataSource) Relation(com.baremaps.osm.domain.Relation) Coordinate(org.locationtech.jts.geom.Coordinate) PostgresNodeRepository(com.baremaps.osm.postgres.PostgresNodeRepository) List(java.util.List) PostgresRelationRepository(com.baremaps.osm.postgres.PostgresRelationRepository) BlobStore(com.baremaps.blob.BlobStore) PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository) PrintWriter(java.io.PrintWriter)

Example 5 with Node

use of com.baremaps.osm.domain.Node in project baremaps by baremaps.

the class Import method call.

@Override
public Integer call() throws Exception {
    BlobStore blobStore = options.blobStore();
    DataSource datasource = PostgresUtils.datasource(database);
    HeaderRepository headerRepository = new PostgresHeaderRepository(datasource);
    Repository<Long, Node> nodeRepository = new PostgresNodeRepository(datasource);
    Repository<Long, Way> wayRepository = new PostgresWayRepository(datasource);
    Repository<Long, Relation> relationRepository = new PostgresRelationRepository(datasource);
    Path directory = Files.createTempDirectory(Paths.get("."), "baremaps_");
    Path nodes = Files.createDirectories(directory.resolve("nodes"));
    Path referencesKeys = Files.createDirectories(directory.resolve("references_keys"));
    Path referencesValues = Files.createDirectories(directory.resolve("references_values"));
    LongDataMap<Coordinate> coordinates = new LongAlignedDataDenseMap<>(new LonLatDataType(), new OnDiskMemory(nodes));
    LongDataMap<List<Long>> references = new LongDataSortedMap<>(new AlignedDataList<>(new PairDataType<>(new LongDataType(), new LongDataType()), new OnDiskMemory(referencesKeys)), new DataStore<>(new LongListDataType(), new OnDiskMemory(referencesValues)));
    logger.info("Importing data");
    new ImportService(file, blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, srid).call();
    logger.info("Done");
    return 0;
}
Also used : PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository) HeaderRepository(com.baremaps.osm.repository.HeaderRepository) LongListDataType(com.baremaps.store.type.LongListDataType) Node(com.baremaps.osm.domain.Node) Way(com.baremaps.osm.domain.Way) Relation(com.baremaps.osm.domain.Relation) ImportService(com.baremaps.osm.repository.ImportService) LongDataSortedMap(com.baremaps.store.LongDataSortedMap) LongAlignedDataDenseMap(com.baremaps.store.LongAlignedDataDenseMap) AlignedDataList(com.baremaps.store.AlignedDataList) List(java.util.List) BlobStore(com.baremaps.blob.BlobStore) PairDataType(com.baremaps.store.type.PairDataType) Path(java.nio.file.Path) PostgresWayRepository(com.baremaps.osm.postgres.PostgresWayRepository) OnDiskMemory(com.baremaps.store.memory.OnDiskMemory) LonLatDataType(com.baremaps.store.type.LonLatDataType) DataSource(javax.sql.DataSource) Coordinate(org.locationtech.jts.geom.Coordinate) PostgresNodeRepository(com.baremaps.osm.postgres.PostgresNodeRepository) PostgresRelationRepository(com.baremaps.osm.postgres.PostgresRelationRepository) LongDataType(com.baremaps.store.type.LongDataType) PostgresHeaderRepository(com.baremaps.osm.postgres.PostgresHeaderRepository)

Aggregations

Node (com.baremaps.osm.domain.Node)16 Way (com.baremaps.osm.domain.Way)8 Relation (com.baremaps.osm.domain.Relation)7 List (java.util.List)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 Info (com.baremaps.osm.domain.Info)5 HashMap (java.util.HashMap)4 BlobStore (com.baremaps.blob.BlobStore)3 PostgresHeaderRepository (com.baremaps.osm.postgres.PostgresHeaderRepository)3 PostgresNodeRepository (com.baremaps.osm.postgres.PostgresNodeRepository)3 PostgresRelationRepository (com.baremaps.osm.postgres.PostgresRelationRepository)3 PostgresWayRepository (com.baremaps.osm.postgres.PostgresWayRepository)3 HeaderRepository (com.baremaps.osm.repository.HeaderRepository)3 RepositoryException (com.baremaps.osm.repository.RepositoryException)3 LongListDataType (com.baremaps.store.type.LongListDataType)3 Path (java.nio.file.Path)3 Osmformat (com.baremaps.osm.binary.Osmformat)2 PrimitiveGroup (com.baremaps.osm.binary.Osmformat.PrimitiveGroup)2 Header (com.baremaps.osm.domain.Header)2 EntityConsumerAdapter (com.baremaps.osm.function.EntityConsumerAdapter)2