Skip to content

Commit 35d4b8b

Browse files
first version
1 parent 1f475cf commit 35d4b8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3177
-1
lines changed

Diff for: .gitignore

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# https://github.com/github/gitignore/blob/master/Gradle.gitignore
2+
.gradle
3+
/build/
4+
5+
# Ignore Gradle GUI config
6+
gradle-app.setting
7+
8+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
9+
!gradle-wrapper.jar
10+
11+
# Cache of project
12+
.gradletasknamecache
13+
14+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
15+
# gradle/wrapper/gradle-wrapper.properties
16+
17+
# https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore
18+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
19+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
20+
21+
# User-specific stuff
22+
.idea/**/workspace.xml
23+
.idea/**/tasks.xml
24+
.idea/**/usage.statistics.xml
25+
.idea/**/dictionaries
26+
.idea/**/shelf
27+
28+
# Generated files
29+
.idea/**/contentModel.xml
30+
31+
# Sensitive or high-churn files
32+
.idea/**/dataSources/
33+
.idea/**/dataSources.ids
34+
.idea/**/dataSources.local.xml
35+
.idea/**/sqlDataSources.xml
36+
.idea/**/dynamic.xml
37+
.idea/**/uiDesigner.xml
38+
.idea/**/dbnavigator.xml
39+
40+
# Gradle
41+
.idea/**/gradle.xml
42+
.idea/**/libraries
43+
44+
# Gradle and Maven with auto-import
45+
# When using Gradle or Maven with auto-import, you should exclude module files,
46+
# since they will be recreated, and may cause churn. Uncomment if using
47+
# auto-import.
48+
.idea/artifacts
49+
.idea/compiler.xml
50+
.idea/modules.xml
51+
.idea/*.iml
52+
.idea/modules
53+
*.iml
54+
*.ipr
55+
56+
# CMake
57+
cmake-build-*/
58+
59+
# Mongo Explorer plugin
60+
.idea/**/mongoSettings.xml
61+
62+
# File-based project format
63+
*.iws
64+
65+
# IntelliJ
66+
out/
67+
68+
# mpeltonen/sbt-idea plugin
69+
.idea_modules/
70+
71+
# JIRA plugin
72+
atlassian-ide-plugin.xml
73+
74+
# Cursive Clojure plugin
75+
.idea/replstate.xml
76+
77+
# Crashlytics plugin (for Android Studio and IntelliJ)
78+
com_crashlytics_export_strings.xml
79+
crashlytics.properties
80+
crashlytics-build.properties
81+
fabric.properties
82+
83+
# Editor-based Rest Client
84+
.idea/httpRequests
85+
86+
# Android studio 3.1+ serialized cache file
87+
.idea/caches/build_file_checksums.ser

Diff for: .idea/jarRepositories.xml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM osgeo/gdal:alpine-small-3.0.2
2+
3+
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk/jre
4+
5+
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin:/byoc/bin
6+
7+
ENV JAVA_VERSION=8u222
8+
9+
ENV JAVA_ALPINE_VERSION=8.222.10-r0
10+
11+
RUN /bin/sh -c set -x && apk add --no-cache openjdk8-jre="$JAVA_ALPINE_VERSION"
12+
13+
COPY build/distributions/byoc-tool.tar /byoc-tool.tar
14+
RUN tar -xvf /byoc-tool.tar
15+
16+
ENTRYPOINT ["/byoc-tool/bin/byoc-tool"]
17+
CMD ["help"]

Diff for: README.md

+113-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,114 @@
1-
# byoc-ingestor
1+
# Utility tool for Sentinel Hub BYOC service
22

3+
The Sentinel Hub BYOC Tool is a utility tool available as a Docker image (in this case) and a Java jar, which can be used to prepare your data for use in Sentinel Hub.
4+
5+
It converts your TIFF and JP2 files to Cloud Optimized GeoTIFFs, uploads them to AWS S3 and registers them in the Sentinel Hub BYOC service. When complete, your data should be visible in Sentinel Hub. The same steps can be done manually and are detailed in our documentation https://docs.sentinel-hub.com/api/latest/#/API/byoc, should you prefer or require more control over the process.
6+
7+
## Prerequisites
8+
9+
- A Sentinel Hub OAuth client -- if you don't have one, create one using our [web application](https://apps.sentinel-hub.com/dashboard). Click [here](https://docs.sentinel-hub.com/api/latest/#/API/authentication) for instructions.
10+
11+
- A BYOC collection -- if you don't have one, create one using our [web application](https://apps.sentinel-hub.com/dashboard/#/byoc) or [API](https://docs.sentinel-hub.com/api/latest/reference/?service=byoc).
12+
13+
- The AWS credentials with access to your bucket -- Get them from the AWS console. These are only used to upload your data and read data that is registered in BYOC service.
14+
15+
- Your bucket configured so that Sentinel Hub can access data from it -- how to do this is documented [here](https://docs.sentinel-hub.com/api/latest/#/API/byoc?id=configuring-the-bucket). This is necessary because this tool and Sentinel Hub are separate.
16+
17+
- Imagery! (Of course)
18+
19+
## Basic setup
20+
21+
Provide the Sentinel Hub OAuth client id and client secret in the environment variables `SH_CLIENT_ID` and `SH_CLIENT_SECRET`.
22+
23+
Provide the AWS client credentials in the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` or by mounting the folder `~/.aws/credentials`.
24+
25+
You can bundle all variables in a text file, e.g. named env.txt:
26+
27+
```
28+
SH_CLIENT_ID=<MySentinelHubClientId>
29+
SH_CLIENT_SECRET=<MySentinelHubClientSecret>
30+
AWS_ACCESS_KEY_ID=<MyAwsAccessKeyId>
31+
AWS_SECRET_ACCESS_KEY=<MyAwsSecretAccessKey>
32+
```
33+
34+
and pass it to Docker: `docker run --env-file env.txt sentinelhub/byoc-tool <Arguments...>`
35+
36+
## Basic Commands
37+
38+
For a list of commands run: `docker run sentinelhub/byoc-tool --help`
39+
40+
For a list of ingestion parameters run: `docker run sentinelhub/byoc-tool ingest --help`
41+
42+
To ingest files, you need to mount the imagery folder inside Docker, for example: `-v <MyFolder>:/folder` to mount the folder `<MyFolder>` to `/folder` inside Docker.
43+
44+
Then you give the tool the BYOC collection id `<MyCollectionId>` you wish to import to and the path to the folder inside the Docker (in this case `/folder`):
45+
46+
The basic import command (see the next chapter for details) is thus: `docker run --env-file env.txt -v <MyFolder>:/folder sentinelhub/byoc-tool ingest <MyCollectionId> /folder`
47+
48+
49+
## The Simple Default Case
50+
51+
The tool offers parameters which will allow tuning for various folder/file structures. The default case, which needs no additional parameters is as follows:
52+
By default, the tool takes the input folder and looks for folders inside which have tiff or jp2 images. In this case, each such folder found represents a tile and each file represents a band. For example, if you have files at the following locations:
53+
54+
- folder/
55+
- tile_1/
56+
- B01.tif
57+
- B02.tif
58+
- tile_2/
59+
- B01.tif
60+
- B02.tif
61+
62+
with `folder/` as the input path, the tool would ingest 2 tiles with names `tile_1` and `tile_2`, and each tile would have two bands named `B01` and `B02`. By default, band names equal the file names without file extensions.
63+
64+
The command will prepare Cloud Optimized GeoTIFFs and upload them to S3 bucket associated with the BYOC collection. Finally, it will register tiles in your BYOC collection. The file `/folder/tile_1/B01.tiff` will be uploaded to`s3://<MyBucket>/tile_1/B01.tiff`.
65+
66+
For more elaborate folder, tile, band structures, see the help of the `--file-pattern` and `--file-map` parameters.
67+
68+
Note that in this case the tile sensing time will not be set and that the tile coverage will not be traced (see the Tracing Coverage chapter).
69+
70+
## Advanced Example
71+
72+
The tool can be quite powerful with the right parameters. This example will attempt to showcase these without being too complicated.
73+
74+
Suppose in this case that the folder structure is as follows:
75+
76+
- folder/
77+
- tile_1/
78+
- DATA_and_sensing_time_1.tif
79+
- tile_2/
80+
- DATA_and_sensing_time_2.tif
81+
82+
In this case lets assume the DATA tiffs are three bands each, containing R,G,B bands.
83+
84+
To effectively use the tool in this case, the `--file-pattern` and `--file-map` parameters need to be used. The `--file pattern` in this case can look something like this: `(?<tile>.*)\/.*(?<year>[0-9]{4})(?<month>[0-9]{2})(?<day>[0-9]{2})T(?<hour>[0-9]{2})(?<minute>[0-9]{2})(?<second>[0-9]{02})`. This will find files with the defined sensing time structure and use the name of their parent folder as the tile name. This can be modified to support multiple files per folder or even files in different folders which together represent one tile.
85+
86+
The `--file-map` parameter allows all bands from the tiff file to be used. In this case since there is only one file per tile only one is needed and it can look something like this: `.*tif;1:R;2:G;3:B`. In words: From a .tif file extract band 1 and name it R, extract band 2 and name it G, extract band 3 and name it B.
87+
88+
To remember: `--file-pattern` finds files using a regular expression. Files with an equal `tile` capture group value are grouped into that one tile. The `--file-map` pattern is then applied to each file within that tile. You can define as many `--file-map` parameters as are files in a tile so that each file can be mapped.
89+
90+
91+
## Tracing Coverage
92+
93+
Information about what coverage tracing is and why it is important is available [here](https://docs.sentinel-hub.com/api/latest/#/API/byoc?id=a-note-about-cover-geometries).
94+
95+
To enable geometry tracing set the flag `--trace-coverage`. See `--distance-tolerance` and `--negative-buffer` for tuning parameters. If not set, the cover geometry will equal the image bounding box.
96+
97+
To speed up tracing, you can trace coverage from one of image overviews. For example, to trace coverage from the first overview, set the flag `--trace-image-idx 1`.
98+
99+
## Building a docker image
100+
101+
```
102+
./gradlew build
103+
docker build -t byoc-tool .
104+
```
105+
106+
## Building an executable
107+
108+
Download OpenJDK 14.
109+
110+
Set JPACKAGE_HOME and JLINK_HOME to OpenJDK 14 location.
111+
112+
Run `gradlew jpackage`
113+
114+
The executable will be located in the project root.

Diff for: build.gradle

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
plugins {
2+
id 'java'
3+
id 'application'
4+
id 'com.diffplug.gradle.spotless' version '3.26.0'
5+
id 'idea'
6+
id 'com.github.johnrengelman.shadow' version '5.2.0'
7+
}
8+
9+
java {
10+
sourceCompatibility = JavaVersion.VERSION_1_8
11+
targetCompatibility = JavaVersion.VERSION_1_8
12+
}
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
spotless {
19+
java {
20+
googleJavaFormat('1.7')
21+
}
22+
}
23+
24+
idea {
25+
module {
26+
outputDir file('build/classes/main')
27+
testOutputDir file('build/classes/test')
28+
}
29+
}
30+
31+
test {
32+
useJUnitPlatform()
33+
}
34+
35+
shadowJar {
36+
// removes '-all' suffix from .jar file
37+
classifier = ''
38+
}
39+
40+
ext {
41+
jerseyVersion = '2.26'
42+
lombokVersion = '1.18.8'
43+
log4jVersion = '2.12.1'
44+
junitVersion = '5.5.2'
45+
}
46+
47+
dependencies {
48+
49+
implementation "info.picocli:picocli:4.0.4"
50+
implementation "org.locationtech.jts:jts-core:1.16.1"
51+
implementation "com.amazonaws:aws-java-sdk-s3:1.11.490"
52+
implementation "com.twelvemonkeys.imageio:imageio-tiff:3.4.2"
53+
implementation "org.wololo:jts2geojson:0.14.3"
54+
implementation "de.grundid.opendatalab:geojson-jackson:1.12"
55+
implementation "commons-cli:commons-cli:1.4"
56+
57+
implementation "org.glassfish.jersey.core:jersey-client:$jerseyVersion"
58+
implementation "org.glassfish.jersey.inject:jersey-hk2:$jerseyVersion"
59+
implementation "org.glassfish.jersey.media:jersey-media-json-jackson:$jerseyVersion"
60+
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.10.1"
61+
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.1"
62+
63+
// lombok
64+
compileOnly "org.projectlombok:lombok:$lombokVersion"
65+
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
66+
67+
// logging
68+
implementation "org.apache.logging.log4j:log4j-api:$log4jVersion"
69+
implementation "org.apache.logging.log4j:log4j-core:$log4jVersion"
70+
71+
// required with newer JDKs
72+
implementation 'javax.activation:activation:1.1'
73+
implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.0'
74+
75+
// testing
76+
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
77+
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
78+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
79+
}
80+
81+
application {
82+
mainClassName = "byoc.ByocTool"
83+
}
84+
85+
// creates a slim JDK runtime for distribution
86+
task createRuntime(type: Exec) {
87+
doFirst() {
88+
project.delete("${buildDir}/runtime")
89+
}
90+
String runtimePath = "${buildDir}/runtime"
91+
92+
workingDir project.projectDir
93+
commandLine = [
94+
"${System.getenv("JLINK_HOME")}/bin/jlink",
95+
'--add-modules', 'java.base,java.desktop,jdk.unsupported,java.management,java.scripting,java.logging,java.sql,java.naming',
96+
'--strip-debug',
97+
'--no-header-files',
98+
'--no-man-pages',
99+
"--compress=2",
100+
'--output', runtimePath
101+
]
102+
}
103+
104+
// creates application bundle (executable + runtime)
105+
task jpackage(type: Exec, dependsOn: shadowJar) {
106+
dependsOn createRuntime
107+
workingDir project.projectDir
108+
commandLine = [
109+
"${System.getenv("JPACKAGE_HOME")}/bin/jpackage",
110+
'--input', "${buildDir}/libs",
111+
'--name', project.name,
112+
'--main-class', project.mainClassName,
113+
'--main-jar', "byoc-tool.jar",
114+
'--runtime-image', "${buildDir}/runtime",
115+
'--java-options', '-Dlog4j2.disable.jmx=true'
116+
]
117+
}

Diff for: gradle/wrapper/gradle-wrapper.jar

54.3 KB
Binary file not shown.

Diff for: gradle/wrapper/gradle-wrapper.properties

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)