Gery
Gery

Reputation: 11

How to add GeoServer's ImagePyramid as a raster layer?

Problem

I want to import an ImagePyramid layer from GeoServer to my Android App. It is showing correctly when I check it using GeoServer's layer preview and QGIS, but I can't seem to import it to my Android app that uses Mapbox Android SDK using GeoServer's TMS.

My Attempt

I created a new pyramid file using GDAL's gdal_retile command and I imported the results file into the data store of my GeoServer, as an ImagePyramid. Here is the exact command that I use:

command = [
        "gdal_retile.py",
        "-v",  # Verbose mode for detailed output
        "-r", "bilinear",  # Resampling method
        "-levels", str(levels),  # Number of pyramid levels
        "-ps", str(ps), str(ps),  # Pixel size
        "-co", "TILED=YES",
        "-co", "COMPRESS=JPEG",
        "-targetDir", target_dir,  # Target directory for the pyramid
        tif_path  # Path to the local TIFF image
    ]

Then, checking using GeoServer's Layer Preview, I can see that my Pyramid file is created correctly because it is showing a different resolution whenever I zoomed in or out. GeoServer's Layer Preview

So I seed using GeoServer's GeoWebCache which give me this TMS url (I changed the WebApp name to "test" for security purpose) http://test.azurewebsites.net/geoserver/gwc/service/tms/1.0.0/ne%3Ashinjuku-small_20240514-115541@WebMercatorQuad@png

To check whether the seeding process is correct or not, I added /{z}/{x}/{-y}.png to back of the TMS url and Using QGIS, I imported is as a XYZ Tile. Again, there are no problem and the tiled images are correctly shown in QGIS. (See image 1)

QGIS XYZ Tiles

Finally, I wanted to add it to my Android appas a new rastersource but somehow it is not showing... I saw some people adding it as a vector layer so I tried that also but it is still not showing the tiles images on my app. Here is the function in my Android app that handles rendering the ImagePyramid from GeoServer's GeoWebCache:

    private fun showGeoserverTile() {
        if (mapView.mapboxMap.style?.getLayer("geoserver-layer") != null) {
            mapView.mapboxMap.style?.removeStyleLayer("geoserver-layer")
            Log.d("[geoserverレイヤー]", "非表示")
            return
        }

        if (mapView.mapboxMap.style?.getSource("geoserver-tms") == null) {
            val rasterSource = rasterSource("osm-source") {
                tileSize(256)
                tiles(listOf("http://test.azurewebsites.net/geoserver/gwc/service/tms/1.0.0/ne%3Ashinjuku-small_20240514-115541@WebMercatorQuad@png/{z}/{x}/{-y}.png"))
            }
            mapView.mapboxMap.style?.addSource(rasterSource)
        }
        val layer = rasterLayer("geoserver-layer", "geoserver-source") {}
        mapView.mapboxMap.style?.addLayer(layer)
        Log.d("[geoserverレイヤー]", "表示")
        return
    }

Upvotes: 0

Views: 74

Answers (0)

Related Questions