2

I am using geoserver 2.8.2 under ubuntu 14.04 with the pyramid plugins. The pyramid tiles are generated by gdal_retile.py. GeoServer will generate some new shp files and property files when I import into a new data store.

As the permission constrained of my file system, I cannot give write permission to tomcat7.

However, geoserver can import a new data store if the shp files and property files already created.

Could I create these file manually with other scripts?

2 Answers 2

2

You can create these files anywhere that you do have write permission and then move them. You could use some GeoTools code to construct the image pyramid as a user that does have write permission.

1
  • Thanks for your suggestion. I am not familiar with Java, but do figure out a way in R. Will post my codes here soon.
    – Bangyou
    Commented Jun 20, 2016 at 11:02
1

I wrote some R codes to manually create the properties files which is generated by geoserver (actually by GeoTools). The codes are not perfect, but work for me. I post here for other who will need them in R.

geoserver_retile <- function(
    input_file,
    target_dir, 
    levels = 8)
{
    # Call gdal_retile to generate tiles
    cmd <- paste0(
        'gdal_retile.py -v -r bilinear -levels ', levels
        , ' -ps 256 256 -co "TILED=YES" -co "COMPRESS=LZW" '
        , '-tileIndex tmp_tile_index '
        , ' -targetDir ', target_dir
        , ' ', input_file)

    system(cmd)
    dir.create(file.path(target_dir, '0'))

    # Create the zero level files
    zero_files <- list.files(target_dir, '*.tif', full.names = TRUE)
    file.rename(
        zero_files
        , file.path(target_dir, '0', basename(zero_files)))

    # Change file name of shapefile
    shp_files <- list.files(target_dir, 'tmp_tile_index*', full.names = TRUE)
    file.rename(
        shp_files
        , file.path(target_dir, '0', basename(shp_files)))


    shp_files <- list.files(
        target_dir, 'tmp_tile_index*'
        , full.names = TRUE, recursive = TRUE)

    idx <- gsub('.*/(\\d+)/.*', '\\1', shp_files)
    shp_files_new <- unlist(lapply(seq(along = shp_files)
           , function(x) gsub('tmp_tile_index', idx[x], shp_files[x])))
    file.rename(shp_files, shp_files_new)

    # Write properities
    library(rgdal)
    options(digits = 6)

    library(raster)
    input_raster <- raster(input_files)

    writeLines(showWKT(proj4string(input_raster)), 
               file.path(target_dir,
                             paste0(basename(target_dir), '.prj')))

    input_res <- res(input_raster)

    for (i in seq(0, levels)) {
        # i <- 0
        file_name <- file.path(target_dir, i, 
                               paste0(i, '.properties'))
        prop <- sprintf('Levels=%s,%s
Heterogeneous=false
AbsolutePath=false
Name=%s
TypeName=%s
Caching=false
ExpandToRGB=false
LocationAttribute=location
SuggestedSPI=it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi
CheckAuxiliaryMetadata=false
LevelsNum=1', input_res[1] * 2^i, input_res[2] * 2^i, i, i)
        writeLines(prop, file_name)
    }

    file_name <- file.path(target_dir,
                           paste0(basename(target_dir), '.properties'))
    input_extend <- extent(input_raster)

    prop <- sprintf('Name=%s
Levels=%s 
LevelsNum=%s
Envelope2D=%s
LevelsDirs=%s',
        basename(target_dir)
        , paste(paste0(input_res[1] * 2 ^ seq(0, levels), ',', input_res[2] * 2 ^ seq(0, levels)), collapse = ' ')
        , levels + 1
        , paste0(input_extend[1], ',', input_extend[3], ' ', input_extend[2], ',', input_extend[4])
        , paste(seq(0, levels), collapse = ' '))
    writeLines(prop, file_name)
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.