Skip to content
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
acebe4c
Port the MARTINI algorithm to java
bchapuis Jun 11, 2024
b034bf2
Fix minor formatting issues
bchapuis Jun 12, 2024
a24f898
use double instead of float values
bchapuis Jun 27, 2024
6104fb9
Format code
bchapuis Jun 27, 2024
ebc0f43
Add hillshade and isolines algorithms
bchapuis Jun 28, 2024
4eb2d23
Compute hillshades and contour
bchapuis Jul 1, 2024
4c0c5bb
Refactor the code and improve javadoc
bchapuis Jul 23, 2024
d1f8069
Improve contour tracer
bchapuis Jul 30, 2024
ba21a24
Do some cleanup
bchapuis Jul 30, 2024
c818573
Improve API
bchapuis Jul 30, 2024
e3994b3
Systematically use SRI
bchapuis Jul 30, 2024
f94eb34
Add Chaikin smoother and improve hillshade and contour server
bchapuis Jul 31, 2024
e4543b2
Improve hillshade demonstration
bchapuis Jul 31, 2024
9ba78e7
Fix sonar issues
bchapuis Jul 31, 2024
80a92db
Fix issues detected by sonar
bchapuis Jul 31, 2024
25cc892
Do some cleaning
bchapuis Jul 31, 2024
a144428
Refactor and clean
bchapuis Aug 2, 2024
65204df
Fix polygonization
bchapuis Aug 2, 2024
7d51799
Fix unit tests
bchapuis Aug 3, 2024
2db80a1
Improve naming
bchapuis Aug 3, 2024
31e2ef7
Do some cleanup
bchapuis Aug 3, 2024
fc95956
Read wkt
bchapuis Aug 3, 2024
533c32f
Format code
bchapuis Aug 3, 2024
2ee536a
Improve hillshade and contour map
bchapuis Aug 5, 2024
ead787e
Improve hillshade and add gdal api
bchapuis Aug 20, 2024
7856a00
Move the gdal classes in a dedicated module
bchapuis Aug 21, 2024
1444236
Avoid falling into the extremes when interpolating
bchapuis Aug 21, 2024
2c4f443
Remove intermediary line merge
bchapuis Aug 21, 2024
73d163c
Add conversion method
bchapuis Aug 21, 2024
6f82ad1
Refactor and cleanup the code
bchapuis Aug 21, 2024
68ff7ea
Clean, format and document
bchapuis Aug 22, 2024
0e0c6fa
Use Apache SIS instead of GDAL to read tiff files
bchapuis Aug 29, 2024
5c4d04c
Remove printstacktrace call
bchapuis Aug 29, 2024
71bc83d
Add failing polygonization test
bchapuis Aug 29, 2024
a4d96ec
Fix polygonization
bchapuis Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions baremaps-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ limitations under the License.
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-raster</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.baremaps.cli.Baremaps.VersionProvider;
import org.apache.baremaps.cli.database.Database;
import org.apache.baremaps.cli.geocoder.Geocoder;
import org.apache.baremaps.cli.hillshade.Hillshade;
import org.apache.baremaps.cli.iploc.IpLoc;
import org.apache.baremaps.cli.map.Map;
import org.apache.baremaps.cli.workflow.Workflow;
Expand All @@ -42,7 +43,14 @@
name = "baremaps",
description = "A toolkit for producing vector tiles.",
versionProvider = VersionProvider.class,
subcommands = {Workflow.class, Database.class, Map.class, Geocoder.class, IpLoc.class},
subcommands = {
Workflow.class,
Database.class,
Map.class,
Geocoder.class,
IpLoc.class,
Hillshade.class
},
sortOptions = false)
@SuppressWarnings("squid:S106")
public class Baremaps implements Callable<Integer> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.baremaps.cli.hillshade;



import picocli.CommandLine;
import picocli.CommandLine.Command;

@Command(name = "hillshade", description = "Hillshade processing commands.",
subcommands = {Serve.class},
sortOptions = false)
@SuppressWarnings("squid:S106")
public class Hillshade implements Runnable {

@Override
public void run() {
CommandLine.usage(this, System.out);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.baremaps.cli.hillshade;

import static org.apache.baremaps.utils.ObjectMapperUtils.objectMapper;

import com.github.benmanes.caffeine.cache.CaffeineSpec;
import com.linecorp.armeria.common.*;
import com.linecorp.armeria.server.Server;
import com.linecorp.armeria.server.annotation.JacksonResponseConverterFunction;
import com.linecorp.armeria.server.cors.CorsService;
import com.linecorp.armeria.server.docs.DocService;
import com.linecorp.armeria.server.file.HttpFile;
import java.util.concurrent.Callable;
import org.apache.baremaps.raster.ElevationUtils;
import org.apache.baremaps.server.BufferedImageResource;
import org.apache.baremaps.server.VectorTileResource;
import org.apache.baremaps.tilestore.raster.*;
import org.apache.baremaps.tilestore.raster.RasterTileCache;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "serve", description = "Start a tile server that computes hillshades.")
public class Serve implements Callable<Integer> {

@Option(names = {"--host"}, paramLabel = "HOST", description = "The host of the server.")
private String host = "localhost";

@Option(names = {"--port"}, paramLabel = "PORT", description = "The port of the server.")
private int port = 9000;

@Override
public Integer call() throws Exception {

var serverBuilder = Server.builder();
serverBuilder.http(port);

var objectMapper = objectMapper();
var jsonResponseConverter = new JacksonResponseConverterFunction(objectMapper);

var elevationTileStore =
new RasterTileCache(new RasterElevationTileStore(), CaffeineSpec.parse("maximumSize=1000"));
var rasterHillshadeTileStore =
new RasterHillshadeTileStore(elevationTileStore, ElevationUtils::pixelToElevationTerrarium);
var vectorHillshadeTileStore = new VectorHillshadeTileStore(elevationTileStore,
ElevationUtils::pixelToElevationTerrarium);
var contourTileStore = new VectorContourTileStore(elevationTileStore);


serverBuilder.annotatedService(
"/raster",
new BufferedImageResource(() -> rasterHillshadeTileStore),
jsonResponseConverter);

serverBuilder.annotatedService(
"/contour",
new VectorTileResource(() -> contourTileStore),
jsonResponseConverter);

serverBuilder.annotatedService(
"/tiles",
new VectorTileResource(() -> vectorHillshadeTileStore),
jsonResponseConverter);

var index = HttpFile.of(ClassLoader.getSystemClassLoader(), "/raster/hillshade.html");
serverBuilder.service("/", index.asService());

serverBuilder.decorator(CorsService.builderForAnyOrigin()
.allowAllRequestHeaders(true)
.allowRequestMethods(
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.PUT,
HttpMethod.DELETE,
HttpMethod.OPTIONS,
HttpMethod.HEAD)
.allowCredentials()
.exposeHeaders(HttpHeaderNames.LOCATION)
.newDecorator());

serverBuilder.serviceUnder("/docs", new DocService());

serverBuilder.disableServerHeader();
serverBuilder.disableDateHeader();

var server = serverBuilder.build();

var startFuture = server.start();
startFuture.join();

var shutdownFuture = server.closeOnJvmShutdown();
shutdownFuture.join();

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.linecorp.armeria.server.file.FileService;
import com.linecorp.armeria.server.file.HttpFile;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
Expand All @@ -37,8 +38,8 @@
import org.apache.baremaps.maplibre.tileset.Tileset;
import org.apache.baremaps.server.ChangeResource;
import org.apache.baremaps.server.StyleResource;
import org.apache.baremaps.server.TileResource;
import org.apache.baremaps.server.TilesetResource;
import org.apache.baremaps.server.VectorTileResource;
import org.apache.baremaps.tilestore.TileStore;
import org.apache.baremaps.tilestore.postgres.PostgresTileStore;
import org.apache.baremaps.utils.PostgresUtils;
Expand Down Expand Up @@ -96,7 +97,7 @@ public Integer call() throws Exception {
}
};

var tileStoreSupplier = (Supplier<TileStore>) () -> {
var tileStoreSupplier = (Supplier<TileStore<ByteBuffer>>) () -> {
var tileJSON = tilesetSupplier.get();
return new PostgresTileStore(datasource, tileJSON);
};
Expand All @@ -116,7 +117,8 @@ public Integer call() throws Exception {
var jsonResponseConverter = new JacksonResponseConverterFunction(objectMapper);
serverBuilder.annotatedService(new ChangeResource(tilesetPath, stylePath),
jsonResponseConverter);
serverBuilder.annotatedService(new TileResource(tileStoreSupplier), jsonResponseConverter);
serverBuilder.annotatedService("/tiles", new VectorTileResource(tileStoreSupplier),
jsonResponseConverter);
serverBuilder.annotatedService(new StyleResource(styleSupplier), jsonResponseConverter);
serverBuilder.annotatedService(new TilesetResource(tilesetSupplier), jsonResponseConverter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.linecorp.armeria.server.docs.DocService;
import com.linecorp.armeria.server.file.FileService;
import com.linecorp.armeria.server.file.HttpFile;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
Expand All @@ -36,9 +37,9 @@
import org.apache.baremaps.maplibre.style.Style;
import org.apache.baremaps.maplibre.tilejson.TileJSON;
import org.apache.baremaps.server.*;
import org.apache.baremaps.tilestore.TileCache;
import org.apache.baremaps.tilestore.TileStore;
import org.apache.baremaps.tilestore.mbtiles.MBTilesStore;
import org.apache.baremaps.tilestore.vector.VectorTileCache;
import org.apache.baremaps.utils.SqliteUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -83,8 +84,8 @@ public Integer call() throws Exception {

var datasource = SqliteUtils.createDataSource(mbtilesPath, true);
try (var tileStore = new MBTilesStore(datasource);
var tileCache = new TileCache(tileStore, caffeineSpec)) {
var tileStoreSupplier = (Supplier<TileStore>) () -> tileCache;
var tileCache = new VectorTileCache(tileStore, caffeineSpec)) {
var tileStoreSupplier = (Supplier<TileStore<ByteBuffer>>) () -> tileCache;

var style = objectMapper.readValue(configReader.read(stylePath), Style.class);
var styleSupplier = (Supplier<Style>) () -> style;
Expand All @@ -96,7 +97,8 @@ public Integer call() throws Exception {
serverBuilder.http(port);

var jsonResponseConverter = new JacksonResponseConverterFunction(objectMapper);
serverBuilder.annotatedService(new TileResource(tileStoreSupplier), jsonResponseConverter);
serverBuilder.annotatedService("/tiles", new VectorTileResource(tileStoreSupplier),
jsonResponseConverter);
serverBuilder.annotatedService(new StyleResource(styleSupplier), jsonResponseConverter);
serverBuilder.annotatedService(new TileJSONResource(tileJSONSupplier), jsonResponseConverter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.linecorp.armeria.server.docs.DocService;
import com.linecorp.armeria.server.file.FileService;
import com.linecorp.armeria.server.file.HttpFile;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
Expand All @@ -39,10 +40,10 @@
import org.apache.baremaps.server.SearchResource;
import org.apache.baremaps.server.StyleResource;
import org.apache.baremaps.server.TileJSONResource;
import org.apache.baremaps.server.TileResource;
import org.apache.baremaps.tilestore.TileCache;
import org.apache.baremaps.server.VectorTileResource;
import org.apache.baremaps.tilestore.TileStore;
import org.apache.baremaps.tilestore.postgres.PostgresTileStore;
import org.apache.baremaps.tilestore.vector.VectorTileCache;
import org.apache.baremaps.utils.PostgresUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -95,9 +96,9 @@ public Integer call() throws Exception {

try (
var tileStore = new PostgresTileStore(datasource, tileset);
var tileCache = new TileCache(tileStore, caffeineSpec)) {
var tileCache = new VectorTileCache(tileStore, caffeineSpec)) {

var tileStoreSupplier = (Supplier<TileStore>) () -> tileCache;
var tileStoreSupplier = (Supplier<TileStore<ByteBuffer>>) () -> tileCache;

var style = objectMapper.readValue(configReader.read(stylePath), Style.class);
var styleSupplier = (Supplier<Style>) () -> style;
Expand All @@ -109,7 +110,8 @@ public Integer call() throws Exception {
serverBuilder.http(port);

var jsonResponseConverter = new JacksonResponseConverterFunction(objectMapper);
serverBuilder.annotatedService(new TileResource(tileStoreSupplier), jsonResponseConverter);
serverBuilder.annotatedService("/tiles", new VectorTileResource(tileStoreSupplier),
jsonResponseConverter);
serverBuilder.annotatedService(new StyleResource(styleSupplier), jsonResponseConverter);
serverBuilder.annotatedService(new TileJSONResource(tileJSONSupplier), jsonResponseConverter);
serverBuilder.annotatedService(new SearchResource(datasource), jsonResponseConverter);
Expand Down
4 changes: 4 additions & 0 deletions baremaps-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ limitations under the License.
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-pmtiles</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-raster</artifactId>
</dependency>
<dependency>
<groupId>org.apache.baremaps</groupId>
<artifactId>baremaps-testing</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@



import java.nio.ByteBuffer;
import java.util.function.Consumer;

/** A channel that conveys tiles from a source to a target. */
public class TileChannel implements Consumer<TileCoord> {
public class TileChannel<T> implements Consumer<TileCoord> {

public final TileStore source;
public final TileStore<T> source;

public final TileStore target;
public final TileStore<T> target;

public final boolean deleteEmptyTiles;

Expand All @@ -37,7 +36,7 @@ public class TileChannel implements Consumer<TileCoord> {
* @param source the source
* @param target the target
*/
public TileChannel(TileStore source, TileStore target) {
public TileChannel(TileStore<T> source, TileStore<T> target) {
this(source, target, false);
}

Expand All @@ -48,7 +47,7 @@ public TileChannel(TileStore source, TileStore target) {
* @param target the target
* @param deleteEmptyTiles deletes empty tiles
*/
public TileChannel(TileStore source, TileStore target, boolean deleteEmptyTiles) {
public TileChannel(TileStore<T> source, TileStore<T> target, boolean deleteEmptyTiles) {
this.source = source;
this.target = target;
this.deleteEmptyTiles = deleteEmptyTiles;
Expand All @@ -58,9 +57,9 @@ public TileChannel(TileStore source, TileStore target, boolean deleteEmptyTiles)
@Override
public void accept(TileCoord tileCoord) {
try {
ByteBuffer blob = source.read(tileCoord);
if (blob != null) {
target.write(tileCoord, blob);
T tile = source.read(tileCoord);
if (tile != null) {
target.write(tileCoord, tile);
} else if (deleteEmptyTiles) {
target.delete(tileCoord);
}
Expand Down
Loading
Loading