use of com.baremaps.osm.domain.Relation in project baremaps by baremaps.
the class PostgresRelationRepository method getValue.
private Relation getValue(ResultSet resultSet) throws SQLException, JsonProcessingException {
long id = resultSet.getLong(1);
int version = resultSet.getInt(2);
int uid = resultSet.getInt(3);
LocalDateTime timestamp = resultSet.getObject(4, LocalDateTime.class);
long changeset = resultSet.getLong(5);
Map<String, String> tags = toMap(resultSet.getString(6));
Long[] refs = (Long[]) resultSet.getArray(7).getArray();
Integer[] types = (Integer[]) resultSet.getArray(8).getArray();
String[] roles = (String[]) resultSet.getArray(9).getArray();
List<Member> members = new ArrayList<>();
for (int i = 0; i < refs.length; i++) {
members.add(new Member(refs[i], MemberType.forNumber(types[i]), roles[i]));
}
Geometry geometry = GeometryUtils.deserialize(resultSet.getBytes(10));
Info info = new Info(version, timestamp, changeset, uid);
return new Relation(id, info, tags, members, geometry);
}
use of com.baremaps.osm.domain.Relation in project baremaps by baremaps.
the class CreateGeometryConsumer method createPolygons.
private Set<Polygon> createPolygons(Relation relation, String role) {
Set<Polygon> polygons = new HashSet<>();
LineMerger lineMerger = new LineMerger();
relation.getMembers().stream().filter(m -> MemberType.WAY.equals(m.getType())).filter(m -> role.equals(m.getRole())).forEach(member -> {
LineString line = createLine(member);
if (line.isClosed()) {
Polygon polygon = geometryFactory.createPolygon(line.getCoordinates());
polygons.add(polygon);
} else {
lineMerger.add(line);
}
});
lineMerger.getMergedLineStrings().stream().forEach(geometry -> {
LineString line = (LineString) geometry;
if (line.isClosed()) {
Polygon polygon = geometryFactory.createPolygon(line.getCoordinates());
polygons.add(polygon);
}
});
return polygons;
}
use of com.baremaps.osm.domain.Relation in project baremaps by baremaps.
the class OsmXmlSpliterator method readRelation.
private Relation readRelation() throws XMLStreamException {
long id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_ID));
Info info = readInfo();
// read the content of the node
Map<String, String> tags = new HashMap<>();
List<Member> members = new ArrayList<>();
reader.nextTag();
while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
switch(reader.getLocalName()) {
case ELEMENT_NAME_TAG:
readTag(tags);
break;
case ELEMENT_NAME_MEMBER:
readRelationMember(members);
break;
default:
readUnknownElement();
break;
}
}
return new Relation(id, info, tags, members);
}
use of com.baremaps.osm.domain.Relation in project baremaps by baremaps.
the class Update 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("Importing changes");
new UpdateService(blobStore, coordinates, references, headerRepository, nodeRepository, wayRepository, relationRepository, srid).call();
logger.info("Done");
return 0;
}
use of com.baremaps.osm.domain.Relation in project baremaps by baremaps.
the class OpenStreetMapGeometriesBenchmark method store.
@Benchmark
@BenchmarkMode(Mode.SingleShotTime)
@Warmup(iterations = 0)
@Measurement(iterations = 1)
public void store() throws IOException {
Path directory = Files.createTempDirectory(Paths.get("."), "benchmark_");
LongDataMap<Coordinate> coordinates = new LongDataOpenHashMap<>(new DataStore<>(new CoordinateDataType(), new OnDiskMemory(directory)));
LongDataMap<List<Long>> references = new LongDataOpenHashMap<>(new DataStore<>(new LongListDataType(), new OnHeapMemory()));
AtomicLong nodes = new AtomicLong(0);
AtomicLong ways = new AtomicLong(0);
AtomicLong relations = new AtomicLong(0);
try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(path))) {
new OsmPbfParser().coordinates(coordinates).references(references).projection(4326).entities(inputStream).forEach(new EntityConsumerAdapter() {
@Override
public void match(Node node) {
nodes.incrementAndGet();
}
@Override
public void match(Way way) {
ways.incrementAndGet();
}
@Override
public void match(Relation relation) {
relations.incrementAndGet();
}
});
}
}
Aggregations