Skip to content

Commit

Permalink
Add generic WMSElevationCoverage class.
Browse files Browse the repository at this point in the history
  • Loading branch information
ComBatVision committed Jan 4, 2023
1 parent 50eb9c4 commit ae2bfa4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import kotlin.math.atan
class WcsElevationTutorial(private val engine: WorldWind) : AbstractTutorial() {
// Create an elevation coverage from a version 1.0.0 WCS
private val wcsElevationCoverage = Wcs100ElevationCoverage(
// Specify the bounding sector - provided by the WCS
sector = Sector.fromDegrees(25.0, -125.0, 25.0, 60.0),
// Specify the number of levels to match data resolution
numLevels = 12,
// Specify the version 1.0.0 WCS address
serviceAddress = "https://elevation.nationalmap.gov/arcgis/services/3DEPElevation/ImageServer/WCSServer",
// Specify the coverage name
coverage = "DEP3Elevation",
// Specify the image format
imageFormat = "geotiff"
imageFormat = "geotiff",
// Specify the bounding sector - provided by the WCS
sector = Sector.fromDegrees(25.0, -125.0, 25.0, 60.0),
// Specify the number of levels to match data resolution
numLevels = 12
)

override fun start() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
package earth.worldwind.globe.elevation.coverage

import earth.worldwind.geom.Sector
import earth.worldwind.geom.TileMatrix
import earth.worldwind.geom.TileMatrixSet
import earth.worldwind.globe.elevation.ElevationSource
import earth.worldwind.globe.elevation.ElevationTileFactory
import earth.worldwind.ogc.WmsLayerConfig
import earth.worldwind.ogc.WmsTileFactory
import earth.worldwind.ogc.WmsElevationCoverage

/**
* Displays NASA's global elevation coverage at 30m resolution and 900m resolution on the ocean floor,
* all from an OGC Web Map Service (WMS). By default, BasicElevationCoverage is configured to
* retrieve elevation coverage from the WMS at [&https://wms.worldwind.earth/elev](https://wms.worldwind.earth/elev?SERVICE=WMS&REQUEST=GetCapabilities).
*/
open class BasicElevationCoverage: TiledElevationCoverage(tileMatrixSet, tileFactory) {
companion object {
/**
* 4x2 top level matrix equivalent to 90 degree top level tiles
*/
private val tileMatrixSet get() = TileMatrixSet.fromTilePyramid(
Sector().setFullSphere(), 4, 2, 256, 256, 13
)

private val tileFactory: ElevationTileFactory get() {
val layerConfig = WmsLayerConfig(
"https://wms.worldwind.earth/elev", "SRTM-CGIAR,GEBCO"
).apply { imageFormat = "application/bil16" }
val wmsTileFactory = WmsTileFactory(layerConfig)
return object : ElevationTileFactory {
override fun createElevationSource(tileMatrix: TileMatrix, row: Int, column: Int): ElevationSource {
val tileSector = tileMatrix.tileSector(row, column)
val urlString = wmsTileFactory.urlForTile(tileSector, tileMatrix.tileWidth, tileMatrix.tileHeight)
return ElevationSource.fromUrlString(urlString)
}
}
}
}
}
class BasicElevationCoverage : WmsElevationCoverage(
"https://wms.worldwind.earth/elev", "SRTM-CGIAR,GEBCO", "application/bil16"
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import earth.worldwind.globe.elevation.coverage.TiledElevationCoverage
* service supports the format and coordinate system parameters detailed here.
*/
class Wcs100ElevationCoverage(
sector: Sector, numLevels: Int, serviceAddress: String, coverage: String, imageFormat: String
serviceAddress: String, coverage: String, imageFormat: String, sector: Sector, numLevels: Int
): TiledElevationCoverage(
TileMatrixSet.fromTilePyramid(sector, if (sector.isFullSphere) 2 else 1, 1, 256, 256, numLevels),
Wcs100TileFactory(serviceAddress, coverage, imageFormat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ open class Wcs201ElevationCoverage: TiledElevationCoverage {
/**
* Constructs a Web Coverage Service (WCS) elevation coverage with specified WCS configuration values.
*
* @param sector the coverage's geographic bounding sector
* @param numLevels the number of levels of elevations to generate, beginning with 2-by-4 geographic grid of
* 90-degree tiles containing 256x256 elevation pixels
* @param serviceAddress the WCS service address
* @param coverage the WCS coverage name
* @param imageFormat the WCS source image format
* @param sector the coverage's geographic bounding sector
* @param numLevels the number of levels of elevations to generate, beginning with 2-by-4 geographic grid of
* 90-degree tiles containing 256x256 elevation pixels
*
* @throws IllegalArgumentException If any argument is null or if the number of levels is less than 0
*/
constructor(sector: Sector, numLevels: Int, serviceAddress: String, coverage: String, imageFormat: String): super(
constructor(serviceAddress: String, coverage: String, imageFormat: String, sector: Sector, numLevels: Int): super(
TileMatrixSet.fromTilePyramid(sector, if (sector.isFullSphere) 2 else 1, 1, 256, 256, numLevels),
Wcs201TileFactory(serviceAddress, coverage, imageFormat)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package earth.worldwind.ogc

import earth.worldwind.geom.Sector
import earth.worldwind.geom.TileMatrix
import earth.worldwind.geom.TileMatrixSet
import earth.worldwind.globe.elevation.ElevationSource
import earth.worldwind.globe.elevation.ElevationTileFactory
import earth.worldwind.globe.elevation.coverage.TiledElevationCoverage

/**
* Generates elevations from OGC Web Map Service (WMS) version 1.3.0.
*/
open class WmsElevationCoverage(
serviceAddress: String, coverage: String, imageFormat: String, sector: Sector = Sector().setFullSphere(), numLevels: Int = 13
): TiledElevationCoverage(
buildTileMatrixSet(sector, numLevels),
buildTileFactory(serviceAddress, coverage, imageFormat)
) {
companion object {
/**
* 4x2 top level matrix equivalent to 90 degree top level tiles
*/
private fun buildTileMatrixSet(sector: Sector, numLevels: Int) = TileMatrixSet.fromTilePyramid(
sector, 4, 2, 256, 256, numLevels
)

private fun buildTileFactory(serviceAddress: String, coverage: String, imageFormat: String): ElevationTileFactory {
val layerConfig = WmsLayerConfig(serviceAddress, coverage).apply { this.imageFormat = imageFormat }
val wmsTileFactory = WmsTileFactory(layerConfig)
return object : ElevationTileFactory {
override fun createElevationSource(tileMatrix: TileMatrix, row: Int, column: Int): ElevationSource {
val tileSector = tileMatrix.tileSector(row, column)
val urlString = wmsTileFactory.urlForTile(tileSector, tileMatrix.tileWidth, tileMatrix.tileHeight)
return ElevationSource.fromUrlString(urlString)
}
}
}
}
}

0 comments on commit ae2bfa4

Please sign in to comment.