Skip to content
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

Bump org.jlleitschuh.gradle.ktlint from 11.0.0 to 11.3.1 #94

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ plugins {
id("pmd")
id("checkstyle")
id("com.github.spotbugs") version "5.0.13"
id("org.jlleitschuh.gradle.ktlint") version "11.0.0"
id("org.jlleitschuh.gradle.ktlint") version "11.3.1"

// Kotlin
kotlin("jvm") version "1.7.22"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ abstract class RaylevationControllerV1Base : AbstractStandaloneMvcTest<Raylevati
every { service.lookup(match { it.size == 3 }) } returns listOf(
LookupResult(GeoPoint(10.0, 10.0), Metre(515)),
LookupResult(GeoPoint(20.0, 20.0), Metre(545)),
LookupResult(GeoPoint(41.161758, -8.583933), Metre(117)),
LookupResult(GeoPoint(41.161758, -8.583933), Metre(117))
)
every { service.lookup(match { it.size == 4 }) } returns listOf(
LookupResult(GeoPoint(10.0, 10.0), Metre(515)),
LookupResult(GeoPoint(20.0, 20.0), Metre(545)),
LookupResult(GeoPoint(41.161758, -8.583933), Metre(117)),
LookupResult(GeoPoint(85.0, 10.1), Metre(0), "Missing elevation data for (85.0,10.1)"),
LookupResult(GeoPoint(85.0, 10.1), Metre(0), "Missing elevation data for (85.0,10.1)")
)
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/kotlin/com/raynigon/raylevation/db/RaylevationDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ class RaylevationDB(
.toSet()

// No change in cache, exit early
if (tilesInCache == tilesToCache)
if (tilesInCache == tilesToCache) {
return
}

// Update cache for tiles
for (tile in tiles) {
Expand All @@ -209,8 +210,10 @@ class RaylevationDB(
val bounds = tile.bounds.roundOff()
val name = String.format(
"%+2.2f_%+2.2f_%+2.2f_%+2.2f",
bounds.yMax, bounds.xMin,
bounds.yMin, bounds.xMax,
bounds.yMax,
bounds.xMin,
bounds.yMin,
bounds.xMax
)
// Copy GDAL Tile to the database directory
val tilePath = tilesFolder.resolve("$name$GEOTIFF_FILE_SUFFIX")
Expand Down Expand Up @@ -254,8 +257,9 @@ class RaylevationDB(

@Synchronized
private fun addTile(tile: IRaylevationTile) {
if (tiles.contains(tile))
if (tiles.contains(tile)) {
throw IllegalArgumentException("Tile $tile already exists")
}
// Create new index, because the index is immutable, therefore we need to create a new one on every change
val newTiles = tiles.toMutableSet()
val newIndex = index.add(tile, tile.toRectangle())
Expand Down
12 changes: 8 additions & 4 deletions src/main/kotlin/com/raynigon/raylevation/db/gdal/GDALTile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ class GDALTile(val path: Path) {
* Logic transferred from https://stackoverflow.com/questions/13439357/extract-point-from-raster-in-gdal
*/
init {
if (dataset.GetRasterCount() != 1)
if (dataset.GetRasterCount() != 1) {
throw IncompatibleTileException(path, "has too many Raster Bands", dataset.GetRasterCount(), 1)
}
val bandDataType = dataset.GetRasterBand(ELEVATION_BAND).dataType
if (bandDataType != GDT_Int16)
if (bandDataType != GDT_Int16) {
throw IncompatibleTileException(path, "has an incompatible data type on Band 1", bandDataType, GDT_Int16)
}

val spatialReferenceRaster = SpatialReference(dataset.GetProjection())
val spatialReference = SpatialReference()
Expand Down Expand Up @@ -129,8 +131,9 @@ class GDALTile(val path: Path) {
val elevation = raster[ylin][xpix]

// if no data exists we know the point is on sea level
if (elevation == noDataValue)
if (elevation == noDataValue) {
return SEA_LEVEL
}
return Metre(elevation)
}

Expand Down Expand Up @@ -164,7 +167,8 @@ class GDALTile(val path: Path) {
private fun createTranslateOptions(bounds: TileBounds) = TranslateOptions(
Vector<Any>(
listOf(
"-of", "GTiff",
"-of",
"GTiff",
"-projWin",
bounds.xMin.toString(),
bounds.yMax.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class RaylevationStateBounds(
val lon0: Double,
val lat0: Double,
val lon1: Double,
val lat1: Double,
val lat1: Double
) {

constructor(bounds: TileBounds) : this(bounds.xMin, bounds.yMax, bounds.xMax, bounds.yMin)
Expand All @@ -24,7 +24,7 @@ data class RaylevationStateBounds(
fun toTileBounds(): TileBounds {
return TileBounds(
GeoPoint(lat0, max(lon0, -180.0)),
GeoPoint(lat1, min(lon1, 180.0)),
GeoPoint(lat1, min(lon1, 180.0))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RaylevationTile(
"latitude",
bounds.center.latitude.toString(),
"longitude",
bounds.center.longitude.toString(),
bounds.center.longitude.toString()
)
private val metricCached = registry.gauge(
"app.raylevation.db.tile.cached",
Expand All @@ -87,6 +87,7 @@ class RaylevationTile(

override var cache: Boolean
get() = tileCache != null

@Synchronized
set(value) {
if (value && tileCache == null) {
Expand All @@ -100,8 +101,9 @@ class RaylevationTile(
}

override fun lookupElevation(point: GeoPoint): Quantity<Length> {
if (!bounds.contains(point))
if (!bounds.contains(point)) {
throw LookupOutOfBoundsException(point, bounds)
}
val result = (tileCache ?: GDALTile(path))
.lookupElevation(point)
incrementCounter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data class TileBounds(
upperLeft.latitude,
upperLeft.longitude,
lowerRight.latitude,
lowerRight.longitude,
lowerRight.longitude
)

val center: GeoPoint by lazy {
Expand Down