-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raster processing and digital elevation models #890
Open
bchapuis
wants to merge
14
commits into
main
Choose a base branch
from
raster-processing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c378e95
Add a wrapper for the gdal bindings
bchapuis 5e67048
Implement algorithms for digital elevation models
bchapuis a15bb12
Introduce TileStore for raster and vector tiles
bchapuis c2f5f29
Add utility to scale geometries
bchapuis d765fde
Add raster tile server and DEM preview utilities
bchapuis ec0827b
Add some utilities for testing with geometries
bchapuis 7cf7981
Add commands to preview DEM data as raster and vector
bchapuis a44233e
Clean code and fix issues detected by analyzers
bchapuis daabd7c
Move version numbers to main pom file
bchapuis 081f5ca
Address issues detected by sonar
bchapuis ab732c1
Clean some unused code
bchapuis c493c9f
Remove the baremaps-gdal module
bchapuis d8a07ca
Add some javadoc and clean the code
bchapuis b50aae8
Validate inputs in the constructor
bchapuis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="basemap-dem" type="Application" factoryName="Application"> | ||
<option name="MAIN_CLASS_NAME" value="org.apache.baremaps.cli.Baremaps" /> | ||
<module name="baremaps-cli" /> | ||
<option name="PROGRAM_PARAMETERS" value="dem serve --path $USER_HOME$/Downloads/gebco_2024.tif" /> | ||
<projectPathOnTarget name="projectPathOnTarget" value="/app" /> | ||
<target name="@@@LOCAL@@@" /> | ||
<extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension"> | ||
<option name="credential" /> | ||
<option name="region" /> | ||
<option name="useCurrentConnection" value="false" /> | ||
</extension> | ||
<method v="2"> | ||
<option name="Make" enabled="true" /> | ||
</method> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
baremaps-cli/src/main/java/org/apache/baremaps/cli/dem/DEM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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.dem; | ||
|
||
|
||
|
||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
|
||
@Command(name = "dem", description = "DEM processing commands.", | ||
subcommands = { | ||
Serve.class, | ||
VectorTileContours.class | ||
}, | ||
sortOptions = false) | ||
@SuppressWarnings("squid:S106") | ||
public class DEM implements Runnable { | ||
|
||
@Override | ||
public void run() { | ||
CommandLine.usage(this, System.out); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
baremaps-cli/src/main/java/org/apache/baremaps/cli/dem/Serve.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* 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.dem; | ||
|
||
import static org.apache.baremaps.utils.ObjectMapperUtils.objectMapper; | ||
|
||
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.nio.file.Path; | ||
import java.util.concurrent.Callable; | ||
import org.apache.baremaps.dem.ElevationUtils; | ||
import org.apache.baremaps.server.BufferedImageResource; | ||
import org.apache.baremaps.server.VectorTileResource; | ||
import org.apache.baremaps.tilestore.raster.*; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
@Command(name = "serve", description = "Start a tile server that serves elevation data.") | ||
public class Serve implements Callable<Integer> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a line to define purpose of the Server |
||
|
||
@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; | ||
|
||
@Option(names = {"--path"}, paramLabel = "PATH", description = "The path of a geoTIFF file.") | ||
private Path path; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
// Initialize the tile stores | ||
var geoTiffReader = new GeoTiffReader(path); | ||
var rasterElevationTileStore = new TerrariumTileStore(geoTiffReader); | ||
var rasterHillshadeTileStore = | ||
new RasterHillshadeTileStore( | ||
geoTiffReader, | ||
ElevationUtils::terrariumToElevation); | ||
var vectorHillshadeTileStore = | ||
new VectorHillshadeTileStore( | ||
geoTiffReader); | ||
var vectorContourTileStore = | ||
new VectorContourTileStore(geoTiffReader); | ||
|
||
// Initialize the server | ||
var objectMapper = objectMapper(); | ||
var jsonResponseConverter = new JacksonResponseConverterFunction(objectMapper); | ||
var serverBuilder = Server.builder(); | ||
serverBuilder.http(port); | ||
|
||
// Register the services | ||
serverBuilder.annotatedService( | ||
"/raster/elevation", | ||
new BufferedImageResource(() -> rasterElevationTileStore), | ||
jsonResponseConverter); | ||
serverBuilder.annotatedService( | ||
"/raster/hillshade", | ||
new BufferedImageResource(() -> rasterHillshadeTileStore), | ||
jsonResponseConverter); | ||
serverBuilder.annotatedService( | ||
"/vector/contour", | ||
new VectorTileResource(() -> vectorContourTileStore), | ||
jsonResponseConverter); | ||
serverBuilder.annotatedService( | ||
"/vector/hillshade", | ||
new VectorTileResource(() -> vectorHillshadeTileStore), | ||
jsonResponseConverter); | ||
|
||
var index = HttpFile.of(ClassLoader.getSystemClassLoader(), "/dem/index.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; | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
baremaps-cli/src/main/java/org/apache/baremaps/cli/dem/VectorTileContours.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* 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.dem; | ||
|
||
|
||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
import org.apache.baremaps.maplibre.tileset.Tileset; | ||
import org.apache.baremaps.maplibre.tileset.TilesetLayer; | ||
import org.apache.baremaps.openstreetmap.stream.ProgressLogger; | ||
import org.apache.baremaps.openstreetmap.stream.StreamUtils; | ||
import org.apache.baremaps.tilestore.TileCoord; | ||
import org.apache.baremaps.tilestore.TileEntry; | ||
import org.apache.baremaps.tilestore.TileStoreException; | ||
import org.apache.baremaps.tilestore.pmtiles.PMTilesStore; | ||
import org.apache.baremaps.tilestore.raster.*; | ||
import org.apache.baremaps.workflow.WorkflowException; | ||
import org.apache.baremaps.workflow.tasks.ExportVectorTiles; | ||
import org.locationtech.jts.geom.Envelope; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
@Command(name = "vector-contours", description = "Generate vector contours from a DEM.") | ||
@SuppressWarnings({"squid:S106", "squid:S3864"}) | ||
public class VectorTileContours implements Callable<Integer> { | ||
|
||
@Option(names = {"--path"}, paramLabel = "PATH", description = "The path of a geoTIFF file.") | ||
private Path path; | ||
|
||
@Option(names = {"--repository"}, paramLabel = "REPOSITORY", description = "The tile repository.", | ||
required = true) | ||
private Path repository; | ||
|
||
@Option(names = {"--format"}, paramLabel = "FORMAT", | ||
description = "The format of the repository.") | ||
private ExportVectorTiles.Format format = ExportVectorTiles.Format.FILE; | ||
|
||
|
||
@Override | ||
public Integer call() throws Exception { | ||
var contourLayer = new TilesetLayer(); | ||
contourLayer.setId("contours"); | ||
|
||
var tileset = new Tileset(); | ||
tileset.setName("contours"); | ||
tileset.setMinzoom(2); | ||
tileset.setMaxzoom(10); | ||
tileset.setCenter(List.of(0d, 0d, 1d)); | ||
tileset.setBounds(List.of(-180d, -85.0511d, 180d, 85.0511d)); | ||
tileset.setVectorLayers(List.of(contourLayer)); | ||
|
||
// Initialize the tile stores | ||
try (var geoTiffReader = new GeoTiffReader(path); | ||
var sourceTileStore = new VectorContourTileStore(geoTiffReader); | ||
var targetTileStore = new PMTilesStore(repository, tileset);) { | ||
|
||
var envelope = new Envelope(-180, 180, -85.0511, 85.0511); | ||
var count = TileCoord.count(envelope, 0, 10); | ||
|
||
var tileCoordIterator = | ||
TileCoord.iterator(envelope, 2, 10); | ||
var tileCoordStream = | ||
StreamUtils.stream(tileCoordIterator).peek(new ProgressLogger<>(count, 1000)); | ||
|
||
|
||
var bufferedTileEntryStream = StreamUtils.bufferInCompletionOrder(tileCoordStream, tile -> { | ||
|
||
try { | ||
return new TileEntry<>(tile, sourceTileStore.read(tile)); | ||
} catch (TileStoreException e) { | ||
throw new WorkflowException(e); | ||
} finally { | ||
System.out.println("Processing tile " + tile); | ||
} | ||
}, 8); | ||
|
||
var partitionedTileEntryStream = StreamUtils.partition(bufferedTileEntryStream, 8); | ||
partitionedTileEntryStream.forEach(batch -> { | ||
try { | ||
targetTileStore.write(batch); | ||
} catch (TileStoreException e) { | ||
throw new WorkflowException(e); | ||
} | ||
}); | ||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could add some javadoc explaining DEM, maybe with external links
This comment applies to the Key classes (entry points of this new functionality)